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

Python core.MimicCore类代码示例

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

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



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

示例1: test_entries_for_tenant_internal

    def test_entries_for_tenant_internal(self):
        """
        Validate that the internal API shows up in the service catalog for a
        given tenant.
        """
        iapi = make_example_internal_api(self)
        core = MimicCore(Clock(), [iapi])

        prefix_map = {}
        base_uri = "http://some/random/prefix"
        catalog_entries = [
            entry
            for entry in core.entries_for_tenant(
                'some-tenant',
                prefix_map,
                base_uri
            )
        ]

        self.assertEqual(len(core._uuid_to_api_internal), 1)
        self.assertEqual(len(core._uuid_to_api_external), 0)
        self.assertEqual(len(catalog_entries), 1)
        self.assertEqual(catalog_entries[0].type, "serviceType")
        self.assertEqual(catalog_entries[0].name, "serviceName")
        self.assertEqual(catalog_entries[0].tenant_id, "some-tenant")
        self.assertEqual(len(catalog_entries[0].endpoints), 1)
开发者ID:rackerlabs,项目名称:mimic,代码行数:26,代码来源:test_core.py


示例2: test_auth_accepts_tenant_name

    def test_auth_accepts_tenant_name(self):
        """
        If "tenantName" is passed, the tenant specified is used instead of a
        generated tenant ID.
        """
        core = MimicCore(Clock(), [])
        root = MimicRoot(core).app.resource()

        (response, json_body) = self.successResultOf(json_request(
            self, root, "POST", "/identity/v2.0/tokens",
            {
                "auth": {
                    "passwordCredentials": {
                        "username": "demoauthor",
                        "password": "theUsersPassword"
                    },
                    "tenantName": "turtlepower"
                }
            }
        ))

        self.assertEqual(200, response.code)
        self.assertEqual("turtlepower",
                         json_body['access']['token']['tenant']['id'])
        token = json_body['access']['token']['id']
        session = core.session_for_token(token)
        self.assertEqual(token, session.token)
        self.assertEqual("turtlepower", session.tenant_id)
开发者ID:jirwin,项目名称:mimic,代码行数:28,代码来源:test_auth.py


示例3: test_response_has_auth_token

    def test_response_has_auth_token(self):
        """
        The JSON response has a access.token.id key corresponding to its
        MimicCore session, and therefore access.token.tenant.id should match
        that session's tenant_id.
        """
        core = MimicCore(Clock(), [])
        root = MimicRoot(core).app.resource()

        (response, json_body) = self.successResultOf(json_request(
            self, root, "POST", "/identity/v2.0/tokens",
            {
                "auth": {
                    "passwordCredentials": {
                        "username": "demoauthor",
                        "password": "theUsersPassword"
                    }

                }
            }
        ))

        self.assertEqual(200, response.code)
        token = json_body['access']['token']['id']
        tenant_id = json_body['access']['token']['tenant']['id']
        session = core.session_for_token(token)
        self.assertEqual(token, session.token)
        self.assertEqual(tenant_id, session.tenant_id)
开发者ID:jirwin,项目名称:mimic,代码行数:28,代码来源:test_auth.py


示例4: test_different_username_different_token

 def test_different_username_different_token(self):
     """
     Sessions are distinct if they are requested with distinct usernames.
     """
     core = MimicCore(Clock(), [])
     a = core.session_for_username_password("a", "ignored")
     b = core.session_for_username_password("b", "ignored")
     self.assertNotEqual(a.token, b.token)
开发者ID:jirwin,项目名称:mimic,代码行数:8,代码来源:test_core.py


示例5: test_no_uuids_if_no_plugins

 def test_no_uuids_if_no_plugins(self):
     """
     If there are no plugins provided to :class:`MimicCore`, there are no
     uri prefixes or entries for the tenant.
     """
     core = MimicCore(Clock(), [])
     self.assertEqual(0, len(core._uuid_to_api))
     self.assertEqual([], list(core.entries_for_tenant("any_tenant", {}, "http://mimic")))
开发者ID:tawalton,项目名称:mimic,代码行数:8,代码来源:test_core.py


