def test_authentication_middleware_adds_authorization_header_to_response_authorized_with_cookie( self): environ[ 'MONGOREST_SETTINGS_MODULE'] = 'tests.fixtures.middlewares_test_auth_settings' class TestResource(ListResourceMixin): def list(self, request): request.environ['session']['test'] = 'test' request.environ['collection'] = 'collection' return Response() self.test_client = self.client( WSGIDispatcher(resources=[TestResource]), Response) session_store = locate(settings.SESSION_STORE)() session = session_store.new() session_store.save(session) response = self.test_client.get( '/', headers=[('Cookie', 'session_id={0}'.format(session.sid))]) self.assertIn('HTTP_AUTHORIZATION', response.headers) self.assertEqual(response.headers.get('HTTP_AUTHORIZATION'), 'Token {0}'.format(session.sid)) environ.pop('MONGOREST_SETTINGS_MODULE')
def setUp(self): class Test(Collection): schema = {'test': {'required': True, 'type': 'integer'}} class TestCollectionUpdate(UpdateResourceMixin): collection = Test self.update_client = self.client( WSGIDispatcher(resources=[TestCollectionUpdate]), Response)
def test_wsgi_wrapper_executes_correct_view_if_url_exists_on_map(self): class WSGIWrapperTest(WSGIWrapper): url_map = Map([Rule('/', methods=['GET'], endpoint='test')]) def test(self, request): return Response(status=999) app = WSGIDispatcher(resources=[WSGIWrapperTest]) response = self.client(app, Response).get('/') self.assertEqual(response.status_code, 999)
def test_wsgi_dispatcher_init_returns_werkzeug_app_with_mounted_resources( self): class TestWSGIWrapper(WSGIWrapper): endpoint = 'test' url_map = Map([Rule('/', methods=['GET'], endpoint='test')]) def test(self, request): return Response(status=999) app = WSGIDispatcher(resources=[TestWSGIWrapper]) self.assertEqual(list(app.mounts.keys()), ['/test'])
def test_authentication_middleware_raises_value_error_if_auth_collection_is_not_sub_class_of_collection( self): environ[ 'MONGOREST_SETTINGS_MODULE'] = 'tests.fixtures.middlewares_test_auth_colelction_error_settings' self.test_client = self.client( WSGIDispatcher(resources=[ListResourceMixin]), Response) with self.assertRaises(ValueError): self.test_client.get('/') environ.pop('MONGOREST_SETTINGS_MODULE')
def test_wsgi_wrapper_returns_not_found_if_no_url_is_found_without_trailing_slash( self): class WSGIWrapperTest(WSGIWrapper): url_map = Map([Rule('/', methods=['GET'], endpoint='test')]) def test(self, request): return Response(status=999) app = WSGIDispatcher(resources=[WSGIWrapperTest]) response = self.client(app, Response).get('/test') self.assertEqual(response.status_code, 404)
def test_wsgi_wrapper_redirects_to_correct_url_if_30x_status_and_follow_redirects( self): class WSGIWrapperTest(WSGIWrapper): url_map = Map([Rule('/test/', methods=['GET'], endpoint='test')]) def test(self, request): return Response(status=999) app = WSGIDispatcher(resources=[WSGIWrapperTest]) response = self.client(app, Response).get('/test', follow_redirects=True) self.assertEqual(response.status_code, 999)
def test_authentication_middleware_does_not_set_token_or_cookie_or_header_if_not_authorized( self): environ[ 'MONGOREST_SETTINGS_MODULE'] = 'tests.fixtures.middlewares_test_auth_settings' self.test_client = self.client( WSGIDispatcher(resources=[ListResourceMixin]), Response) response = self.test_client.get('/') self.assertNotIn('HTTP_AUTHORIZATION', response.headers) self.assertNotIn('Set-Cookie', response.headers) environ.pop('MONGOREST_SETTINGS_MODULE')
def test_wsgi_dispatcher_adds_middlewares_to_mounts(self): environ[ 'MONGOREST_SETTINGS_MODULE'] = 'tests.fixtures.wsgi_test_settings' class TestWSGIWrapper(WSGIWrapper): endpoint = 'test' url_map = Map([Rule('/', methods=['GET'], endpoint='test')]) def test(self, request): return Response(status=999) app = WSGIDispatcher(resources=[TestWSGIWrapper]) self.assertIsInstance(app.mounts['/test'], CORSMiddleware) environ.pop('MONGOREST_SETTINGS_MODULE')
def setUp(self): environ[ 'MONGOREST_SETTINGS_MODULE'] = 'tests.fixtures.middlewares_test_cors_settings' self.test_client = self.client( WSGIDispatcher(resources=[ListResourceMixin]), Response)
def setUp(self): self.retrieve_client = self.client( WSGIDispatcher(resources=[RetrieveResourceMixin]), Response)
def setUp(self): self.delete_client = self.client( WSGIDispatcher(resources=[DeleteResourceMixin]), Response )
def setUp(self): self.documents_client = self.client( WSGIDispatcher(resources=[ListResourceMixin]), Response )