-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_sync_invoice.py
More file actions
60 lines (40 loc) · 1.41 KB
/
test_sync_invoice.py
File metadata and controls
60 lines (40 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import pytest
from mpt_api_client.exceptions import MPTAPIError
from mpt_api_client.rql.query_builder import RQLQuery
pytestmark = [pytest.mark.flaky]
@pytest.fixture
def invoices(mpt_ops):
limit = 1
return mpt_ops.billing.invoices.fetch_page(limit=limit)
@pytest.fixture
def invoice(invoices):
if invoices:
return invoices[0]
return None
def test_get_invoice_by_id(mpt_ops, invoice):
if invoice is None:
pytest.skip("No invoice available for get by id test.")
invoice_id = invoice.id
result = mpt_ops.billing.invoices.get(invoice_id)
assert result is not None
def test_get_invoice_by_id_not_found(mpt_ops, invalid_invoice_id):
with pytest.raises(MPTAPIError, match=r"404 Not Found"):
mpt_ops.billing.invoices.get(invalid_invoice_id)
def test_list_invoices(mpt_ops):
limit = 10
result = mpt_ops.billing.invoices.fetch_page(limit=limit)
assert len(result) > 0
def test_filter_invoices(mpt_ops, invoice):
if invoice is None:
pytest.skip("No invoice available for filtering test.")
invoice_id = invoice.id
invoice_status = invoice.status
select_fields = ["-buyer"]
filtered_invoices = (
mpt_ops.billing.invoices
.filter(RQLQuery(id=invoice_id))
.filter(RQLQuery(status=invoice_status))
.select(*select_fields)
)
result = list(filtered_invoices.iterate())
assert len(result) == 1