Beispiel #1
0
 def test_post_redirect_get(self):
     base = controllers.HttpMixin()
     router = Router({'test': {'path': '/test'}})
     environ = sample_environ(PATH_INFO='/', REQUEST_METHOD='POST')
     environ['wsgi.input'] = BufferedReader(BytesIO(b'post_var_one=test&post_var_two=blah'))
     base.request = create_request_from_environ(environ, 'watson.http.sessions.Memory')
     base.container = Mock()
     base.container.get.return_value = router
     response = base.redirect('test')
     assert response.status_code == 303
     assert base.redirect_vars == base.request.session['post_redirect_get']
     base.clear_redirect_vars()
     assert not base.redirect_vars
     base.redirect('test', clear=True)
     assert not base.redirect_vars
Beispiel #2
0
 def test_route_to_url(self):
     base = controllers.HttpMixin()
     router = Router({
         'test': {
             'path': '/test',
         },
         'segment': {
             'path': '/segment[/:part]',
             'type': 'segment'
         }
     })
     base.container = Mock()
     base.container.get.return_value = router
     assert base.url('test') == '/test'
     assert base.url('segment', part='test') == '/segment/test'
Beispiel #3
0
 def test_redirect(self):
     base = controllers.HttpMixin()
     router = Router({
         'test': {
             'path': '/test',
         },
         'segment': {
             'path': '/segment[/:part]',
             'type': 'segment',
             'defaults': {'part': 'test'}
         }
     })
     base.request = create_request_from_environ(sample_environ())
     base.container = Mock()
     base.container.get.return_value = router
     response = base.redirect('/test')
     assert response.headers['location'] == '/test'
     response = base.redirect('segment')
     assert response.headers['location'] == '/segment/test'
     assert response.status_code == 302
Beispiel #4
0
 def test_invalid_response(self):
     base = controllers.HttpMixin()
     base.response = 'test'
Beispiel #5
0
 def test_invalid_request(self):
     base = controllers.HttpMixin()
     base.request = 'test'
Beispiel #6
0
 def test_set_event(self):
     base = controllers.HttpMixin()
     base.event = 'test'
Beispiel #7
0
 def test_get_event(self):
     base = controllers.HttpMixin()
     base.event = types.Event('test')
     assert isinstance(base.event, types.Event)
Beispiel #8
0
 def test_request_response(self):
     base = controllers.HttpMixin()
     base.request = Request('GET')
     assert isinstance(base.request, Request)
     assert isinstance(base.response, Response)