Skip to content

Commit 644a970

Browse files
author
Robert Segal
committed
Added e2e tests for commerce credit memos
1 parent 9879263 commit 644a970

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_credit_memo_id():
6+
return "CRD-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 credit_memos(async_mpt_ops):
11+
limit = 1
12+
return await async_mpt_ops.billing.credit_memos.fetch_page(limit=limit)
13+
14+
15+
@pytest.fixture
16+
def credit_memo(credit_memos):
17+
if credit_memos:
18+
return credit_memos[0]
19+
return None
20+
21+
22+
async def test_get_credit_memo_by_id(async_mpt_ops, credit_memo):
23+
if credit_memo is None:
24+
pytest.skip("No credit memos available to test retrieval by ID.")
25+
credit_memo_id = credit_memo.id
26+
27+
result = await async_mpt_ops.billing.credit_memos.get(credit_memo_id)
28+
29+
assert result is not None
30+
31+
32+
async def test_get_credit_memo_by_id_not_found(async_mpt_ops, invalid_credit_memo_id):
33+
with pytest.raises(MPTAPIError, match=r"404 Not Found"):
34+
await async_mpt_ops.billing.credit_memos.get(invalid_credit_memo_id)
35+
36+
37+
async def test_list_credit_memos(async_mpt_ops):
38+
limit = 10
39+
40+
result = await async_mpt_ops.billing.credit_memos.fetch_page(limit=limit)
41+
42+
assert len(result) > 0
43+
44+
45+
async def test_filter_credit_memos(async_mpt_ops, credit_memo):
46+
if credit_memo is None:
47+
pytest.skip("No credit memos available to test filtering.")
48+
credit_memo_id = credit_memo.id
49+
credit_memo_status = credit_memo.status
50+
select_fields = ["-vendor"]
51+
filtered_credit_memos = (
52+
async_mpt_ops.billing.credit_memos.filter(RQLQuery(id=credit_memo_id))
53+
.filter(RQLQuery(status=credit_memo_status))
54+
.select(*select_fields)
55+
)
56+
57+
result = [credit_memo async for credit_memo in filtered_credit_memos.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 credit_memos(mpt_ops):
11+
limit = 1
12+
return mpt_ops.billing.credit_memos.fetch_page(limit=limit)
13+
14+
15+
@pytest.fixture
16+
def credit_memo(credit_memos):
17+
if credit_memos:
18+
return credit_memos[0]
19+
return None
20+
21+
22+
def test_get_credit_memo_by_id(mpt_ops, credit_memo):
23+
if credit_memo is None:
24+
pytest.skip("No credit memos available to test retrieval by ID.")
25+
credit_memo_id = credit_memo.id
26+
27+
result = mpt_ops.billing.credit_memos.get(credit_memo_id)
28+
29+
assert result is not None
30+
31+
32+
def test_get_credit_memo_by_id_not_found(mpt_ops, invalid_credit_memo_id):
33+
with pytest.raises(MPTAPIError, match=r"404 Not Found"):
34+
mpt_ops.billing.credit_memos.get(invalid_credit_memo_id)
35+
36+
37+
def test_list_credit_memos(mpt_ops):
38+
limit = 10
39+
40+
result = mpt_ops.billing.credit_memos.fetch_page(limit=limit)
41+
42+
assert len(result) > 0
43+
44+
45+
def test_filter_credit_memos(mpt_ops, credit_memo):
46+
if credit_memo is None:
47+
pytest.skip("No credit memos available to test filtering.")
48+
credit_memo_id = credit_memo.id
49+
credit_memo_status = credit_memo.status
50+
select_fields = ["-vendor"]
51+
filtered_credit_memos = (
52+
mpt_ops.billing.credit_memos.filter(RQLQuery(id=credit_memo_id))
53+
.filter(RQLQuery(status=credit_memo_status))
54+
.select(*select_fields)
55+
)
56+
57+
result = list(filtered_credit_memos.iterate())
58+
59+
assert len(result) == 1

0 commit comments

Comments
 (0)