示例6: test_get_external_api_invalid

 def test_get_external_api_invalid(self):
     """
     Validate retrieving a non-existent external API which should raise an
     `IndexError` exception.
     """
     core = MimicCore(Clock(), [])
     with self.assertRaises(ServiceDoesNotExist):
         core.get_external_api(self.eeapi_name)
开发者ID:rackerlabs,项目名称:mimic,代码行数:8,代码来源:test_core.py


示例7: test_no_uri_prefixes_if_no_plugins

 def test_no_uri_prefixes_if_no_plugins(self):
     """
     If there are no plugins provided to :class:`MimicCore`, there are no
     uri prefixes or entries for the tenant.
     """
     core = MimicCore(Clock(), [])
     self.assertEqual(0, len(core.uri_prefixes))
     self.assertEqual([], list(core.entries_for_tenant('any_tenant', {},
                                                       'http://mimic')))
开发者ID:jirwin,项目名称:mimic,代码行数:9,代码来源:test_core.py


示例8: test_session_for_tenant_id

 def test_session_for_tenant_id(self):
     """
     MimicCore.session_for_tenant_id will return a session that can be
     retrieved by tenant_id.
     """
     clock = Clock()
     core = MimicCore(clock, [])
     session = core.session_for_username_password("someuser", "testpass")
     session2 = core.session_for_tenant_id(session.tenant_id)
     self.assertIdentical(session, session2)
开发者ID:jirwin,项目名称:mimic,代码行数:10,代码来源:test_core.py


示例9: test_remove_api_invalid

 def test_remove_api_invalid(self):
     """
     Validate API removal fails when it does not find the
     api name in the listing
     """
     core = MimicCore(Clock(), [])
     with self.assertRaises(ServiceDoesNotExist):
         core.remove_external_api(
             'some-id'
         )
开发者ID:rackerlabs,项目名称:mimic,代码行数:10,代码来源:test_core.py


示例10: test_by_username_after_token

 def test_by_username_after_token(self):
     """
     MimicCore.session_for_username_password should retrieve the same
     session that was created by MimicCore.session_for_token.
     """
     core = MimicCore(Clock(), [])
     a = core.session_for_token("testtoken")
     b = core.session_for_username_password(a.username, "testpswd")
     c = core.session_for_api_key(a.username, "testapikey")
     self.assertIdentical(a, b)
     self.assertIdentical(a, c)
开发者ID:jirwin,项目名称:mimic,代码行数:11,代码来源:test_core.py


示例11: test_generate_username_from_tenant_id

 def test_generate_username_from_tenant_id(self):
     """
     MimicCore.session_for_tenant_id will create a new session with a
     synthetic username if no such tenant ID yet exists.
     """
     clock = Clock()
     core = MimicCore(clock, [])
     session = core.session_for_tenant_id("user_specified_tenant")
     session2 = core.session_for_username_password(session.username,
                                                   "testpass")
     self.assertIdentical(session, session2)
开发者ID:jirwin,项目名称:mimic,代码行数:11,代码来源:test_core.py


示例12: test_by_token_after_username

 def test_by_token_after_username(self):
     """
     MimicCore.session_for_token should retrieve the same session that was
     created by MimicCore.session_for_username_password.
     """
     core = MimicCore(Clock(), [])
     a = core.session_for_username_password("username", "testpswd")
     b = core.session_for_token(a.token)
     self.assertIdentical(a, b)
     c = core.session_for_api_key("apiuser", "testkey")
     d = core.session_for_token(c.token)
     self.assertIdentical(c, d)
开发者ID:jirwin,项目名称:mimic,代码行数:12,代码来源:test_core.py


示例13: test_get_external_api

    def test_get_external_api(self):
        """
        Validate retrieving an external API.
        """
        eeapi = make_example_external_api(
            self,
            name=self.eeapi_name,
            set_enabled=True
        )

        core = MimicCore(Clock(), [eeapi])
        api_from_core = core.get_external_api(
            eeapi.uuid_key
        )
        self.assertEqual(eeapi, api_from_core)
开发者ID:rackerlabs,项目名称:mimic,代码行数:15,代码来源:test_core.py


