def test_must_raise_http_405_using_controller_without_get_method(self): self.config_module.urls.url_patterns = ( ( url( '/exp1', 'tests.mocks.controllers.GetControllerMock', 'exp1' ), url( '/exp2', 'tests.mocks.controllers.PutControllerMock', 'exp2' ), ) ) handler = Handler() request = HttpRequestMock() request.method = 'GET' request.path_info = '/exp2' with self.assertRaises(http.Http405, msg="Must be raise a InvalidConfigModuleException"): handler.dispatch(request)
def test_middleware_level0_must_add_mw_field_to_request_and_response(self): GetControllerMock.get = lambda self, *args, **kwargs: \ http.Http200() self.config_module.urls.url_patterns = ( ( url('/exp1', GetControllerMock, 'exp1'), ) ) CompleteMiddlewareLevel0Mock.process_request = lambda self, request: \ setattr(request, 'mw', True) CompleteMiddlewareLevel0Mock.process_response = \ lambda self, request, response: \ setattr(response, 'mw', True) self.config_module.middleware_level0.append( CompleteMiddlewareLevel0Mock ) handler = Handler() request = HttpRequestMock() request.method = 'GET' request.path_info = '/exp1' request.accept['text/html'] = 1.0 response = handler.dispatch(request) self.assertTrue( getattr(request, 'mw', False) and getattr(response, 'mw', False), "Middleware level0 does not add 'mw' field to request and response" )
def test_must_raise_http_404_without_url_patterns(self): handler = Handler() request = HttpRequestMock() request.method = 'GET' with self.assertRaises(http.Http404, msg="Must be raise a Http404"): handler.dispatch(request)
def test_must_not_launch_exception_with_200_response(self): GetControllerMock.get = lambda self, *args, **kwargs: \ http.Http200() self.config_module.urls.url_patterns = ( ( url('/exp1', GetControllerMock, 'exp1'), ) ) handler = Handler() request = HttpRequestMock() request.method = 'GET' request.path_info = '/exp1' request.accept['text/html'] = 1.0 response = handler.dispatch(request)
def test_must_not_launch_exception_with_context_data_response(self): GetControllerMock.get = lambda self, *args, **kwargs: \ { 'title': 'Just now' } self.config_module.urls.url_patterns = ( ( url('/exp1', GetControllerMock, 'exp1'), ) ) handler = Handler() request = HttpRequestMock() request.method = 'GET' request.path_info = '/exp1' request.accept['text/html'] = 1.0 with self.assertRaises(http.Http415, msg="Must be raise a Http415"): handler.dispatch(request)
def test_must_render_a_response(self): self.config_module.templates['directory'] = \ os.path.join(os.getcwd(), 'tests/data/templates/') GetControllerMock.get = lambda self, *args, **kwargs: \ { 'title': 'Just now' } self.config_module.urls.url_patterns = ( ( url('/home', GetControllerMock, 'home'), ) ) handler = Handler() request = HttpRequestMock() request.method = 'GET' request.path_info = '/home' request.accept['text/html'] = 1.0 response = handler.dispatch(request) self.assertTrue(response.status_code, 200)