• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python api.create_object_graph函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中microcosm.api.create_object_graph函数的典型用法代码示例。如果您正苦于以下问题:Python create_object_graph函数的具体用法?Python create_object_graph怎么用?Python create_object_graph使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了create_object_graph函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_deferred_production_decorator

def test_deferred_production_decorator():
    """
    Deferred production can be used to decorate a function

    """
    def loader(metadata):
        return dict(
            sns_topic_arns=dict(
                default="topic",
            )
        )

    class Foo:
        def __init__(self, graph):
            self.graph = graph
            self.sns_producer = graph.sns_producer

        def bar(self):
            assert isinstance(self.sns_producer, DeferredProducer)
            self.sns_producer.produce(DerivedSchema.MEDIA_TYPE, data="data")
            assert_that(graph.sns_producer.sns_client.publish.call_count, is_(equal_to(0)))

    graph = create_object_graph("example", testing=True, loader=loader)
    foo = Foo(graph)

    func = deferred(foo)(foo.bar)
    func()

    assert_that(graph.sns_producer.sns_client.publish.call_count, is_(equal_to(1)))
开发者ID:globality-corp,项目名称:microcosm-pubsub,代码行数:29,代码来源:test_producer.py


示例2: test_publish_batch_with_no_topic_fails

def test_publish_batch_with_no_topic_fails():
    """
    Require explicit configuration of a topic for batch messages.

    """
    def loader(metadata):
        return dict(
            sns_topic_arns=dict(
                default="topic",
            )
        )

    graph = create_object_graph("example", testing=True, loader=loader)
    graph.use("opaque")

    # set up response
    graph.sns_producer.sns_client.publish.return_value = dict(MessageId=MESSAGE_ID)

    assert_that(
        calling(graph.sns_producer.produce).with_args(
            MessageBatchSchema.MEDIA_TYPE,
            messages=[]
        ),
        raises(TopicNotDefinedError)
    )
开发者ID:globality-corp,项目名称:microcosm-pubsub,代码行数:25,代码来源:test_producer.py


示例3: test_basic_auth_default_realm

def test_basic_auth_default_realm():
    """
    Basic auth uses the convention that the metadata's name is the realm.

    """
    graph = create_object_graph(name="example", testing=True)

    @graph.app.route("/unauthorized")
    @graph.audit
    @graph.basic_auth.required
    def unauthorized():
        raise Exception("Should not be raised!")

    client = graph.app.test_client()

    response = client.get("/unauthorized")
    assert_that(response.status_code, is_(equal_to(401)))
    data = loads(response.get_data().decode("utf-8"))
    assert_that(data, is_(equal_to({
        "code": 401,
        "message": "The server could not verify that you are authorized to access the URL requested. "
                   "You either supplied the wrong credentials (e.g. a bad password), or your browser "
                   "doesn't understand how to supply the credentials required.",
        "retryable": False,
        "context": {"errors": []},
    })))
    assert_that(response.headers["WWW-Authenticate"], is_(equal_to('Basic realm="example"')))
开发者ID:globality-corp,项目名称:microcosm-flask,代码行数:27,代码来源:test_basic_auth.py


示例4: test_basic_auth_custom_credentials

def test_basic_auth_custom_credentials():
    """
    Basic auth default credentials work.

    """
    config = dict(
        basic_auth=dict(
            credentials=dict(
                username="password",
            )
        )
    )

    graph = create_object_graph(name="example", testing=True, loader=lambda metadata: config)

    @graph.app.route("/ok")
    @graph.audit
    @graph.basic_auth.required
    def unauthorized():
        return "OK"

    client = graph.app.test_client()

    response = client.get("/ok", headers={
        "Authorization": encode_basic_auth("username", "password"),
    })
    assert_that(response.status_code, is_(equal_to(200)))
开发者ID:globality-corp,项目名称:microcosm-flask,代码行数:27,代码来源:test_basic_auth.py


示例5: setup

    def setup(self):
        self.graph = create_object_graph(name="example", testing=True, import_name="microcosm_postgres")
        self.company_store = self.graph.company_store

        self.context = SessionContext(self.graph)
        self.context.recreate_all()
        self.context.open()
