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')
def test_post_returns_path_param(self): klass = api_resource( '/path/to/resource/with/<string:project_name>/params')( APIResourceMocks.ParamsMockWithPost) with self._test_client() as client: response = client.post('/path/to/resource/with/value/params') self.assertEqual(self._json_response(response), {'project_name': 'value'})
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']})
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_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_sets_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': '******'}) self.assertEqual(self._json_response(response), {'password': '******'})
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_put_returns_update(self): klass = api_resource(self.uri_path)(APIResourceMocks.MockWithUpdate) with self._test_client() as client: response = client.put(self.uri_path) self.assertEqual(self._json_response(response), 'some updated 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_get_returns_show(self): klass = api_resource(self.uri_path)(APIResourceMocks.MockWithShow) with self._test_client() as client: response = client.get(self.uri_path) self.assertEqual(self._json_response(response), 'some specific data')
def test_returns_class(self): klass = api_resource(self.uri_path)(APIResourceMocks.Mock) self.assertEqual(klass, APIResourceMocks.Mock)
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_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), {})
from foundations_rest_api.utils.api_resource import api_resource from foundations_core_rest_api_components.v1.controllers.job_controller import JobController JobController = api_resource( '/api/v2beta/projects/<string:project_name>/job_listing/<string:job_id>')( JobController)
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'})