Ejemplo n.º 1
0
    def test_post_exception(self):
        mock_requests = patch('globomap_api_client.base.Session').start()

        mock_requests.return_value.request.return_value = MagicMock(
            side_effect=Exception())

        with self.assertRaises(exceptions.ApiError):
            base = Base(Mock())
            data = {'key': 'value'}
            base.make_request('POST', 'path', None, data)
Ejemplo n.º 2
0
    def test_post_403(self):
        mock_requests = patch('globomap_api_client.base.Session').start()
        response_mock = MagicMock(return_value={'message': 'Error'})

        mock_requests.return_value.request.return_value = MagicMock(
            json=response_mock, status_code=403)

        with self.assertRaises(exceptions.Forbidden):
            base = Base(Mock())
            data = {'key': 'value'}
            base.make_request('POST', 'path', None, data)
Ejemplo n.º 3
0
    def test_get_404(self):
        mock_requests = patch('globomap_api_client.base.Session').start()
        response_mock = MagicMock(return_value={'message': 'Error'})

        mock_requests.return_value.request.return_value = MagicMock(
            json=response_mock, status_code=404)

        with self.assertRaises(exceptions.NotFound):
            base = Base(Mock())
            params = {'key': 'value'}
            base.make_request('GET', 'path', params, None)
Ejemplo n.º 4
0
    def test_get_error(self):
        mock_requests = patch('globomap_api_client.base.Session').start()
        response_mock = MagicMock(return_value={'message': 'Error'})

        mock_requests.return_value.request.return_value = MagicMock(
            json=response_mock, status_code=500)

        with self.assertRaises(exceptions.ApiError):
            base = Base(Mock())
            query = {'key': 'value'}
            base.make_request('GET', 'path', query, None, 6)
Ejemplo n.º 5
0
    def test_get_200(self):
        mock_session = patch('globomap_api_client.base.Session').start()

        response_mock = MagicMock(return_value={'message': 'message'})
        request_mock = mock_session.return_value.request
        request_mock.return_value = MagicMock(json=response_mock,
                                              status_code=200)

        params = {'key': 'value'}

        base = Base(Mock(api_url='http://localhost', token='token123'))
        base.make_request('GET', 'path', params, None)

        headers = {'Authorization': 'Token token=token123'}
        request_mock.assert_called_once_with('GET',
                                             'http://localhost/v2/path/',
                                             params=params,
                                             headers=headers)
Ejemplo n.º 6
0
    def test_post_200(self):
        mock_session = patch('globomap_api_client.base.Session').start()

        response_mock = MagicMock(return_value={'message': 'message'})
        request_mock = mock_session.return_value.request
        request_mock.return_value = MagicMock(
            json=response_mock, status_code=200)

        data = {'key': 'value'}

        base = Base(Mock(api_url='http://localhost', token='token123'))
        base.make_request('POST', 'path', None, data, 1)

        headers = {
            'Content-Type': 'application/json',
            'Authorization': 'Token token=token123'
        }
        request_mock.assert_called_once_with(
            'POST', 'http://localhost/v2/path/', data=json.dumps(data), headers=headers, verify=1
        )