Beispiel #1
0
 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')
Beispiel #2
0
 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'})
Beispiel #3
0
 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']})
Beispiel #4
0
    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)
Beispiel #5
0
 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')
Beispiel #6
0
    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': '******'})
Beispiel #7
0
    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'))
Beispiel #8
0
 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')
Beispiel #9
0
 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')
Beispiel #10
0
 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')
Beispiel #11
0
 def test_returns_class(self):
     klass = api_resource(self.uri_path)(APIResourceMocks.Mock)
     self.assertEqual(klass, APIResourceMocks.Mock)
Beispiel #12
0
 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)
Beispiel #13
0
 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)
Beispiel #14
0
 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)
Beispiel #15
0
 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)
Beispiel #16
0
 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), {})
Beispiel #17
0
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)
Beispiel #18
0
 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'})