示例14: test_entries_for_tenant_combined

    def test_entries_for_tenant_combined(self):
        """
        Validate that both internal and external APIs show up in the service
        catalog for a given tenant.
        """
        eeapi = make_example_external_api(
            self,
            name=self.eeapi_name,
            set_enabled=True
        )

        core = MimicCore(Clock(), [eeapi, make_example_internal_api(self)])

        prefix_map = {}
        base_uri = "http://some/random/prefix"
        catalog_entries = [
            entry
            for entry in core.entries_for_tenant(
                'some-tenant',
                prefix_map,
                base_uri
            )
        ]

        self.assertEqual(len(core._uuid_to_api_internal), 1)
        self.assertEqual(len(core._uuid_to_api_external), 1)
        self.assertEqual(len(catalog_entries), 2)

        found_internal = False
        found_external = False

        for catalog_entry in catalog_entries:
            if catalog_entry.name == eeapi.name_key:
                found_external = True
                self.assertEqual(catalog_entry.type, eeapi.type_key)
                self.assertEqual(catalog_entry.name, eeapi.name_key)
                self.assertEqual(catalog_entry.tenant_id, "some-tenant")
                self.assertEqual(len(catalog_entry.endpoints), 1)

            elif catalog_entry.name == "serviceName":
                found_internal = True
                self.assertEqual(catalog_entry.type, "serviceType")
                self.assertEqual(catalog_entry.name, "serviceName")
                self.assertEqual(catalog_entry.tenant_id, "some-tenant")
                self.assertEqual(len(catalog_entry.endpoints), 1)

        self.assertTrue(found_internal)
        self.assertTrue(found_external)
开发者ID:rackerlabs,项目名称:mimic,代码行数:48,代码来源:test_core.py


示例15: test_session_created_for_token

    def test_session_created_for_token(self):
        """
        A session is created for the token provided
        """
        core = MimicCore(Clock(), [])
        root = MimicRoot(core).app.resource()

        token = '1234567890'

        request(
            self, root, "GET",
            "/identity/v2.0/tokens/{0}/endpoints".format(token)
        )

        session = core.session_for_token(token)
        self.assertEqual(token, session.token)
开发者ID:jirwin,项目名称:mimic,代码行数:16,代码来源:test_auth.py


示例16: test_from_plugin_includes_all_plugins

 def test_from_plugin_includes_all_plugins(self):
     """
     Using the :func:`MimicRoot.fromPlugin` creator for a
     :class:`MimicCore`, the nova and loadbalancer plugins are included.
     """
     core = MimicCore.fromPlugins(Clock())
     plugin_apis = set((
         glance_plugin.glance,
         loadbalancer_plugin.loadbalancer,
         loadbalancer_plugin.loadbalancer_control,
         maas_plugin.maas,
         maas_plugin.maas_control,
         nova_plugin.nova,
         nova_plugin.nova_control_api,
         queue_plugin.queue,
         rackconnect_v3_plugin.rackconnect,
         swift_plugin.swift,
         cloudfeeds_plugin.cloudfeeds,
         cloudfeeds_plugin.cloudfeeds_control,
     ))
     self.assertEqual(
         plugin_apis,
         set(core._uuid_to_api.values()))
     self.assertEqual(
         len(plugin_apis),
         len(list(core.entries_for_tenant('any_tenant', {},
                                          'http://mimic'))))
开发者ID:raghav3259,项目名称:mimic,代码行数:27,代码来源:test_core.py


示例17: test_load_domain_plugin_includes_all_domain_plugins

    def test_load_domain_plugin_includes_all_domain_plugins(self):
        """
        Using the :func:`MimicRoot.fromPlugin` creator for a
        :class:`MimicCore`, domain mocks implementing `class`:`IAPIDomainMock`
        are included.
        """
        self.root = FilePath(self.mktemp())
        self.root.createDirectory()
        plugin = b"""from mimic.test.dummy import ExampleDomainAPI
dummy_domain_plugin = ExampleDomainAPI()
"""
        self.root.child('fake_plugin.py').setContent(plugin)

        import mimic.plugins
        mimic.plugins.__path__.append(self.root.path)
        from mimic.plugins import fake_plugin

        def cleanup():
            sys.modules.pop("mimic.plugins.fake_plugin")
            del mimic.plugins.fake_plugin
        self.addCleanup(cleanup)

        core = MimicCore.fromPlugins(Clock())
        self.assertIn(
            fake_plugin.dummy_domain_plugin,
            core.domains
        )
