本文整理汇总了Python中pyrax.utils.random_name函数的典型用法代码示例。如果您正苦于以下问题:Python random_name函数的具体用法?Python random_name怎么用?Python random_name使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了random_name函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, name=None, info=None, *args, **kwargs):
name = name or utils.random_name(ascii_only=True)
info = info or {"fake": "fake"}
super(FakeLoadBalancer, self).__init__(name, info, *args, **kwargs)
self.id = utils.random_name(ascii_only=True)
self.port = random.randint(1, 256)
self.manager = FakeLoadBalancerManager()
示例2: test_update_user
def test_update_user(self):
for cls in self.id_classes.values():
ident = cls()
resp = fakes.FakeIdentityResponse()
resp.response_type = "users"
ident.method_put = Mock(return_value=resp)
fake_name = utils.random_name()
fake_email = utils.random_name()
fake_username = utils.random_name()
fake_uid = utils.random_name()
fake_region = utils.random_name()
fake_enabled = random.choice((True, False))
kwargs = {"email": fake_email, "username": fake_username,
"uid": fake_uid, "enabled": fake_enabled}
if isinstance(ident, self.rax_identity_class):
kwargs["defaultRegion"] = fake_region
ident.update_user(fake_name, **kwargs)
cargs = ident.method_put.call_args
self.assertEqual(len(cargs), 2)
self.assertEqual(cargs[0], ("users/%s" % fake_name, ))
data = cargs[1]["data"]["user"]
self.assertEqual(data["enabled"], fake_enabled)
self.assertEqual(data["username"], fake_username)
self.assert_(fake_email in data.values())
if isinstance(ident, self.rax_identity_class):
self.assert_(fake_region in data.values())
示例3: test_update_user
def test_update_user(self):
ident = self.rax_identity_class()
resp = fakes.FakeIdentityResponse()
resp.response_type = "users"
ident.method_put = Mock(return_value=resp)
fake_name = utils.random_name()
fake_email = utils.random_name()
fake_username = utils.random_name()
fake_uid = utils.random_name()
fake_region = utils.random_name()
fake_enabled = random.choice((True, False))
ident.update_user(
fake_name,
email=fake_email,
username=fake_username,
uid=fake_uid,
defaultRegion=fake_region,
enabled=fake_enabled,
)
cargs = ident.method_put.call_args
self.assertEqual(len(cargs), 2)
self.assertEqual(cargs[0], ("users/%s" % fake_name,))
data = cargs[1]["data"]["user"]
self.assertEqual(data["enabled"], fake_enabled)
self.assertEqual(data["username"], fake_username)
self.assert_(fake_email in data.values())
self.assert_(fake_region in data.values())
示例4: test_call
def test_call(self):
ident = self.base_identity_class()
sav_post = requests.post
requests.post = Mock()
sav_debug = ident.http_log_debug
ident.http_log_debug = True
uri = "https://%s/%s" % (utils.random_name(), utils.random_name())
sav_stdout = sys.stdout
out = StringIO.StringIO()
sys.stdout = out
utils.add_method(ident, lambda self: "", "_get_auth_endpoint")
dkv = utils.random_name()
data = {dkv: dkv}
jdata = json.dumps(data)
hkv = utils.random_name()
headers = {hkv: hkv}
for std_headers in (True, False):
expected_headers = ident._standard_headers() if std_headers else {}
expected_headers.update(headers)
for admin in (True, False):
ident.method_post(uri, data=data, headers=headers,
std_headers=std_headers, admin=admin)
requests.post.assert_called_with(uri, data=jdata,
headers=expected_headers, verify=True)
self.assertTrue(out.getvalue())
out.seek(0)
out.truncate()
out.close()
requests.post = sav_post
ident.http_log_debug = sav_debug
sys.stdout = sav_stdout
示例5: test_auth_with_token_rax
def test_auth_with_token_rax(self):
ident = self.rax_identity_class()
mid = utils.random_name()
oid = utils.random_name()
token = utils.random_name()
class FakeResp(object):
info = None
def json(self):
return self.info
resp_main = FakeResp()
resp_main.info = {"access": {
"serviceCatalog": [{"a": "a", "name": "a", "type": "a"}],
"user": {"roles":
[{"tenantId": oid, "name": "object-store:default"}],
}}}
resp_obj = FakeResp()
resp_obj.info = {"access": {
"serviceCatalog": [{"b": "b", "name": "b", "type": "b"}]}}
ident._call_token_auth = Mock(side_effect=(resp_main, resp_obj))
def fake_parse(dct):
svcs = dct.get("access", {}).get("serviceCatalog", {})
pyrax.services = [svc["name"] for svc in svcs]
ident._parse_response = fake_parse
ident.auth_with_token(token, tenant_id=mid)
ident._call_token_auth.assert_called_with(token, oid, None)
self.assertTrue("a" in pyrax.services)
self.assertTrue("b" in pyrax.services)
示例6: test_clt_resolve_lbs_dict
def test_clt_resolve_lbs_dict(self):
clt = fakes.FakeAutoScaleClient()
key = utils.random_name()
val = utils.random_name()
lb_dict = {key: val}
ret = clt._resolve_lbs(lb_dict)
self.assertEqual(ret, [lb_dict])
示例7: test_detach_from_instance_fail
def test_detach_from_instance_fail(self):
vol = self.volume
srv_id = utils.random_name()
att_id = utils.random_name()
vol.attachments = [{"server_id": srv_id, "id": att_id}]
vol._nova_volumes.delete_server_volume = Mock(side_effect=Exception("test"))
self.assertRaises(exc.VolumeDetachmentFailed, vol.detach)
示例8: test_get_temp_url_missing_key
def test_get_temp_url_missing_key(self):
client = self.client
cname = utils.random_name(ascii_only=True)
oname = utils.random_name(ascii_only=True)
client.connection.head_account = Mock()
client.connection.head_account.return_value = {"some-other-key": "no"}
self.assertRaises(exc.MissingTemporaryURLKey, client.get_temp_url, cname, oname, seconds=120, method="GET")
示例9: test_http_methods
def test_http_methods(self):
ident = self.base_identity_class()
ident._call = Mock()
uri = utils.random_name()
dkv = utils.random_name()
data = {dkv: dkv}
hkv = utils.random_name()
headers = {hkv: hkv}
std_headers = True
ident.method_get(uri, admin=False, data=data, headers=headers,
std_headers=std_headers)
ident._call.assert_called_with(requests.get, uri, False, data, headers,
std_headers)
ident.method_head(uri, admin=False, data=data, headers=headers,
std_headers=std_headers)
ident._call.assert_called_with(requests.head, uri, False, data, headers,
std_headers)
ident.method_post(uri, admin=False, data=data, headers=headers,
std_headers=std_headers)
ident._call.assert_called_with(requests.post, uri, False, data, headers,
std_headers)
ident.method_put(uri, admin=False, data=data, headers=headers,
std_headers=std_headers)
ident._call.assert_called_with(requests.put, uri, False, data, headers,
std_headers)
ident.method_delete(uri, admin=False, data=data, headers=headers,
std_headers=std_headers)
ident._call.assert_called_with(requests.delete, uri, False, data,
headers, std_headers)
示例10: test_snapshot_name_property
def test_snapshot_name_property(self):
snap = self.snapshot
nm = utils.random_name()
snap.display_name = nm
self.assertEqual(snap.name, snap.display_name)
nm = utils.random_name()
snap.name = nm
self.assertEqual(snap.name, snap.display_name)
示例11: test_volume_description_property
def test_volume_description_property(self):
vol = self.volume
nm = utils.random_name()
vol.display_description = nm
self.assertEqual(vol.description, vol.display_description)
nm = utils.random_name()
vol.description = nm
self.assertEqual(vol.description, vol.display_description)
示例12: test_volume_name_property
def test_volume_name_property(self):
vol = self.volume
nm = utils.random_name()
vol.display_name = nm
self.assertEqual(vol.name, vol.display_name)
nm = utils.random_name()
vol.name = nm
self.assertEqual(vol.name, vol.display_name)
示例13: test_client_create_snapshot
def test_client_create_snapshot(self):
clt = self.client
vol = self.volume
name = utils.random_name()
description = utils.random_name()
vol.create_snapshot = Mock()
clt.create_snapshot(vol, name=name, description=description, force=True)
vol.create_snapshot.assert_called_once_with(name=name, description=description, force=True)
示例14: test_create_snapshot
def test_create_snapshot(self):
vol = self.volume
vol._snapshot_manager.create = Mock()
name = utils.random_name()
desc = utils.random_name()
vol.create_snapshot(name=name, description=desc, force=False)
vol._snapshot_manager.create.assert_called_once_with(volume=vol, name=name,
description=desc, force=False)
示例15: test_name
def test_name(self):
sg = self.scaling_group
name = utils.random_name()
newname = utils.random_name()
sg.groupConfiguration = {"name": name}
self.assertEqual(sg.name, name)
sg.name = newname
self.assertEqual(sg.name, newname)