本文整理汇总了Python中pyrax.utils.random_ascii函数的典型用法代码示例。如果您正苦于以下问题:Python random_ascii函数的具体用法?Python random_ascii怎么用?Python random_ascii使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了random_ascii函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_call
def test_call(self):
ident = self.base_identity_class()
sav_req = pyrax.http.request
pyrax.http.request = Mock()
sav_debug = ident.http_log_debug
ident.http_log_debug = True
uri = "https://%s/%s" % (utils.random_ascii(), utils.random_ascii())
sav_stdout = sys.stdout
out = StringIO.StringIO()
sys.stdout = out
utils.add_method(ident, lambda self: "", "_get_auth_endpoint")
dkv = utils.random_ascii()
data = {dkv: dkv}
hkv = utils.random_ascii()
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)
pyrax.http.request.assert_called_with("POST", uri, body=data,
headers=expected_headers)
self.assertEqual(out.getvalue(), "")
out.seek(0)
out.truncate()
out.close()
pyrax.http.request = sav_req
ident.http_log_debug = sav_debug
sys.stdout = sav_stdout
示例2: __init__
def __init__(self, name=None, info=None, *args, **kwargs):
name = name or utils.random_ascii()
info = info or {"fake": "fake"}
super(FakeLoadBalancer, self).__init__(name, info, *args, **kwargs)
self.id = utils.random_ascii()
self.port = random.randint(1, 256)
self.manager = FakeLoadBalancerManager()
示例3: test_revoke_user_access
def test_revoke_user_access(self):
inst = self.instance
fakeuser = utils.random_ascii()
dbname1 = utils.random_ascii()
inst._user_manager.api.method_delete = Mock(return_value=(None, None))
inst.revoke_user_access(fakeuser, dbname1, strict=False)
inst._user_manager.api.method_delete.assert_called_once_with(
"/None/%s/databases/%s" % (fakeuser, dbname1))
示例4: test_get_db_names_fail
def test_get_db_names_fail(self):
inst = self.instance
mgr = inst._user_manager
mgr.instance = inst
dbname1 = utils.random_ascii()
dbname2 = utils.random_ascii()
inst.list_databases = Mock(return_value=((dbname1, dbname2)))
self.assertRaises(exc.NoSuchDatabase, mgr._get_db_names, "BAD")
示例5: test_grant_user_access
def test_grant_user_access(self):
inst = self.instance
fakeuser = utils.random_ascii()
dbname1 = utils.random_ascii()
inst._user_manager.api.method_put = Mock(return_value=(None, None))
inst.grant_user_access(fakeuser, dbname1, strict=False)
inst._user_manager.api.method_put.assert_called_once_with(
"/None/%s/databases" % fakeuser, body={"databases": [{"name":
dbname1}]})
示例6: test_list_user_access
def test_list_user_access(self):
inst = self.instance
dbname1 = utils.random_ascii()
dbname2 = utils.random_ascii()
acc = {"databases": [{"name": dbname1}, {"name": dbname2}]}
inst._user_manager.api.method_get = Mock(return_value=(None, acc))
db_list = inst.list_user_access("fakeuser")
self.assertEqual(len(db_list), 2)
self.assertTrue(db_list[0].name in (dbname1, dbname2))
示例7: test_get_db_names
def test_get_db_names(self):
inst = self.instance
mgr = inst._user_manager
mgr.instance = inst
dbname1 = utils.random_ascii()
dbname2 = utils.random_ascii()
inst.list_databases = Mock(return_value=((dbname1, dbname2)))
resp = mgr._get_db_names(dbname1)
self.assertEqual(resp, [dbname1])
示例8: test_get_db_names_not_strict
def test_get_db_names_not_strict(self):
inst = self.instance
mgr = inst._user_manager
mgr.instance = inst
dbname1 = utils.random_ascii()
dbname2 = utils.random_ascii()
inst.list_databases = Mock(return_value=((dbname1, dbname2)))
resp = mgr._get_db_names("BAD", strict=False)
self.assertEqual(resp, ["BAD"])
示例9: test_download_object
def test_download_object(self):
cont = self.container
cont.client.download_object = Mock()
oname = utils.random_ascii()
dname = utils.random_ascii()
stru = random.choice((True, False))
cont.download_object(oname, dname, structure=stru)
cont.client.download_object.assert_called_once_with(cont, oname,
dname, structure=stru)
示例10: test_client_snap_mgr_create_snapshot
def test_client_snap_mgr_create_snapshot(self):
clt = self.client
vol = self.volume
name = utils.random_ascii()
description = utils.random_ascii()
mgr = clt._snapshot_manager
snap = fakes.FakeBlockStorageSnapshot()
mgr._create = Mock(return_value=snap)
ret = mgr.create(name, vol, description=description, force=True)
self.assertTrue(isinstance(ret, CloudBlockStorageSnapshot))
示例11: test_case_insensitive_update
def test_case_insensitive_update(self):
k1 = utils.random_ascii()
k2 = utils.random_ascii()
k2up = k2.upper()
k3 = utils.random_ascii()
d1 = {k1: "fake", k2up: "fake"}
d2 = {k2: "NEW", k3: "NEW"}
expected = {k1: "fake", k2up: "NEW", k3: "NEW"}
utils.case_insensitive_update(d1, d2)
self.assertEqual(d1, expected)
示例12: test_get_temp_url
def test_get_temp_url(self):
cont = self.container
nm = utils.random_ascii()
sav = cont.name
cont.name = utils.random_ascii()
cont.client.get_temp_url = Mock()
secs = random.randint(1, 1000)
cont.get_temp_url(nm, seconds=secs)
cont.client.get_temp_url.assert_called_with(cont, nm, seconds=secs,
method="GET")
cont.name = sav
示例13: test_change_user_password
def test_change_user_password(self):
inst = self.instance
fakename = utils.random_ascii()
newpass = utils.random_ascii()
resp = fakes.FakeResponse()
resp.status_code = 202
inst._user_manager.api.method_put = Mock(return_value=(resp, {}))
fakeuser = fakes.FakeDatabaseUser(inst._user_manager, {"name": fakename})
inst._user_manager.get = Mock(return_value=fakeuser)
inst.change_user_password(fakename, newpass)
inst._user_manager.api.method_put.assert_called_once_with(
"/None/%s" % fakename, body={"user": {"password": newpass}})
示例14: test_api_request_missing_clt_id
def test_api_request_missing_clt_id(self):
clt = self.client
uri = utils.random_ascii()
method = utils.random_ascii()
kwargs = {"fake": utils.random_ascii()}
err = exc.BadRequest("400", 'The "Client-ID" header is required.')
clt._time_request = Mock(side_effect=err)
clt.management_url = utils.random_unicode()
id_svc = pyrax.identity
sav = id_svc.authenticate
id_svc.authenticate = Mock()
self.assertRaises(exc.QueueClientIDNotDefined, clt._api_request, uri,
method, **kwargs)
id_svc.authenticate = sav
示例15: test_api_request_other_error
def test_api_request_other_error(self):
clt = self.client
uri = utils.random_ascii()
method = utils.random_ascii()
kwargs = {"fake": utils.random_ascii()}
err = exc.BadRequest("400", "Some other message")
clt._time_request = Mock(side_effect=err)
clt.management_url = utils.random_unicode()
id_svc = pyrax.identity
sav = id_svc.authenticate
id_svc.authenticate = Mock()
self.assertRaises(exc.BadRequest, clt._api_request, uri,
method, **kwargs)
id_svc.authenticate = sav