-
Notifications
You must be signed in to change notification settings - Fork 59
Expand file tree
/
Copy pathtest_batch.py
More file actions
112 lines (70 loc) · 3.98 KB
/
Copy pathtest_batch.py
File metadata and controls
112 lines (70 loc) · 3.98 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import inspect
import os
import time
import pytest
from easypost.models import Batch
@pytest.mark.vcr()
def test_batch_create(one_call_buy_shipment, test_client):
batch = test_client.batch.create(shipments=[one_call_buy_shipment])
assert isinstance(batch, Batch)
assert str.startswith(batch.id, "batch_")
assert batch.shipments is not None
@pytest.mark.vcr()
def test_batch_retrieve(one_call_buy_shipment, test_client):
batch = test_client.batch.create(shipments=[one_call_buy_shipment])
retrieved_batch = test_client.batch.retrieve(batch.id)
assert isinstance(batch, Batch)
# status changes between creation and retrieval, so we can't compare the whole object
assert retrieved_batch.id == batch.id
@pytest.mark.vcr()
def test_batch_all(page_size, test_client):
batches = test_client.batch.all(page_size=page_size)
batches_array = batches["batches"]
assert len(batches_array) <= page_size
assert batches["has_more"] is not None
assert all(isinstance(batch, Batch) for batch in batches_array)
@pytest.mark.vcr()
def test_batch_buy(one_call_buy_shipment, test_client, synchronous_sleep_seconds):
function_name = inspect.stack()[0][3]
shipment_data = one_call_buy_shipment
batch = test_client.batch.create(shipments=[shipment_data])
if not os.path.exists(os.path.join("tests", "cassettes", f"{function_name}.yaml")):
time.sleep(synchronous_sleep_seconds) # Wait enough time for the batch to process before moving on
bought_batch = test_client.batch.buy(batch.id)
assert isinstance(bought_batch, Batch)
assert bought_batch.num_shipments == 1
@pytest.mark.vcr()
def test_batch_create_scanform(one_call_buy_shipment, test_client, synchronous_sleep_seconds):
function_name = inspect.stack()[0][3]
shipment_data = one_call_buy_shipment
batch = test_client.batch.create(shipments=[shipment_data])
if not os.path.exists(os.path.join("tests", "cassettes", f"{function_name}.yaml")):
time.sleep(synchronous_sleep_seconds) # Wait enough time for the batch to process before moving on
bought_batch = test_client.batch.buy(batch.id)
if not os.path.exists(os.path.join("tests", "cassettes", f"{function_name}.yaml")):
time.sleep(synchronous_sleep_seconds) # Wait enough time for the batch to process before moving on
batch_with_scanform = test_client.batch.create_scan_form(bought_batch.id)
# We can't assert anything meaningful here because the scanform gets queued
# for generation and may not be immediately available
assert isinstance(batch_with_scanform, Batch)
@pytest.mark.vcr()
def test_batch_add_remove_shipment(one_call_buy_shipment, test_client):
shipment = test_client.shipment.create(**one_call_buy_shipment)
batch = test_client.batch.create()
batch_with_shipments = test_client.batch.add_shipments(batch.id, shipments=[shipment])
assert batch_with_shipments.num_shipments == 1
batch_without_shipments = test_client.batch.remove_shipments(batch_with_shipments.id, shipments=[shipment])
assert batch_without_shipments.num_shipments == 0
@pytest.mark.vcr()
def test_batch_label(one_call_buy_shipment, test_client, synchronous_sleep_seconds):
function_name = inspect.stack()[0][3]
batch = test_client.batch.create(shipments=[one_call_buy_shipment])
if not os.path.exists(os.path.join("tests", "cassettes", f"{function_name}.yaml")):
time.sleep(synchronous_sleep_seconds) # Wait enough time for the batch to process before moving on
bought_batch = test_client.batch.buy(batch.id)
if not os.path.exists(os.path.join("tests", "cassettes", f"{function_name}.yaml")):
time.sleep(synchronous_sleep_seconds) # Wait enough time for the batch to process before moving on
batch_with_label = test_client.batch.label(bought_batch.id, file_format="ZPL")
# We can't assert anything meaningful here because the label gets queued
# for generation and may not be immediately available
assert isinstance(batch_with_label, Batch)