本文整理汇总了Python中mimic.core.MimicCore类的典型用法代码示例。如果您正苦于以下问题:Python MimicCore类的具体用法?Python MimicCore怎么用?Python MimicCore使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MimicCore类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
示例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)
示例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)
示例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)
示例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")))
示例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)
示例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')))
示例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)
示例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'
)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)