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_get_projects_resource(self) -> None: self.assertTrue(isinstance(Client('').projects(), ResourceProjects))
def test_get_endpoint(self) -> None: self.assertEqual("/tasks", Client('').tasks().get_resource_endpoint())
def test_get_endpoint(self) -> None: self.assertEqual("/attachments", Client('').attachments().get_resource_endpoint())
def test_get_endpoint(self) -> None: self.assertEqual( "/customer-groups", Client('').customer_groups().get_resource_endpoint())
def test_get_endpoint(self) -> None: self.assertEqual("/logins", Client('').logins().get_resource_endpoint())
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, )
def test_get_text_templates(self) -> None: self.assertTrue( isinstance(Client('').text_templates(), ResourceTextTemplates))
def test_get_contacts(self) -> None: self.assertTrue(isinstance(Client('').contacts(), ResourceContacts))
def test_get_webhooks(self) -> None: self.assertTrue(isinstance(Client('').webhooks(), ResourceWebhooks))
def test_get_sepa_payments(self) -> None: self.assertTrue( isinstance(Client('').sepa_payments(), ResourceSepaPayments))
def test_get_serial_numbers_resource(self) -> None: self.assertTrue( isinstance(Client('').serial_numbers(), ResourceSerialNumbers))
def test_get_stocks_resource(self) -> None: self.assertTrue(isinstance(Client('').stocks(), ResourceStocks))
def test_get_tasks_resource(self) -> None: self.assertTrue(isinstance(Client('').tasks(), ResourceTasks))
def test_client_basic_headers(self) -> None: headers = Client("test").get_basic_headers() self.assertEqual("Bearer test", headers["Authorization"])
def test_client_pdf_headers(self) -> None: headers = Client("test").get_basic_headers_for_pdf() self.assertEqual("Bearer test", headers["Authorization"]) self.assertEqual("application/pdf", headers["Content-type"])
def test_get_discount_position_groups(self) -> None: self.assertTrue( isinstance( Client('').discount_position_groups(), ResourceDiscountPositionGroups))
def test_get_attachments(self) -> None: self.assertTrue( isinstance(Client('').attachments(), ResourceAttachments))
def test_get_time_trackings(self) -> None: self.assertTrue( isinstance(Client('').time_trackings(), ResourceTimeTrackings))
def test_get_endpoint(self) -> None: self.assertEqual("/position-groups", Client('').position_groups().get_resource_endpoint())
def test_client_version(self) -> None: self.assertEqual('0.2.1', Client('')._version)
def test_get_endpoint(self) -> None: self.assertEqual( "/pdf-templates", Client('').pdf_templates().get_resource_endpoint())
def test_client_base_url(self) -> None: self.assertEqual('https://api.easybill.de', Client('')._base_url)
def test_get_endpoint(self) -> None: self.assertEqual( "/sepa-payments", Client('').sepa_payments().get_resource_endpoint())
def test_api_key_on_client(self) -> None: client = Client('test') self.assertTrue(hasattr(client, 'api_key')) self.assertEqual('test', client.api_key)
def test_get_endpoint(self) -> None: self.assertEqual("/post-boxes", Client('').post_boxes().get_resource_endpoint())
def test_client_attributes(self) -> None: self.assertTrue(hasattr(Client(''), '_requests')) self.assertTrue(hasattr(Client(''), '_version')) self.assertTrue(hasattr(Client(''), '_base_url')) self.assertTrue(hasattr(Client(''), 'api_key'))
def test_get_endpoint(self) -> None: self.assertEqual( "/discounts/position", Client('').discount_positions().get_resource_endpoint())
def test_get_position_groups_resource(self) -> None: self.assertTrue( isinstance(Client('').position_groups(), ResourcePositionGroups))