-
Notifications
You must be signed in to change notification settings - Fork 58
Expand file tree
/
Copy pathtest_refund.py
More file actions
63 lines (44 loc) · 2.01 KB
/
test_refund.py
File metadata and controls
63 lines (44 loc) · 2.01 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
61
62
63
import pytest
from easypost.constant import (
_FILTERS_KEY,
_TEST_FAILED_INTENTIONALLY_ERROR,
NO_MORE_PAGES_ERROR,
)
from easypost.models import Refund
@pytest.mark.vcr()
def test_refund_create(one_call_buy_shipment, usps, test_client):
shipment = test_client.shipment.create(**one_call_buy_shipment)
# We need to retrieve the shipment so that the tracking_code has time to populate
retrieved_shipment = test_client.shipment.retrieve(shipment["id"])
refund = test_client.refund.create(
carrier=usps,
tracking_codes=[retrieved_shipment.tracking_code],
)
assert str.startswith(refund[0].id, "rfnd_")
assert refund[0].status == "submitted"
@pytest.mark.vcr()
def test_refund_all(page_size, test_client):
refunds = test_client.refund.all(page_size=page_size)
refunds_array = refunds["refunds"]
assert len(refunds_array) <= page_size
assert refunds["has_more"] is not None
assert all(isinstance(refund, Refund) for refund in refunds_array)
@pytest.mark.vcr()
def test_refund_get_next_page(page_size, test_client):
try:
first_page = test_client.refund.all(page_size=page_size)
next_page = test_client.refund.get_next_page(refunds=first_page, page_size=page_size)
first_id_of_first_page = first_page["refunds"][0].id
first_id_of_second_page = next_page["refunds"][0].id
assert first_id_of_first_page != first_id_of_second_page
# Verify that the filters are being passed along for behind-the-scenes reference
assert first_page[_FILTERS_KEY] == next_page[_FILTERS_KEY]
except Exception as e:
if e.message != NO_MORE_PAGES_ERROR:
raise Exception(_TEST_FAILED_INTENTIONALLY_ERROR)
@pytest.mark.vcr()
def test_refund_retrieve(page_size, test_client):
refunds = test_client.refund.all(page_size=page_size)
retrieved_refund = test_client.refund.retrieve(refunds["refunds"][0]["id"])
assert isinstance(retrieved_refund, Refund)
assert retrieved_refund.id == refunds["refunds"][0].id