def test_get_and_post_returns_index_and_post(self):
     klass = api_resource(self.uri_path)(APIResourceMocks.MockWithIndexAndPost)
     with self._test_client() as client:
         post_response = client.post(self.uri_path)
         get_response = client.get(self.uri_path)
         self.assertEqual(self._json_response(post_response), 'some post data')
         self.assertEqual(self._json_response(get_response), 'some index data')
    def test_post_has_cookie(self):
        def _callback(mock_instance):
            return mock_instance.params

        mock_klass = self._mock_resource('post', _callback, cookie=self.random_cookie, )
        klass = api_resource(self.uri_path)(mock_klass)
        with self._test_client() as client:
            response = client.post(self.uri_path, data={'password': '******'})
            self.assertEqual(self.cookie_string + ';path=/', response.headers.get('Set-Cookie'))
    def test_post_sets_params_different_params(self):
        def _callback(mock_instance):
            return mock_instance.params

        mock_klass = self._mock_resource('post', _callback)

        klass = api_resource(self.uri_path)(mock_klass)
        with self._test_client() as client:
            response = client.post(self.uri_path, data={'password': '******', 'cat': 'dog'})
            self.assertEqual(self._json_response(response), {'password': '******', 'cat': 'dog'})
    def test_delete_sets_params(self):
        def _callback(mock_instance):
            return mock_instance.params

        mock_klass = self._mock_resource('delete', _callback)

        klass = api_resource(self.uri_path)(mock_klass)
        with self._test_client() as client:
            response = client.delete(self.uri_path, data=self.random_data)
            self.assertEqual(self._json_response(response), self.random_data)
    def test_put_has_status_code_and_params(self):
        fake_status_code = self.faker.pyint()
        fake_put_data = self.faker.pydict(3, False, 'int', 'str', 'float')

        APIResourceMocks.ParamsMockWithPutAndStatus.status_code = fake_status_code
        klass = api_resource(self.uri_path)(APIResourceMocks.ParamsMockWithPutAndStatus)
        with self._test_client() as client:
            response = client.put(self.uri_path, json=fake_put_data)
            self.assertEqual(response.status_code, fake_status_code)
            self.assertEqual(response.json, fake_put_data)
 def test_post_returns_post(self):
     klass = api_resource(self.uri_path)(APIResourceMocks.MockWithPost)
     with self._test_client() as client:
         response = client.post(self.uri_path)
         self.assertEqual(self._json_response(response), 'some data')
 def test_returns_class(self):
     klass = api_resource(self.uri_path)(APIResourceMocks.Mock)
     self.assertEqual(klass, APIResourceMocks.Mock)
 def test_put_request_returns_return_value_of_resource_put_method(self):
     klass = api_resource(self.uri_path)(APIResourceMocks.MockWithPut)
     with self._test_client() as client:
         response = client.put(self.uri_path, json={})
         self.assertEqual(response.json, 'some put data')
 def test_get_returns_empty_params(self):
     klass = api_resource(self.uri_path)(APIResourceMocks.ParamsMockWithIndex)
     with self._test_client() as client:
         response = client.get(self.uri_path)
         self.assertEqual(self._json_response(response), {})
 def test_get_returns_path_with_query_params(self):
     klass = api_resource(self.uri_path)(APIResourceMocks.ParamsMockWithIndex)
     with self._test_client() as client:
         response = client.get(self.uri_path + '?hello=world')
         self.assertEqual(self._json_response(response), {'hello': 'world'})
 def test_get_returns_path_param(self):
     klass = api_resource('/path/to/resource/with/<string:project_name>/params')(APIResourceMocks.ParamsMockWithIndex)
     with self._test_client() as client:
         response = client.get('/path/to/resource/with/value/params')
         self.assertEqual(self._json_response(response), {'project_name': 'value'})
 def test_post_has_status_code_different_code(self):
     klass = api_resource(self.uri_path)(APIResourceMocks.ParamsMockWithPostAndStatus)
     with self._test_client() as client:
         response = client.post(self.uri_path)
         self.assertEqual(response.status_code, 403)
 def test_post_has_status_code(self):
     klass = api_resource(self.uri_path)(APIResourceMocks.MockWithIndexAndPost)
     with self._test_client() as client:
         response = client.post(self.uri_path)
         self.assertEqual(response.status_code, 200)
 def test_delete_has_status_code_different_code(self):
     klass = api_resource(self.uri_path)(APIResourceMocks.MockWithDeleteAndStatus)
     with self._test_client() as client:
         response = client.delete(self.uri_path)
         self.assertEqual(response.status_code, 403)
 def test_get_has_status_code(self):
     klass = api_resource(self.uri_path)(APIResourceMocks.ParamsMockWithIndex)
     with self._test_client() as client:
         response = client.get(self.uri_path)
         self.assertEqual(response.status_code, 200)
 def test_get_returns_index_different_data(self):
     klass = api_resource(self.uri_path)(APIResourceMocks.DifferentMockWithIndex)
     with self._test_client() as client:
         response = client.get(self.uri_path)
         self.assertEqual(self._json_response(response), 'some different data')
示例#17
0
from foundations_core_rest_api_components.v1.controllers.projects_controller import ProjectsController
from foundations_core_rest_api_components.utils.api_resource import api_resource

ProjectsController = api_resource('/api/v2beta/projects')(ProjectsController)
 def test_get_returns_path_with_query_list_params(self):
     klass = api_resource('/path/to/resource/with/query_list/params')(APIResourceMocks.ParamsMockWithIndex)
     with self._test_client() as client:
         response = client.get('/path/to/resource/with/query_list/params?hello=world&hello=lou')
         self.assertEqual(self._json_response(response), {'hello': ['world', 'lou']})