本文整理汇总了Python中pyrax.utils.add_method函数的典型用法代码示例。如果您正苦于以下问题:Python add_method函数的具体用法?Python add_method怎么用?Python add_method使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了add_method函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: 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
开发者ID:216software,项目名称:pyrax,代码行数:31,代码来源:test_identity.py
示例2: test_add_method_no_name
def test_add_method_no_name(self):
def fake_method(self):
pass
obj = fakes.FakeEntity()
utils.add_method(obj, fake_method)
self.assertTrue(hasattr(obj, "fake_method"))
self.assertTrue(callable(obj.fake_method))
开发者ID:naterh,项目名称:pyrax,代码行数:7,代码来源:test_utils.py
示例3: 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
开发者ID:annegentle,项目名称:pyrax,代码行数:30,代码来源:test_identity.py
示例4: test_authenticate
def test_authenticate(self):
savrequest = requests.api.request
requests.api.request = Mock(return_value=fakes.FakeIdentityResponse())
for cls in self.id_classes.values():
ident = cls()
if cls is self.keystone_identity_class:
# Necessary for testing to avoid NotImplementedError.
utils.add_method(ident, lambda self: "", "_get_auth_endpoint")
ident.authenticate()
requests.api.request = savrequest
开发者ID:216software,项目名称:pyrax,代码行数:10,代码来源:test_identity.py
示例5: test_call
def test_call(self):
ident = self.base_identity_class()
sav_post = requests.post
requests.post = Mock()
uri = utils.random_name()
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)
ident.method_post(uri, data=data, headers=headers, std_headers=std_headers)
requests.post.assert_called_with(uri, data=jdata, headers=expected_headers)
requests.post = sav_post
开发者ID:piecommerce,项目名称:pyrax,代码行数:17,代码来源:test_identity.py
示例6: test_has_valid_token
def test_has_valid_token(self):
savrequest = requests.api.request
requests.api.request = Mock(return_value=fakes.FakeIdentityResponse())
for cls in self.id_classes.values():
ident = cls()
if cls is self.keystone_identity_class:
# Necessary for testing to avoid NotImplementedError.
utils.add_method(ident, lambda self: "", "_get_auth_endpoint")
ident.authenticate()
valid = ident._has_valid_token()
self.assert_(valid)
ident.expires = datetime.datetime.now() - datetime.timedelta(1)
valid = ident._has_valid_token()
self.assertFalse(valid)
ident = self._get_clean_identity()
valid = ident._has_valid_token()
self.assertFalse(valid)
requests.api.request = savrequest
开发者ID:216software,项目名称:pyrax,代码行数:18,代码来源:test_identity.py
示例7: __init__
def __init__(self, *args, **kwargs):
super(FakeCSClient, self).__init__(*args, **kwargs)
def dummy(self): pass
self.servers = FakeService()
utils.add_method(self.servers, dummy, "list")
self.images = FakeService()
utils.add_method(self.images, dummy, "list")
self.flavors = FakeService()
utils.add_method(self.flavors, dummy, "list")
开发者ID:ejhammons,项目名称:pyrax,代码行数:9,代码来源:fakes.py
注:本文中的pyrax.utils.add_method函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论