Esempio n. 1
0
    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, "", "", {})
Esempio n. 2
0
    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"])
Esempio n. 3
0
 def test_get_projects_resource(self) -> None:
     self.assertTrue(isinstance(Client('').projects(), ResourceProjects))
Esempio n. 4
0
 def test_get_endpoint(self) -> None:
     self.assertEqual("/tasks", Client('').tasks().get_resource_endpoint())
Esempio n. 5
0
 def test_get_endpoint(self) -> None:
     self.assertEqual("/attachments",
                      Client('').attachments().get_resource_endpoint())
Esempio n. 6
0
 def test_get_endpoint(self) -> None:
     self.assertEqual(
         "/customer-groups",
         Client('').customer_groups().get_resource_endpoint())
Esempio n. 7
0
 def test_get_endpoint(self) -> None:
     self.assertEqual("/logins",
                      Client('').logins().get_resource_endpoint())
Esempio n. 8
0
    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,
            )
Esempio n. 9
0
 def test_get_text_templates(self) -> None:
     self.assertTrue(
         isinstance(Client('').text_templates(), ResourceTextTemplates))
Esempio n. 10
0
 def test_get_contacts(self) -> None:
     self.assertTrue(isinstance(Client('').contacts(), ResourceContacts))
Esempio n. 11
0
 def test_get_webhooks(self) -> None:
     self.assertTrue(isinstance(Client('').webhooks(), ResourceWebhooks))
Esempio n. 12
0
 def test_get_sepa_payments(self) -> None:
     self.assertTrue(
         isinstance(Client('').sepa_payments(), ResourceSepaPayments))
Esempio n. 13
0
 def test_get_serial_numbers_resource(self) -> None:
     self.assertTrue(
         isinstance(Client('').serial_numbers(), ResourceSerialNumbers))
Esempio n. 14
0
 def test_get_stocks_resource(self) -> None:
     self.assertTrue(isinstance(Client('').stocks(), ResourceStocks))
Esempio n. 15
0
 def test_get_tasks_resource(self) -> None:
     self.assertTrue(isinstance(Client('').tasks(), ResourceTasks))
Esempio n. 16
0
 def test_client_basic_headers(self) -> None:
     headers = Client("test").get_basic_headers()
     self.assertEqual("Bearer test", headers["Authorization"])
Esempio n. 17
0
 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"])
Esempio n. 18
0
 def test_get_discount_position_groups(self) -> None:
     self.assertTrue(
         isinstance(
             Client('').discount_position_groups(),
             ResourceDiscountPositionGroups))
Esempio n. 19
0
 def test_get_attachments(self) -> None:
     self.assertTrue(
         isinstance(Client('').attachments(), ResourceAttachments))
Esempio n. 20
0
 def test_get_time_trackings(self) -> None:
     self.assertTrue(
         isinstance(Client('').time_trackings(), ResourceTimeTrackings))
Esempio n. 21
0
 def test_get_endpoint(self) -> None:
     self.assertEqual("/position-groups",
                      Client('').position_groups().get_resource_endpoint())
Esempio n. 22
0
 def test_client_version(self) -> None:
     self.assertEqual('0.2.1', Client('')._version)
Esempio n. 23
0
 def test_get_endpoint(self) -> None:
     self.assertEqual(
         "/pdf-templates",
         Client('').pdf_templates().get_resource_endpoint())
Esempio n. 24
0
 def test_client_base_url(self) -> None:
     self.assertEqual('https://api.easybill.de', Client('')._base_url)
Esempio n. 25
0
 def test_get_endpoint(self) -> None:
     self.assertEqual(
         "/sepa-payments",
         Client('').sepa_payments().get_resource_endpoint())
Esempio n. 26
0
 def test_api_key_on_client(self) -> None:
     client = Client('test')
     self.assertTrue(hasattr(client, 'api_key'))
     self.assertEqual('test', client.api_key)
Esempio n. 27
0
 def test_get_endpoint(self) -> None:
     self.assertEqual("/post-boxes", Client('').post_boxes().get_resource_endpoint())
Esempio n. 28
0
 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'))
Esempio n. 29
0
 def test_get_endpoint(self) -> None:
     self.assertEqual(
         "/discounts/position",
         Client('').discount_positions().get_resource_endpoint())
Esempio n. 30
0
 def test_get_position_groups_resource(self) -> None:
     self.assertTrue(
         isinstance(Client('').position_groups(), ResourcePositionGroups))