开发者ID:globality-corp,项目名称:microcosm-postgres,代码行数:7,代码来源:test_cloning.py


示例6: test_ack

def test_ack():
    """
    Consumer delegates to SQS client.

    """
    def loader(metadata):
        return dict(
            sqs_consumer=dict(
                sqs_queue_url=FOO_QUEUE_URL,
            ),
            pubsub_message_codecs=dict(
                default=FooSchema,
            ),
        )

    graph = create_object_graph("example", testing=True, loader=loader)
    message = SQSMessage(
        consumer=graph.sqs_consumer,
        message_id=MESSAGE_ID,
        receipt_handle=RECEIPT_HANDLE,
        content=None,
    )
    message.ack()
    graph.sqs_consumer.sqs_client.delete_message.assert_called_with(
        QueueUrl='foo-queue-url',
        ReceiptHandle=RECEIPT_HANDLE,
    )
开发者ID:pokey,项目名称:microcosm-pubsub,代码行数:27,代码来源:test_consumer.py


示例7: test_codec_sqs_envelope

def test_codec_sqs_envelope():
    graph = create_object_graph("example", testing=True)
    consumer = None
    message_id = "message_id"
    receipt_handle = "receipt_handle"
    envelope = CodecSQSEnvelope(graph)

    media_type = created("foo")
    uri = "http://foo/id"

    sqs_message = envelope.parse_raw_message(consumer, dict(
        MessageId=message_id,
        ReceiptHandle=receipt_handle,
        Body=dumps(dict(
            Message=dumps(dict(
                mediaType=media_type,
                foo="bar",
                uri=uri,
            )),
        )),
    ))

    assert_that(sqs_message.content, is_(equal_to(dict(
        # NB: no foo key here because it's not part of the schema
        media_type=media_type,
        uri=uri,
    ))))
    assert_that(sqs_message.media_type, is_(equal_to(media_type)))
    assert_that(sqs_message.message_id, is_(equal_to(message_id)))
    assert_that(sqs_message.receipt_handle, is_(equal_to(receipt_handle)))
开发者ID:globality-corp,项目名称:microcosm-pubsub,代码行数:30,代码来源:test_envelope.py


示例8: test_configure_engine

def test_configure_engine():
    """
    Engine factory should work with zero configuration.

    """
    graph = create_object_graph(name="example", testing=True)
    engine = graph.postgres

    assert_that(engine, is_(instance_of(Engine)))

    # engine has expected configuration
    assert_that(
        str(engine.url),
        starts_with("postgresql://example:@"),
    )

    assert_that(
        str(engine.url),
        ends_with(":5432/example_test_db"),
    )

    # engine supports connections
    with engine.connect() as connection:
        row = connection.execute("SELECT 1;").fetchone()
        assert_that(row[0], is_(equal_to(1)))
开发者ID:globality-corp,项目名称:microcosm-postgres,代码行数:25,代码来源:test_engine.py


示例9: produce

def produce():
    """
    Produce test messages.

    """
    parser = ArgumentParser()
    parser.add_argument("--count", default=1, type=int)
    parser.add_argument("--message")
    parser.add_argument("--message-type", default="test")
    parser.add_argument("--topic-arn", required=True)
    args = parser.parse_args()

    def load_config(metadata):
        return dict(
            pubsub_message_codecs=dict(
                default=SimpleSchema,
            ),
            sns_topic_arns=dict(
                default=args.topic_arn,
            ),
        )

    graph = create_object_graph("example", loader=load_config)
    for _ in range(args.count):
        message_id = graph.sns_producer.produce(
            args.message_type,
            message=args.message or uuid4().hex,
            timestamp=time(),
        )
        print message_id  # noqa
开发者ID:pokey,项目名称:microcosm-pubsub,代码行数:30,代码来源:main.py


示例10: test_produce_custom_topic