开发者ID:rackerlabs,项目名称:mimic,代码行数:27,代码来源:test_core.py


示例18: test_remove_api_with_endpoints

 def test_remove_api_with_endpoints(self):
     """
     Validate an API cannot be removed if it still has
     endpoints assigned to it
     """
     eeapi = make_example_external_api(
         self,
         name=self.eeapi_name,
         set_enabled=True
     )
     self.assertIsNotNone(eeapi)
     core = MimicCore(Clock(), [eeapi])
     with self.assertRaises(ServiceHasTemplates):
         core.remove_external_api(
             eeapi.uuid_key
         )
开发者ID:rackerlabs,项目名称:mimic,代码行数:16,代码来源:test_core.py


示例19: test_from_plugin_includes_all_plugins

 def test_from_plugin_includes_all_plugins(self):
     """
     Using the :func:`MimicRoot.fromPlugin` creator for a
     :class:`MimicCore`, the nova and loadbalancer plugins are included.
     """
     core = MimicCore.fromPlugins(Clock())
     plugin_apis = set((
         glance_plugin.glance,
         heat_plugin.heat,
         loadbalancer_plugin.loadbalancer,
         loadbalancer_plugin.loadbalancer_control,
         maas_plugin.maas,
         maas_plugin.maas_control,
         nova_plugin.nova,
         nova_plugin.nova_control_api,
         queue_plugin.queue,
         rackconnect_v3_plugin.rackconnect,
         swift_plugin.swift,
         cloudfeeds_plugin.cloudfeeds,
         cloudfeeds_plugin.cloudfeeds_control,
         neutron_plugin.neutron,
         dns_plugin.dns,
         cinder_plugin.cinder
     ))
     # all plugins should be on the internal listing
     self.assertEqual(
         plugin_apis,
         set(core._uuid_to_api_internal.values()))
     # the external listing should still be empty
     self.assertEqual(
         set([]),
         set(core._uuid_to_api_external.values()))
开发者ID:rackerlabs,项目名称:mimic,代码行数:32,代码来源:test_core.py


示例20: test_entries_for_tenant_external_with_tenantid_replacement

    def test_entries_for_tenant_external_with_tenantid_replacement(self):
        """
        Validate that the external API shows up in the service catalog for a
        given tenant and the tenant id is in the URL.
        """
        eeapi = make_example_external_api(
            self,
            name=self.eeapi_name,
            set_enabled=True
        )

        tenant_id = 'some-tenant-other'

        ept_internal_url = "http://internal.url/v1/" + tenant_id
        ept_public_url = "http://public.url/v1/" + tenant_id
        for ept in eeapi.endpoint_templates.values():
            ept.internal_url = "http://internal.url/v1/%tenant_id%"
            ept.public_url = "http://public.url/v1/%tenant_id%"

        core = MimicCore(Clock(), [eeapi])

        prefix_map = {}
        base_uri = "http://some/random/prefix"
        catalog_entries = [
            entry
            for entry in core.entries_for_tenant(
                tenant_id,
                prefix_map,
                base_uri
            )
        ]

        self.assertEqual(len(core._uuid_to_api_internal), 0)
        self.assertEqual(len(core._uuid_to_api_external), 1)
        self.assertEqual(len(catalog_entries), 1)
        self.assertEqual(catalog_entries[0].type, eeapi.type_key)
        self.assertEqual(catalog_entries[0].name, eeapi.name_key)
        self.assertEqual(catalog_entries[0].tenant_id, tenant_id)
        self.assertEqual(len(catalog_entries[0].endpoints), 1)
        self.assertEqual(
            catalog_entries[0].endpoints[0].internal_url,
            ept_internal_url
        )
        self.assertEqual(
            catalog_entries[0].endpoints[0].complete_url,
            ept_public_url
        )
开发者ID:rackerlabs,项目名称:mimic,代码行数:47,代码来源:test_core.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python helpers.json_request函数代码示例发布时间:2022-05-27
下一篇:
Python mimetypes.MimeTypes类代码示例发布时间: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