-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_estimates_api.py
More file actions
378 lines (312 loc) · 14.1 KB
/
Copy pathtest_estimates_api.py
File metadata and controls
378 lines (312 loc) · 14.1 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
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
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
# 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.mass_g, 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.mass_g, 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_and_retrieve_shipping_estimate(self):
"""Test case for create_shipping_estimate
Create an estimate based on the shipping distance, transportation method, and package mass # noqa: E501
"""
distance_m = 10000000
package_mass_g = 1000
transportation_method = "sea"
estimate = self.api.create_shipping_estimate(
distance_m=distance_m,
package_mass_g=package_mass_g,
transportation_method=transportation_method,
create_order=False,
)
self.assertEqual(estimate.data.order, None)
self.assertEqual(estimate.data.type, "shipping")
self.assertGreater(estimate.data.mass_g, 200)
retrieved_estimate = self.api.retrieve_estimate(id=estimate.data.id)
self.assertTrue(retrieved_estimate)
def test_create_and_retrieve_vehicle_estimate(self):
"""Test case for create_vehicle_estimate
Create an estimate based on the vehicle distance, transportation method, and package mass # noqa: E501
"""
distance_m = 1000000
make = "Toyota"
model = "Corolla"
year = 1995
estimate = self.api.create_vehicle_estimate(
distance_m=distance_m, model=model, make=make, year=year
)
self.assertEqual(estimate.data.type, "vehicle")
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_vehicle_estimate_best_match(self):
"""Test case for create_vehicle_estimate
Create an estimate based on the vehicle with partial information # noqa: E501
"""
distance_m = 1000000
make = "Toyota"
model = "Corolla"
estimate = self.api.create_vehicle_estimate(
distance_m=distance_m, model=model, make=make
)
self.assertEqual(estimate.data.type, "vehicle")
self.assertGreater(estimate.data.mass_g, 50000)
retrieved_estimate = self.api.retrieve_estimate(id=estimate.data.id)
self.assertTrue(retrieved_estimate)
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_bitcoin_estimate_transaction_value(self):
"""Test case for create_bitcoin_estimate
Create an estimate based on an average daily balance # noqa: E501
"""
estimate1 = self.api.create_bitcoin_estimate(
average_daily_balance_btc_sats=100000
)
estimate2 = self.api.create_bitcoin_estimate(
average_daily_balance_btc_sats=1000000
)
self.assertEqual(estimate1.data.type, "bitcoin")
self.assertGreater(estimate2.data.mass_g, estimate1.data.mass_g)
def test_create_ethereum_estimate_transaction_value(self):
"""Test case for create_ethereum_estimate
Create an estimate based on a transaction amount # noqa: E501
"""
estimate = self.api.create_ethereum_estimate(gas_used=1000)
self.assertEqual(estimate.data.type, "ethereum")
self.assertGreater(
estimate.data.mass_g, 1
) # 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, 10_000
) # 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, 10_000
) # 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, 300
) # 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, 800
) # 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, 900)
self.assertEqual(estimate.data.type, "shipping_rail")
self.assertGreater(
estimate.data.mass_g, 800
) # 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, 600
) # 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, 1_000
) # 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, 1_000)
self.assertEqual(estimate.data.type, "shipping_road")
self.assertGreater(
estimate.data.mass_g, 800
) # 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, 600
) # 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, 1_000
) # 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, 1_000)
self.assertEqual(estimate.data.type, "shipping_sea")
self.assertGreater(
estimate.data.mass_g, 800
) # not setting an exact value since the mock values returned are randomized
if __name__ == "__main__":
unittest.main()