def test_produce_custom_topic():
    """
    Producer delegates to SNS client.

    """
    def loader(metadata):
        return dict(
            pubsub_message_codecs=dict(
                default=FooSchema,
            ),
            sns_topic_arns=dict(
                default=None,
                mappings={
                    FOO_MEDIA_TYPE: FOO_TOPIC,
                },
            )
        )

    graph = create_object_graph("example", testing=True, loader=loader)

    # set up response
    graph.sns_producer.sns_client.publish.return_value = dict(MessageId=MESSAGE_ID)

    message_id = graph.sns_producer.produce(FOO_MEDIA_TYPE, bar="baz")

    assert_that(graph.sns_producer.sns_client.publish.call_count, is_(equal_to(1)))
    assert_that(graph.sns_producer.sns_client.publish.call_args[1]["TopicArn"], is_(equal_to(FOO_TOPIC)))
    assert_that(loads(graph.sns_producer.sns_client.publish.call_args[1]["Message"]), is_(equal_to({
        "bar": "baz",
        "mediaType": "application/vnd.globality.pubsub.foo",
    })))
    assert_that(message_id, is_(equal_to(MESSAGE_ID)))
开发者ID:pokey,项目名称:microcosm-pubsub,代码行数:32,代码来源:test_producer.py


示例11: test_configure_sessionmaker

def test_configure_sessionmaker():
    """
    Should create the `SQLAlchemy` sessionmaker

    """
    graph = create_object_graph(name="example", testing=True)
    assert_that(graph.sessionmaker, is_(instance_of(sessionmaker)))
开发者ID:globality-corp,项目名称:microcosm-postgres,代码行数:7,代码来源:test_sessionmaker.py


示例12: test_override_default_limit_from_request_header

def test_override_default_limit_from_request_header():
    graph = create_object_graph(name="example", testing=True)
    with graph.flask.test_request_context(headers={"X-Request-Limit": "2"}):
        page = OffsetLimitPage.from_dict(dict(foo="bar"))
        assert_that(page.offset, is_(equal_to(0)))
        assert_that(page.limit, is_(equal_to(2)))
        assert_that(page.kwargs, has_entry("foo", "bar"))
开发者ID:globality-corp,项目名称:microcosm-flask,代码行数:7,代码来源:test_paging.py


示例13: test_configure_flywheel_engine

def test_configure_flywheel_engine():
    """
    Should create the `flywheel` engine

    """
    graph = create_object_graph(name="example", testing=True, import_name="microcosm_dynamodb")
    assert_that(graph.dynamodb, is_(instance_of(Engine)))
开发者ID:pokey,项目名称:microcosm-dynamodb,代码行数:7,代码来源:test_factories.py


示例14: test_configure_flask

def test_configure_flask():
    """
    Should create the `Flask` application.

    """
    graph = create_object_graph(name="example", testing=True)
    assert_that(graph.app, is_(instance_of(Flask)))
开发者ID:globality-corp,项目名称:microcosm-flask,代码行数:7,代码来源:test_factories.py


示例15: setup

    def setup(self):
        self.graph = create_object_graph(
            name="example",
            testing=True,
            import_name="microcosm_postgres",
        )
        self.company_store = self.graph.company_store

        self.companies = [
            Company(
                name="name1",
                type=CompanyType.private,
            ),
            Company(
                name="name2",
                type=CompanyType.private,
            ),
            Company(
                name="name3",
                type=CompanyType.private,
            ),
        ]

        with SessionContext(self.graph) as context:
            context.recreate_all()
开发者ID:globality-corp,项目名称:microcosm-postgres,代码行数:25,代码来源:test_temporary.py


示例16: test_discovery

def test_discovery():
    graph = create_object_graph(name="example", testing=True)
    graph.use("discovery_convention")

    ns = Namespace("foo")

    @graph.route(ns.collection_path, Operation.Search, ns)
    def search_foo():
        pass

    client = graph.flask.test_client()

    response = client.get("/api")
    assert_that(response.status_code, is_(equal_to(200)))
    data = loads(response.get_data().decode("utf-8"))
    assert_that(data, is_(equal_to({
        "_links": {
            "search": [{
                "href": "http://localhost/api/foo?offset=0&limit=20",
                "type": "foo",
            }],
            "self": {
                "href": "http://localhost/api?offset=0&limit=20",
            },
        }
    })))
