本文整理汇总了Python中stackinabox.stack.StackInABox类的典型用法代码示例。如果您正苦于以下问题:Python StackInABox类的具体用法?Python StackInABox怎么用?Python StackInABox使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了StackInABox类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_double_service_registration
def test_double_service_registration(self):
service1 = HelloService()
service2 = HelloService()
StackInABox.register_service(service1)
with self.assertRaises(ServiceAlreadyRegisteredError):
StackInABox.register_service(service2)
开发者ID:kidster,项目名称:stackInABox,代码行数:7,代码来源:test_stack.py
示例2: registration
def registration(uri):
"""Responses handler registration.
Registers a handler for a given URI with Responses
so that it can be intercepted and handed to
Stack-In-A-Box.
:param uri: URI used for the base of the HTTP requests
:returns: n/a
"""
# log the URI that is used to access the Stack-In-A-Box services
logger.debug('Registering Stack-In-A-Box at {0} under Python Responses'
.format(uri))
# tell Stack-In-A-Box what URI to match with
StackInABox.update_uri(uri)
# Build the regex for the URI and register all HTTP verbs
# with Responses
regex = re.compile('(http)?s?(://)?{0}:?(\d+)?/'.format(uri),
re.I)
METHODS = [
responses.DELETE,
responses.GET,
responses.HEAD,
responses.OPTIONS,
responses.PATCH,
responses.POST,
responses.PUT
]
for method in METHODS:
responses.add_callback(method,
regex,
callback=responses_callback)
开发者ID:BenjamenMeyer,项目名称:stackInABox,代码行数:35,代码来源:core.py
示例3: setUp
def setUp(self):
super(TestKeystoneV2UserGet, self).setUp()
self.keystone = KeystoneV2Service()
self.headers = {
'x-auth-token': self.keystone.model.tokens.admin_token
}
StackInABox.register_service(self.keystone)
开发者ID:BenjamenMeyer,项目名称:openstackinabox,代码行数:7,代码来源:test_get.py
示例4: setUp
def setUp(self):
super(TestKeystoneV2UserAddCredentials, self).setUp()
self.keystone = KeystoneV2Service()
self.headers = {
'x-auth-token': self.keystone.model.tokens.admin_token
}
self.tenant_id = self.keystone.model.tenants.add(
tenant_name='neo',
description='The One'
)
self.user_info = {
'user': {
'username': 'trinity',
'enabled': True,
'email': '[email protected]',
'password': 'Inl0veWithNeo'
}
}
self.user_info['user']['userid'] = self.keystone.model.users.add(
tenant_id=self.tenant_id,
username=self.user_info['user']['username'],
email=self.user_info['user']['email'],
password=self.user_info['user']['password'],
enabled=self.user_info['user']['enabled']
)
self.keystone.model.tokens.add(
tenant_id=self.tenant_id,
user_id=self.user_info['user']['userid']
)
self.keystone.model.roles.add_user_role_by_role_name(
tenant_id=self.tenant_id,
user_id=self.user_info['user']['userid'],
role_name=self.keystone.model.roles.IDENTITY_ADMIN_ROLE
)
StackInABox.register_service(self.keystone)
开发者ID:BenjamenMeyer,项目名称:openstackinabox,代码行数:35,代码来源:test_add_credentials.py
示例5: setUp
def setUp(self):
super(TestKeystoneV2UserListing, self).setUp()
self.keystone = KeystoneV2Service()
self.headers = {
'x-auth-token': self.keystone.model.get_admin_token()
}
StackInABox.register_service(self.keystone)
开发者ID:ananthanithya,项目名称:openstackinabox,代码行数:7,代码来源:test_keystone_v2_user_listing.py
示例6: setUp
def setUp(self):
super(TestKeystoneV2UserUpdate, self).setUp()
self.keystone = KeystoneV2Service()
self.headers = {
'x-auth-token': self.keystone.model.tokens.admin_token
}
self.tenant_id = self.keystone.model.tenants.add(
tenant_name='neo',
description='The One'
)
self.user_info = {
'user': {
'username': 'trinity',
'enabled': True,
'email': '[email protected]',
'OS-KSADM:password': 'Inl0veWithNeo'
}
}
self.user_info['user']['userid'] = self.keystone.model.users.add(
tenant_id=self.tenant_id,
username=self.user_info['user']['username'],
email=self.user_info['user']['email'],
password=self.user_info['user']['OS-KSADM:password'],
enabled=self.user_info['user']['enabled']
)
self.keystone.model.tokens.add(
tenant_id=self.tenant_id,
user_id=self.user_info['user']['userid']
)
StackInABox.register_service(self.keystone)
开发者ID:BenjamenMeyer,项目名称:openstackinabox,代码行数:30,代码来源:test_update.py
示例7: setUp
def setUp(self):
super(TestHttprettyKeystone, self).setUp()
self.keystone = KeystoneV2Service()
self.headers = {
'x-auth-token': self.keystone.model.tokens.admin_token
}
StackInABox.register_service(self.keystone)
self.session = requests.Session()
开发者ID:BenjamenMeyer,项目名称:openstackinabox,代码行数:8,代码来源:test_keystone.py
示例8: test_service_exception
def test_service_exception(self):
exceptional = ExceptionalServices()
StackInABox.register_service(exceptional)
stackinabox.util_httpretty.httpretty_registration('localhost')
res = requests.get('http://localhost/except/')
self.assertEqual(res.status_code, 596)
开发者ID:kidster,项目名称:stackInABox,代码行数:8,代码来源:test_stack.py
示例9: run
def run():
StackInABox.reset_services()
StackInABox.register_service(HelloService())
stackinabox.util.responses.registration('localhost')
res = requests.get('http://localhost/hello/')
assert res.status_code == 200
assert res.text == 'Hello'
开发者ID:BenjamenMeyer,项目名称:stackInABox,代码行数:8,代码来源:test_core.py
示例10: test_subservice_registration
def test_subservice_registration(self):
service = AnotherAdvancedService()
subservice = YetAnotherService()
service.register_subservice(re.compile('^/french'),
subservice)
StackInABox.register_service(service)
stackinabox.util_httpretty.httpretty_registration('localhost')
res = requests.get('http://localhost/aas/french')
self.assertEqual(res.status_code,
200)
self.assertEqual(res.text,
'bonjour')
开发者ID:kidster,项目名称:stackInABox,代码行数:15,代码来源:test_service.py
示例11: setUp
def setUp(self):
super(TestKeystoneV2UserAdd, self).setUp()
self.keystone = KeystoneV2Service()
self.headers = {
'x-auth-token': self.keystone.model.get_admin_token()
}
self.user_info = {
'user': {
'username': 'trinity',
'enabled': True,
'email': '[email protected]',
'OS-KSADM:password': 'Inl0veWithNeo'
}
}
StackInABox.register_service(self.keystone)
开发者ID:ananthanithya,项目名称:openstackinabox,代码行数:15,代码来源:test_keystone_v2_user_add.py
示例12: httpretty_callback
def httpretty_callback(request, uri, headers):
"""httpretty request handler.
converts a call intercepted by httpretty to
the stack-in-a-box infrastructure
:param request: request object
:param uri: the uri of the request
:param headers: headers for the response
:returns: tuple - (int, dict, string) containing:
int - the http response status code
dict - the headers for the http response
string - http string response
"""
method = request.method
response_headers = CaseInsensitiveDict()
response_headers.update(headers)
request_headers = CaseInsensitiveDict()
request_headers.update(request.headers)
request.headers = request_headers
return StackInABox.call_into(method,
request,
uri,
response_headers)
开发者ID:BenjamenMeyer,项目名称:stackInABox,代码行数:26,代码来源:core.py
示例13: httpretty_registration
def httpretty_registration(uri):
status_data = {
595: 'StackInABoxService - Unknown Route',
596: 'StackInABox - Exception in Service Handler',
597: 'StackInABox - Unknown Service'
}
for k, v in six.iteritems(status_data):
if k not in httpretty.http.STATUSES:
httpretty.http.STATUSES[k] = v
logger.debug('Registering Stack-In-A-Box at {0} under Python HTTPretty'
.format(uri))
StackInABox.update_uri(uri)
regex = re.compile('(http)?s?(://)?{0}:?(\d+)?/'.format(uri),
re.I)
for method in HttpBaseClass.METHODS:
register_uri(method, regex, body=httpretty_callback)
开发者ID:kidster,项目名称:stackInABox,代码行数:18,代码来源:util_httpretty.py
示例14: requests_mock_session_registration
def requests_mock_session_registration(uri, session):
logger.debug('Registering Stack-In-A-Box at {0} under Python Requests-Mock'
.format(uri))
logger.debug('Session has id {0}'.format(id(session)))
StackInABox.update_uri(uri)
StackInABox.hold_onto('adapter', requests_mock.Adapter())
StackInABox.hold_out('adapter').add_matcher(RequestMockCallable(uri))
session.mount('http://{0}'.format(uri), StackInABox.hold_out('adapter'))
session.mount('https://{0}'.format(uri), StackInABox.hold_out('adapter'))
开发者ID:kidster,项目名称:stackInABox,代码行数:11,代码来源:util_requests_mock.py
示例15: handle
def handle(self, request, uri):
"""Request handler interface.
:param request: Python requests Request object
:param uri: URI of the request
"""
# Convert the call over to Stack-In-A-Box
method = request.method
headers = CaseInsensitiveDict()
request_headers = CaseInsensitiveDict()
request_headers.update(request.headers)
request.headers = request_headers
stackinabox_result = StackInABox.call_into(method,
request,
uri,
headers)
# reformat the result for easier use
status_code, output_headers, body = stackinabox_result
json_data = None
text_data = None
content_data = None
body_data = None
# if the body is a string-type...
if isinstance(body, six.string_types):
# Try to convert it to JSON
text_data = body
try:
json_data = json.dumps(text_data)
text_data = json_data
except Exception:
json_data = None
text_data = body
# if the body is binary, then it's the content
elif isinstance(body, six.binary_type):
content_data = body
# by default, it's just body data
else:
# default to body data
body_data = body
# build the Python requests' Response object
return requests_mock.response.create_response(
request,
headers=output_headers,
status_code=status_code,
body=body_data,
json=json_data,
text=text_data,
content=content_data
)
开发者ID:BenjamenMeyer,项目名称:stackInABox,代码行数:56,代码来源:core.py
示例16: responses_registration
def responses_registration(uri):
logger.debug('Registering Stack-In-A-Box at {0} under Python Responses'
.format(uri))
StackInABox.update_uri(uri)
regex = re.compile('(http)?s?(://)?{0}:?(\d+)?/'.format(uri),
re.I)
METHODS = [
responses.DELETE,
responses.GET,
responses.HEAD,
responses.OPTIONS,
responses.PATCH,
responses.POST,
responses.PUT
]
for method in METHODS:
responses.add_callback(method,
regex,
callback=responses_callback)
开发者ID:kidster,项目名称:stackInABox,代码行数:19,代码来源:util_responses.py
示例17: httpretty_callback
def httpretty_callback(request, uri, headers):
method = request.method
response_headers = CaseInsensitiveDict()
response_headers.update(headers)
request_headers = CaseInsensitiveDict()
request_headers.update(request.headers)
request.headers = request_headers
return StackInABox.call_into(method,
request,
uri,
response_headers)
开发者ID:kidster,项目名称:stackInABox,代码行数:11,代码来源:util_httpretty.py
示例18: responses_callback
def responses_callback(request):
method = request.method
headers = CaseInsensitiveDict()
request_headers = CaseInsensitiveDict()
request_headers.update(request.headers)
request.headers = request_headers
uri = request.url
return StackInABox.call_into(method,
request,
uri,
headers)
开发者ID:kidster,项目名称:stackInABox,代码行数:11,代码来源:util_responses.py
示例19: setUp
def setUp(self):
super(TestKeystoneV2AuthBase, self).setUp()
self.tenantname = self.make_tenant_name()
self.keystone = KeystoneV2Service()
self.username = 'user_{0}'.format(str(uuid.uuid4()))
self.password = 'pAss{0}'.format(
str(uuid.uuid4()).replace('-', '')
)
self.apikey = str(uuid.uuid4())
self.email = '{0}@stackinabox.mock'.format(self.username)
self.keystone.model.tenants.add(
tenant_name=self.tenantname,
description="test tenant"
)
tenant_data = self.keystone.model.tenants.get_by_name(
tenant_name=self.tenantname
)
self.tenantid = tenant_data['id']
self.keystone.model.users.add(
tenant_id=self.tenantid,
username=self.username,
password=self.password,
apikey=self.apikey,
email=self.email
)
user_data = self.keystone.model.users.get_by_name(
tenant_id=self.tenantid,
username=self.username
)
self.userid = user_data['user_id']
self.token = self.keystone.model.tokens.make_token()
self.keystone.model.tokens.add(
tenant_id=self.tenantid,
user_id=self.userid,
token=self.token
)
StackInABox.register_service(self.keystone)
开发者ID:BenjamenMeyer,项目名称:openstackinabox,代码行数:40,代码来源:base.py
示例20: wrapped
def wrapped(*args, **kwargs):
args_copy = list(args)
for arg in self.args:
args_copy.append(arg)
args_finalized = tuple(args_copy)
kwargs.update(self.kwargs)
if self.enable_service_access is not None:
kwargs[self.enable_service_access] = self.services
httpretty.reset()
httpretty.enable()
for service in self.services.values():
StackInABox.register_service(service)
httpretty_registration(self.uri)
return_value = fn(*args_finalized, **kwargs)
StackInABox.reset_services()
httpretty.disable()
httpretty.reset()
return return_value
开发者ID:BenjamenMeyer,项目名称:stackInABox,代码行数:23,代码来源:decorator.py
注:本文中的stackinabox.stack.StackInABox类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论