-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest_estimates_api.py
296 lines (244 loc) · 10.9 KB
/
test_estimates_api.py
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
# coding: utf-8
"""
Patch API V1
The core API used to integrate with Patch's service # noqa: E501
The version of the OpenAPI document: v1
Contact: [email protected]
Generated by: https://openapi-generator.tech
"""
from __future__ import absolute_import
import unittest
import os
from patch_api.api_client import ApiClient
class TestEstimatesApi(unittest.TestCase):
"""EstimatesApi unit test stubs"""
def setUp(self):
api_client = ApiClient(api_key=os.environ.get("SANDBOX_API_KEY"))
self.api = api_client.estimates # noqa: E501
def tearDown(self):
self.api = None
def test_create_and_retrieve_mass_estimate(self):
"""Test case for create_mass_estimate
Create an estimate based on mass of CO2 # noqa: E501
"""
mass_g = 100
project_id = "pro_test_2b67b11a030b66e0a6dd61a56b49079a"
estimate = self.api.create_mass_estimate(
mass_g=mass_g, project_id=project_id, create_order=True
)
self.assertTrue(estimate)
self.assertEqual(estimate.data.order.amount, mass_g)
retrieved_estimate = self.api.retrieve_estimate(id=estimate.data.id)
self.assertTrue(retrieved_estimate)
def test_create_and_retrieve_flight_estimate(self):
"""Test case for create_flight_estimate
Create an estimate based on the distance in meters flown by an airplane # noqa: E501
"""
distance_m = 1000000
estimate = self.api.create_flight_estimate(
distance_m=distance_m, create_order=True
)
self.assertEqual(estimate.data.type, "flight")
self.assertGreater(estimate.data.order.amount, 50000)
self.assertGreater(estimate.data.mass_g, 50000)
retrieved_estimate = self.api.retrieve_estimate(id=estimate.data.id)
self.assertTrue(retrieved_estimate)
def test_create_and_retrieve_flight_estimate_with_airports(self):
"""Test case for create_flight_estimate
Create an estimate based on the distance in meters flown by an airplane # noqa: E501
"""
estimate_short = self.api.create_flight_estimate(
origin_airport="SFO", destination_airport="LAX"
)
estimate_long = self.api.create_flight_estimate(
origin_airport="SFO", destination_airport="JFK"
)
self.assertGreater(estimate_long.data.mass_g, estimate_short.data.mass_g)
def test_create_bitcoin_estimate_no_params(self):
"""Test case for create_bitcoin_estimate
Create an estimate based on a transaction amount # noqa: E501
"""
estimate = self.api.create_bitcoin_estimate()
self.assertEqual(estimate.data.type, "bitcoin")
self.assertGreater(
estimate.data.mass_g, 200
) # not setting an exact value since this is changing daily
def test_create_bitcoin_estimate_transaction_value(self):
"""Test case for create_bitcoin_estimate
Create an estimate based on a transaction amount # noqa: E501
"""
transaction_value_btc_sats = 100000
estimate = self.api.create_bitcoin_estimate(
transaction_value_btc_sats=transaction_value_btc_sats
)
self.assertEqual(estimate.data.type, "bitcoin")
self.assertGreater(
estimate.data.mass_g, 200
) # not setting an exact value since this is changing daily
def test_create_hotel_estimate(self):
"""Test case for create_hotel_estimate
Create an estimate based on a country code # noqa: E501
"""
estimate = self.api.create_hotel_estimate(country_code="US")
self.assertEqual(estimate.data.type, "hotel")
self.assertGreater(
estimate.data.mass_g, 15_000
) # not setting an exact value since this is changing daily
def test_create_air_shipping_estimate_airport_iatas(self):
"""Test case for create_air_shipping_estimate
Create an estimate based on airport iata values # noqa: E501
"""
estimate = self.api.create_air_shipping_estimate(
destination_airport="JFK", freight_mass_g=19_158, origin_airport="ATL"
)
self.assertEqual(estimate.data.order, None)
self.assertEqual(estimate.data.type, "shipping_air")
self.assertGreater(
estimate.data.mass_g, 0
) # not setting an exact value since the mock values returned are randomized
def test_create_air_shipping_estimate_create_order(self):
"""Test case for create_air_shipping_estimate
Create an estimate and an order # noqa: E501
"""
estimate = self.api.create_air_shipping_estimate(
create_order=True,
destination_airport="JFK",
freight_mass_g=18_092,
origin_airport="ATL",
)
self.assertGreater(estimate.data.order.amount, 2_000)
self.assertEqual(estimate.data.type, "shipping_air")
self.assertGreater(
estimate.data.mass_g, 0
) # not setting an exact value since the mock values returned are randomized
def test_create_rail_shipping_estimate_addresses(self):
"""Test case for create_rail_shipping_estimate
Create an estimate based on locode values # noqa: E501
"""
estimate = self.api.create_rail_shipping_estimate(
destination_country_code="US",
destination_postal_code="90210",
freight_mass_g=18092,
origin_country_code="US",
origin_postal_code="97209",
)
self.assertEqual(estimate.data.order, None)
self.assertEqual(estimate.data.type, "shipping_rail")
self.assertGreater(
estimate.data.mass_g, 0
) # not setting an exact value since the mock values returned are randomized
def test_create_rail_shipping_estimate_locodes(self):
"""Test case for create_rail_shipping_estimate
Create an estimate based on locode values # noqa: E501
"""
estimate = self.api.create_rail_shipping_estimate(
destination_locode="USSD2", freight_mass_g=18092, origin_locode="USSEA"
)
self.assertEqual(estimate.data.order, None)
self.assertEqual(estimate.data.type, "shipping_rail")
self.assertGreater(
estimate.data.mass_g, 0
) # not setting an exact value since the mock values returned are randomized
def test_create_rail_shipping_estimate_create_order(self):
"""Test case for create_rail_shipping_estimate
Create an estimate and an order # noqa: E501
"""
estimate = self.api.create_rail_shipping_estimate(
create_order=True,
destination_locode="USSD2",
freight_mass_g=19_217,
origin_locode="USSEA",
)
self.assertGreater(estimate.data.order.amount, 0)
self.assertEqual(estimate.data.type, "shipping_rail")
self.assertGreater(
estimate.data.mass_g, 0
) # not setting an exact value since the mock values returned are randomized
def test_create_road_shipping_estimate_addresses(self):
"""Test case for create_road_shipping_estimate
Create an estimate based on locode values # noqa: E501
"""
estimate = self.api.create_road_shipping_estimate(
destination_country_code="US",
destination_postal_code="90210",
freight_mass_g=19_166,
origin_country_code="US",
origin_postal_code="97209",
)
self.assertEqual(estimate.data.order, None)
self.assertEqual(estimate.data.type, "shipping_road")
self.assertGreater(
estimate.data.mass_g, 0
) # not setting an exact value since the mock values returned are randomized
def test_create_road_shipping_estimate_locodes(self):
"""Test case for create_road_shipping_estimate
Create an estimate based on locode values # noqa: E501
"""
estimate = self.api.create_road_shipping_estimate(
destination_locode="USSD2", freight_mass_g=16_907, origin_locode="USSEA"
)
self.assertEqual(estimate.data.order, None)
self.assertEqual(estimate.data.type, "shipping_road")
self.assertGreater(
estimate.data.mass_g, 0
) # not setting an exact value since the mock values returned are randomized
def test_create_road_shipping_estimate_create_order(self):
"""Test case for create_road_shipping_estimate
Create an estimate and an order # noqa: E501
"""
estimate = self.api.create_road_shipping_estimate(
create_order=True,
destination_locode="USSD2",
freight_mass_g=21_933,
origin_locode="USSEA",
)
self.assertGreater(estimate.data.order.amount, 0)
self.assertEqual(estimate.data.type, "shipping_road")
self.assertGreater(
estimate.data.mass_g, 0
) # not setting an exact value since the mock values returned are randomized
def test_create_sea_shipping_estimate_addresses(self):
"""Test case for create_sea_shipping_estimate
Create an estimate based on address values # noqa: E501
"""
estimate = self.api.create_sea_shipping_estimate(
destination_country_code="US",
destination_postal_code="90210",
freight_mass_g=26_906,
origin_country_code="US",
origin_postal_code="97209",
)
self.assertEqual(estimate.data.order, None)
self.assertEqual(estimate.data.type, "shipping_sea")
self.assertGreater(
estimate.data.mass_g, 0
) # not setting an exact value since the mock values returned are randomized
def test_create_sea_shipping_estimate_locodes(self):
"""Test case for create_sea_shipping_estimate
Create an estimate based on locode values # noqa: E501
"""
estimate = self.api.create_sea_shipping_estimate(
destination_locode="USSD2", freight_mass_g=17_311, origin_locode="USSEA"
)
self.assertEqual(estimate.data.order, None)
self.assertEqual(estimate.data.type, "shipping_sea")
self.assertGreater(
estimate.data.mass_g, 0
) # not setting an exact value since the mock values returned are randomized
def test_create_sea_shipping_estimate_create_order(self):
"""Test case for create_sea_shipping_estimate
Create an estimate and an order # noqa: E501
"""
estimate = self.api.create_sea_shipping_estimate(
create_order=True,
destination_locode="USSD2",
freight_mass_g=22_210,
origin_locode="USSEA",
)
self.assertGreater(estimate.data.order.amount, 0)
self.assertEqual(estimate.data.type, "shipping_sea")
self.assertGreater(
estimate.data.mass_g, 0
) # not setting an exact value since the mock values returned are randomized
if __name__ == "__main__":
unittest.main()