def test_client_call_api_client_exceptions(self) -> None: client = Client("Test") response_mock = mock.Mock() response_mock.status_code = mock.Mock(return_value=500) response_mock.content = bytes('{"msg": "exception"}', 'utf-8') response_mock.raise_for_status = mock.Mock( side_effect=RequestException) client._requests = mock.Mock() client._requests.request = mock.Mock(return_value=response_mock) self.assertRaises(RequestException, client.call, "", "", {})
def test_client_call_api_success(self) -> None: client = Client("Test") response_mock = mock.Mock() response_mock.status_code = mock.Mock(return_value=200) response_mock.json = mock.Mock(return_value={"test": "test"}) client._requests = mock.Mock() client._requests.request = mock.Mock(return_value=response_mock) result = client.call("", "", {}) self.assertTrue(isinstance(result, dict)) self.assertTrue(bool(result)) self.assertEqual("test", result["test"])
def test_client_call_using_right_format(self) -> None: client = Client("Test") client._requests = mock.Mock() header = { 'Authorization': 'Bearer Test', 'User-Agent': 'py-ebrest 0.2.1', 'Content-type': 'application/json' } with mock.patch.object(Client, 'call', wraps=client.call) as clientMock: client.documents().update_document("1", {"is_archive": True}) clientMock.assert_called_once_with('PUT', '/rest/v1/documents/1', header, {"is_archive": True}) with mock.patch.object(Client, 'call', wraps=client.call) as clientMock: client.documents().create_document({"is_archive": True}) clientMock.assert_called_once_with('POST', '/rest/v1/documents', header, {"is_archive": True}) with mock.patch.object(Client, 'call', wraps=client.call) as clientMock: client.documents().get_document("2") clientMock.assert_called_once_with( 'GET', '/rest/v1/documents/2', header, ) with mock.patch.object(Client, 'call', wraps=client.call) as clientMock: client.documents().get_documents({"page": 2}) clientMock.assert_called_once_with( 'GET', '/rest/v1/documents?page=2', header, )