Skip to content

Commit cc46ffd

Browse files
authored
[MPT-14920] Added e2e tests for invoice (#192)
Added e2e tests for invoice Data can't be seeded because it comes from Nav. https://softwareone.atlassian.net/browse/MPT-14920 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> Closes [MPT-14920](https://softwareone.atlassian.net/browse/MPT-14920) ## Changes - Added invoice e2e test fixture `invalid_invoice_id` in `conftest.py` to provide a consistent invalid invoice identifier for testing error cases - Added asynchronous e2e tests for invoice operations: - Retrieval of invoice by ID - 404 handling for invalid invoice IDs - Listing invoices with limit - Filtering invoices by ID and status with field selection - Added synchronous e2e tests for invoice operations: - CRUD-like behavior tests for invoice retrieval - Error handling for non-existent invoices (404 Not Found) - Pagination and listing with limits - Advanced filtering using RQLQuery with field exclusion - Tests marked as flaky with conditional skip when test data unavailable <!-- end of auto-generated comment: release notes by coderabbit.ai --> [MPT-14920]: https://softwareone.atlassian.net/browse/MPT-14920?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
2 parents e65c348 + b824350 commit cc46ffd

File tree

3 files changed

+124
-0
lines changed

3 files changed

+124
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import pytest
2+
3+
4+
@pytest.fixture
5+
def invalid_invoice_id():
6+
return "INV-0000-0000-0000-0000"
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import pytest
2+
3+
from mpt_api_client.exceptions import MPTAPIError
4+
from mpt_api_client.rql.query_builder import RQLQuery
5+
6+
pytestmark = [pytest.mark.flaky]
7+
8+
9+
@pytest.fixture
10+
async def invoices(async_mpt_ops):
11+
limit = 1
12+
return await async_mpt_ops.billing.invoices.fetch_page(limit=limit)
13+
14+
15+
@pytest.fixture
16+
def invoice(invoices):
17+
if invoices:
18+
return invoices[0]
19+
return None
20+
21+
22+
async def test_get_invoice_by_id(async_mpt_ops, invoice):
23+
if invoice is None:
24+
pytest.skip("No invoice available for get by id test.")
25+
invoice_id = invoice.id
26+
27+
result = await async_mpt_ops.billing.invoices.get(invoice_id)
28+
29+
assert result is not None
30+
31+
32+
async def test_get_invoice_by_id_not_found(async_mpt_ops, invalid_invoice_id):
33+
with pytest.raises(MPTAPIError, match=r"404 Not Found"):
34+
await async_mpt_ops.billing.invoices.get(invalid_invoice_id)
35+
36+
37+
async def test_list_invoices(async_mpt_ops):
38+
limit = 10
39+
40+
result = await async_mpt_ops.billing.invoices.fetch_page(limit=limit)
41+
42+
assert len(result) > 0
43+
44+
45+
async def test_filter_invoices(async_mpt_ops, invoice):
46+
if invoice is None:
47+
pytest.skip("No invoice available to test filtering.")
48+
invoice_id = invoice.id
49+
invoice_status = invoice.status
50+
select_fields = ["-buyer"]
51+
filtered_invoices = (
52+
async_mpt_ops.billing.invoices.filter(RQLQuery(id=invoice_id))
53+
.filter(RQLQuery(status=invoice_status))
54+
.select(*select_fields)
55+
)
56+
57+
result = [invoice async for invoice in filtered_invoices.iterate()]
58+
59+
assert len(result) == 1
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import pytest
2+
3+
from mpt_api_client.exceptions import MPTAPIError
4+
from mpt_api_client.rql.query_builder import RQLQuery
5+
6+
pytestmark = [pytest.mark.flaky]
7+
8+
9+
@pytest.fixture
10+
def invoices(mpt_ops):
11+
limit = 1
12+
return mpt_ops.billing.invoices.fetch_page(limit=limit)
13+
14+
15+
@pytest.fixture
16+
def invoice(invoices):
17+
if invoices:
18+
return invoices[0]
19+
return None
20+
21+
22+
def test_get_invoice_by_id(mpt_ops, invoice):
23+
if invoice is None:
24+
pytest.skip("No invoice available for get by id test.")
25+
invoice_id = invoice.id
26+
27+
result = mpt_ops.billing.invoices.get(invoice_id)
28+
29+
assert result is not None
30+
31+
32+
def test_get_invoice_by_id_not_found(mpt_ops, invalid_invoice_id):
33+
with pytest.raises(MPTAPIError, match=r"404 Not Found"):
34+
mpt_ops.billing.invoices.get(invalid_invoice_id)
35+
36+
37+
def test_list_invoices(mpt_ops):
38+
limit = 10
39+
40+
result = mpt_ops.billing.invoices.fetch_page(limit=limit)
41+
42+
assert len(result) > 0
43+
44+
45+
def test_filter_invoices(mpt_ops, invoice):
46+
if invoice is None:
47+
pytest.skip("No invoice available for filtering test.")
48+
invoice_id = invoice.id
49+
invoice_status = invoice.status
50+
select_fields = ["-buyer"]
51+
filtered_invoices = (
52+
mpt_ops.billing.invoices.filter(RQLQuery(id=invoice_id))
53+
.filter(RQLQuery(status=invoice_status))
54+
.select(*select_fields)
55+
)
56+
57+
result = list(filtered_invoices.iterate())
58+
59+
assert len(result) == 1

0 commit comments

Comments
 (0)