开发者ID:globality-corp,项目名称:microcosm-flask,代码行数:26,代码来源:test_discovery.py


示例17: setup

    def setup(self):
        loaders = load_each(
            load_from_dict(
                multi_tenant_key_registry=dict(
                    context_keys=[
                        "private",
                    ],
                    key_ids=[
                        "key_id",
                    ],
                ),
            ),
            load_from_environ,
        )
        self.graph = create_object_graph(
            name="example",
            testing=True,
            import_name="microcosm_postgres",
            loader=loaders,
        )
        self.encryptable_store = self.graph.encryptable_store
        self.encrypted_store = self.graph.encrypted_store
        self.json_encryptable_store = self.graph.json_encryptable_store
        self.json_encrypted_store = self.graph.json_encrypted_store
        self.nullable_encryptable_store = self.graph.nullable_encryptable_store
        self.nullable_encrypted_store = self.graph.nullable_encrypted_store
        self.encryptor = self.graph.multi_tenant_encryptor

        with SessionContext(self.graph) as context:
            context.recreate_all()
开发者ID:globality-corp,项目名称:microcosm-postgres,代码行数:30,代码来源:test_models.py


示例18: setup

 def setup(self):
     self.graph = create_object_graph("test")
     self.graph.use(
         "pubsub_message_schema_registry",
         "pubsub_lifecycle_change",
     )
     self.graph.lock()
开发者ID:globality-corp,项目名称:microcosm-pubsub,代码行数:7,代码来源:test_conventions.py


示例19: test_produce_custom_topic

def test_produce_custom_topic():
    """
    Producer delegates to SNS client.

    """
    def loader(metadata):
        return dict(
            sns_topic_arns=dict(
                default=None,
                mappings={
                    DerivedSchema.MEDIA_TYPE: "special-topic",
                },
            )
        )

    graph = create_object_graph("example", testing=True, loader=loader)
    graph.use("opaque")

    # set up response
    graph.sns_producer.sns_client.publish.return_value = dict(MessageId=MESSAGE_ID)

    message_id = graph.sns_producer.produce(DerivedSchema.MEDIA_TYPE, data="data")

    assert_that(graph.sns_producer.sns_client.publish.call_count, is_(equal_to(1)))
    assert_that(graph.sns_producer.sns_client.publish.call_args[1]["TopicArn"], is_(equal_to("special-topic")))
    assert_that(loads(graph.sns_producer.sns_client.publish.call_args[1]["Message"]), is_(equal_to({
        "data": "data",
        "mediaType": DerivedSchema.MEDIA_TYPE,
        "opaqueData": {},
    })))
    assert_that(message_id, is_(equal_to(MESSAGE_ID)))
开发者ID:globality-corp,项目名称:microcosm-pubsub,代码行数:31,代码来源:test_producer.py


示例20: test_configure_logging_with_custom_library_levels

def test_configure_logging_with_custom_library_levels():
    """
    Logging levels can be configured.

    """
    def loader(metadata):
        return dict(
            logging=dict(
                level=INFO,
                levels=dict(
                    default=dict(
                        debug=["foo", "bar"],
                    ),
                    override=dict(
                        warn=["foo"],
                    )
                )
            )
        )

    graph = create_object_graph(name="test", testing=True, loader=loader)
    graph.use("logger")

    assert_that(getLogger("foo").getEffectiveLevel(), is_(equal_to(WARN)))
    assert_that(getLogger("bar").getEffectiveLevel(), is_(equal_to(DEBUG)))

    getLogger("bar").info("Bar should be visible at info")
    getLogger("foo").info("Foo should not be visible at info")
    getLogger("foo").warn("Foo should be visible at warn")
开发者ID:globality-corp,项目名称:microcosm-logging,代码行数:29,代码来源:test_factories.py



注:本文中的microcosm.api.create_object_graph函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python app_context.get_app函数代码示例发布时间:2022-05-27
下一篇:
Python microbit.sleep函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap