本文整理汇总了Python中tests.watson.framework.support.sample_environ函数的典型用法代码示例。如果您正苦于以下问题:Python sample_environ函数的具体用法?Python sample_environ怎么用?Python sample_environ使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sample_environ函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_child_route_creation
def test_child_route_creation(self):
router = Router({
'home': {
'path': '/'
},
'parent': {
'path': '/parent',
'children': {
'child_one': {
'path': '/child_one',
'children': {
'sub_child': {
'path': '/test'
}
}
},
'child_two': {
'path': '/child_two'
}
}
}
})
assert len(router) == 5
request = create_request_from_environ(sample_environ(PATH_INFO='/child_one'))
matches = router.matches(request)
assert len(matches) == 0
request = create_request_from_environ(sample_environ(PATH_INFO='/parent/child_one'))
matches = router.matches(request)
assert len(matches) == 1
assert router.assemble('parent/child_one/sub_child') == '/parent/child_one/test'
示例2: test_static_match
def test_static_match(self):
route = Route(name='home', path='/')
invalid_request = create_request_from_environ(
sample_environ(PATH_INFO='/test'))
valid_request = create_request_from_environ(
sample_environ(PATH_INFO='/'))
assert not route.match(invalid_request)
assert route.match(valid_request)
示例3: test_accept_method_match
def test_accept_method_match(self):
valid_request = create_request_from_environ(
sample_environ(PATH_INFO='/test', REQUEST_METHOD='POST'))
invalid_request = create_request_from_environ(
sample_environ(PATH_INFO='/test', REQUEST_METHOD='GET'))
route = Route(name='test', path='/test', accepts=('POST',))
assert route.match(valid_request)
assert not route.match(invalid_request)
示例4: test_optional_segment_match
def test_optional_segment_match(self):
route = Route(name="search", path='/search[/:keyword]')
invalid_request = create_request_from_environ(
sample_environ(PATH_INFO='/searching'))
valid_request = create_request_from_environ(
sample_environ(PATH_INFO='/search'))
valid_request_with_param = create_request_from_environ(
sample_environ(PATH_INFO='/search/test'))
assert not route.match(invalid_request)
assert route.match(valid_request)
assert route.match(valid_request_with_param)
示例5: test_mandatory_segment_match
def test_mandatory_segment_match(self):
route = Route("search", path='/search/:keyword')
invalid_request = create_request_from_environ(
sample_environ(PATH_INFO='/searching'))
valid_request_no_param = create_request_from_environ(
sample_environ(PATH_INFO='/search'))
valid_request_with_param = create_request_from_environ(
sample_environ(PATH_INFO='/search/test'))
assert not route.match(invalid_request)
assert not route.match(valid_request_no_param)
assert route.match(valid_request_with_param)
示例6: test_optional_segment_with_required
def test_optional_segment_with_required(self):
route = Route(
name="search",
path='/search[/:keyword]',
requires={'keyword': 'blah'})
valid_request = create_request_from_environ(
sample_environ(PATH_INFO='/search/blah'))
invalid_request = create_request_from_environ(
sample_environ(PATH_INFO='/search/test'))
assert not route.match(invalid_request)
assert route.match(valid_request)
示例7: test_requires_get_variables
def test_requires_get_variables(self):
route = Route(name='test', path='/', requires={'test': '.*'})
request = create_request_from_environ(sample_environ(
PATH_INFO='/',
QUERY_STRING='test=blah&something=test'))
match = route.match(request)
assert match
request = create_request_from_environ(sample_environ(
PATH_INFO='/',
QUERY_STRING='tesst=blah'))
match = route.match(request)
assert not match
示例8: test_subdomain_match
def test_subdomain_match(self):
valid_request = create_request_from_environ(
sample_environ(PATH_INFO='/test',
SERVER_NAME='clients.test.com',
HTTP_HOST='clients.test.com'))
invalid_request = create_request_from_environ(
sample_environ(PATH_INFO='/test', SERVER_NAME='clients2.test.com',
HTTP_HOST='clients2.test.com'))
route = Route(name='test', path='/test', subdomain='clients')
assert route.match(valid_request)
assert not route.match(invalid_request)
route_multiple_subdomains = Route(name='test', path='/test', subdomain=('clients', 'test'))
assert route_multiple_subdomains.match(valid_request)
assert not route_multiple_subdomains.match(invalid_request)
示例9: test_format_match
def test_format_match(self):
valid_request = create_request_from_environ(
sample_environ(PATH_INFO='/dump',
HTTP_ACCEPT='application/json'))
invalid_request = create_request_from_environ(
sample_environ(PATH_INFO='/dump', HTTP_ACCEPT='application/xml'))
valid_request_segment = create_request_from_environ(
sample_environ(PATH_INFO='/dump.json'))
route = Route(name='json', path='/dump', requires={'format': 'json'})
route_format = Route(
name='json',
path='/dump.:format',
requires={'format': 'json'})
assert route.match(valid_request)
assert not route.match(invalid_request)
assert route_format.match(valid_request_segment)
示例10: test_call
def test_call(self):
application = applications.Http({
'routes': {
'home': {
'path': '/',
'options': {
'controller': 'tests.watson.framework.support.TestController'
},
'requires': {
'format': 'json'
}
}
},
'views': {
'templates': {
'watson/mvc/test_applications/testcontroller/post': 'blank'
}
},
'debug': {
'enabled': True
}
})
environ = sample_environ(PATH_INFO='/',
REQUEST_METHOD='POST',
HTTP_ACCEPT='application/json')
response = application(environ, start_response)
assert response == [b'{"content": "Posted Hello World!"}']
示例11: test_optional_segment_with_defaults
def test_optional_segment_with_defaults(self):
route = Route(
name="search",
path='/search[/:keyword]',
defaults={'keyword': 'blah'})
invalid_request = create_request_from_environ(
sample_environ(PATH_INFO='/searching'))
valid_request = create_request_from_environ(
sample_environ(PATH_INFO='/search'))
valid_request_with_param = create_request_from_environ(
sample_environ(PATH_INFO='/search/test'))
valid_request_with_default = route.match(valid_request)
assert not route.match(invalid_request)
assert valid_request_with_default
assert valid_request_with_default.params == {'keyword': 'blah'}
assert route.match(valid_request_with_param)
示例12: test_forward_no_method
def test_forward_no_method(self):
controller = SampleActionController()
controller.container = IocContainer()
request = Request.from_environ(sample_environ())
context = {'request': request}
controller.event = types.Event('test', params={'context': context})
controller.__action__ = 'do_method_forward'
assert controller.do_method_forward() == 'Another Response'
示例13: test_flash_message
def test_flash_message(self):
controller = SampleActionController()
controller.request = Request.from_environ(sample_environ(), "watson.http.sessions.Memory")
controller.flash_messages.add("testing")
controller.flash_messages.add("something")
assert controller.flash_messages["info"] == ["testing", "something"]
for namespace, message in controller.flash_messages:
assert namespace == "info"
assert not controller.flash_messages.messages
示例14: test_last_exception
def test_last_exception(self):
# occurs when exceptions have been raised from others
environ = sample_environ()
context = {
'request': Request.from_environ(environ)
}
app = applications.Http()
response, view_model = app.exception(
last_exception=True, exception=Exception('test'), context=context)
assert '<h1>Internal Server Error</h1>' in response.body
示例15: test_short_circuit
def test_short_circuit(self):
environ = sample_environ()
route = LiteralRoute(
"test", path="/", options={"controller": "tests.watson.framework.support.ShortCircuitedController"}
)
match = RouteMatch(route, {})
context = {"request": Request.from_environ(environ), "route_match": match}
event = Event("something", params={"container": IocContainer(), "context": context})
listener = listeners.DispatchExecute({"404": "page/404"})
response, view_model = listener(event)
assert isinstance(response, Response)