Skip to content

Commit 658a839

Browse files
committed
update tests to handle changes for 404’s
The generated code returns None instead of throwing an error when a 404 is returned
1 parent 7b72d46 commit 658a839

10 files changed

Lines changed: 101 additions & 63 deletions

tests/platform/test_service_cart_discounts.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def test_cart_discount_with_id(ct_platform_client: Client):
1818
value=models.CartDiscountValueRelative(permyriad=10),
1919
cart_predicate="",
2020
sort_order="",
21-
requires_discount_code=False
21+
requires_discount_code=False,
2222
)
2323
)
2424
)
@@ -33,13 +33,13 @@ def test_cart_discount_with_id(ct_platform_client: Client):
3333
)
3434
assert cart_discount.id
3535

36-
with pytest.raises(HTTPError):
37-
(
38-
ct_platform_client.with_project_key("unittest")
39-
.cart_discounts()
40-
.with_id("invalid")
41-
.get()
42-
)
36+
cart_discount = (
37+
ct_platform_client.with_project_key("unittest")
38+
.cart_discounts()
39+
.with_id("invalid")
40+
.get()
41+
)
42+
assert cart_discount is None
4343

4444

4545
def test_cart_discount_query(ct_platform_client: Client):

tests/platform/test_service_categories.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,13 @@ def test_category_with_id_get(ct_platform_client: Client):
3030
assert category.id
3131
assert category.key == "test-category"
3232

33-
with pytest.raises(HTTPError):
34-
ct_platform_client.with_project_key("unittest").categories().with_id(
35-
"invalid"
36-
).get()
33+
category = (
34+
ct_platform_client.with_project_key("unittest")
35+
.categories()
36+
.with_id("invalid")
37+
.get()
38+
)
39+
assert category is None
3740

3841

3942
def test_category_get_by_key(ct_platform_client: Client):
@@ -61,10 +64,13 @@ def test_category_get_by_key(ct_platform_client: Client):
6164
assert category.id
6265
assert category.key == "test-category"
6366

64-
with pytest.raises(HTTPError):
65-
ct_platform_client.with_project_key("unittest").categories().with_key(
66-
"invalid"
67-
).get()
67+
category = (
68+
ct_platform_client.with_project_key("unittest")
69+
.categories()
70+
.with_key("invalid")
71+
.get()
72+
)
73+
assert category is None
6874

6975

7076
def test_category_query(ct_platform_client: Client):

tests/platform/test_service_channels.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,13 @@ def test_channel_with_id_get(ct_platform_client: Client):
2828
assert channel.id
2929
assert channel.key == "test-channel"
3030

31-
with pytest.raises(HTTPError):
32-
ct_platform_client.with_project_key("unittest").channels().with_id(
33-
"invalid"
34-
).get()
31+
channel = (
32+
ct_platform_client.with_project_key("unittest")
33+
.channels()
34+
.with_id("invalid")
35+
.get()
36+
)
37+
assert channel is None
3538

3639

3740
def test_channel_query(ct_platform_client: Client):

tests/platform/test_service_custom_objects.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,13 @@ def test_custom_object_get_by_container_and_key(ct_platform_client: Client):
3232
assert custom_object.key == "test-object"
3333
assert custom_object.value == 1234
3434

35-
with pytest.raises(HTTPError):
36-
ct_platform_client.with_project_key(
37-
"unittest"
38-
).custom_objects().with_container_and_key("invalid", "invalid").get()
35+
custom_object = (
36+
ct_platform_client.with_project_key("unittest")
37+
.custom_objects()
38+
.with_container_and_key("invalid", "invalid")
39+
.get()
40+
)
41+
assert custom_object is None
3942

4043

4144
def test_custom_object_query(ct_platform_client: Client):
@@ -156,9 +159,11 @@ def test_delete_by_container_and_key(ct_platform_client: Client):
156159

157160
assert deleted_object.key == "test-object-1"
158161

159-
with pytest.raises(HTTPError):
160-
ct_platform_client.with_project_key(
161-
"unittest"
162-
).custom_objects().with_container_and_key(
162+
deleted_object = (
163+
ct_platform_client.with_project_key("unittest")
164+
.custom_objects()
165+
.with_container_and_key(
163166
container=custom_object.container, key=custom_object.key
164-
).delete()
167+
)
168+
.delete()
169+
)

tests/platform/test_service_discount_codes.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,13 @@ def test_discount_code_with_id_get(ct_platform_client: Client):
3535
assert discount_code.id
3636
assert discount_code.code == "1337"
3737

38-
with pytest.raises(HTTPError):
39-
ct_platform_client.with_project_key("unittest").discount_codes().with_id(
40-
"invalid"
41-
).get()
38+
discount_code = (
39+
ct_platform_client.with_project_key("unittest")
40+
.discount_codes()
41+
.with_id("invalid")
42+
.get()
43+
)
44+
assert discount_code is None
4245

4346

4447
def test_discount_code_query(ct_platform_client: Client):

tests/platform/test_service_order.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ def get_test_order():
236236
total_gross=models.CentPrecisionMoney(
237237
cent_amount=1000, currency_code="GBP", fraction_digits=2
238238
),
239-
tax_portions=[]
239+
tax_portions=[],
240240
),
241241
shipping_method_state=models.ShippingMethodState.MATCHES_CART,
242242
),
@@ -301,7 +301,7 @@ def get_test_order():
301301
total_gross=models.CentPrecisionMoney(
302302
cent_amount=1190, currency_code="GBP", fraction_digits=2
303303
),
304-
tax_portions=[]
304+
tax_portions=[],
305305
),
306306
line_item_mode=models.LineItemMode.STANDARD,
307307
)

tests/platform/test_service_product_projections.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,13 @@ def test_product_projections_with_id_get(ct_platform_client: Client):
3535

3636

3737
def test_product_projections_get_by_id_not_found(ct_platform_client: Client):
38-
with pytest.raises(HTTPError):
39-
ct_platform_client.with_project_key("unittest").products().with_id(
40-
"invalid"
41-
).get()
38+
product = (
39+
ct_platform_client.with_project_key("unittest")
40+
.products()
41+
.with_id("invalid")
42+
.get()
43+
)
44+
assert product is None
4245

4346

4447
def test_product_projections_get_by_key(ct_platform_client: Client):
@@ -83,10 +86,13 @@ def test_product_projections_query_parameters_are_passed(
8386

8487

8588
def test_product_projections_get_by_key_not_found(ct_platform_client: Client):
86-
with pytest.raises(HTTPError):
87-
ct_platform_client.with_project_key("unittest").products().with_id(
88-
"invalid"
89-
).get()
89+
product = (
90+
ct_platform_client.with_project_key("unittest")
91+
.products()
92+
.with_id("invalid")
93+
.get()
94+
)
95+
assert product is None
9096

9197

9298
def test_product_projections_query(ct_platform_client: Client):

tests/platform/test_service_product_types.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,13 @@ def test_product_types_with_id_get(ct_platform_client: Client):
2828
assert product_type.id
2929
assert product_type.key == "test-product-type"
3030

31-
with pytest.raises(HTTPError) as e:
32-
ct_platform_client.with_project_key("unittest").product_types().with_id(
33-
"invalid"
34-
).get()
31+
product_type = (
32+
ct_platform_client.with_project_key("unittest")
33+
.product_types()
34+
.with_id("invalid")
35+
.get()
36+
)
37+
assert product_type is None
3538

3639

3740
def test_product_types_get_by_key(ct_platform_client: Client):
@@ -57,10 +60,13 @@ def test_product_types_get_by_key(ct_platform_client: Client):
5760
assert product_type.id
5861
assert product_type.key == "test-product-type"
5962

60-
with pytest.raises(HTTPError) as e:
61-
ct_platform_client.with_project_key("unittest").product_types().with_id(
62-
"invalid"
63-
).get()
63+
product_type = (
64+
ct_platform_client.with_project_key("unittest")
65+
.product_types()
66+
.with_id("invalid")
67+
.get()
68+
)
69+
assert product_type is None
6470

6571

6672
def test_product_type_query(ct_platform_client: Client):

tests/platform/test_service_products.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,13 @@ def test_products_with_id_get(ct_platform_client: Client):
9090
assert product.id
9191
assert product.key == "test-product"
9292

93-
with pytest.raises(HTTPError) as e:
94-
ct_platform_client.with_project_key("unittest").products().with_id(
95-
"invalid"
96-
).get()
93+
product = (
94+
ct_platform_client.with_project_key("unittest")
95+
.products()
96+
.with_id("invalid")
97+
.get()
98+
)
99+
assert product is None
97100

98101

99102
def test_products_get_by_key(ct_platform_client: Client):
@@ -123,10 +126,13 @@ def test_products_get_by_key(ct_platform_client: Client):
123126
assert product.id
124127
assert product.key == "test-product"
125128

126-
with pytest.raises(HTTPError) as e:
127-
ct_platform_client.with_project_key("unittest").products().with_key(
128-
"invalid"
129-
).get()
129+
product = (
130+
ct_platform_client.with_project_key("unittest")
131+
.products()
132+
.with_key("invalid")
133+
.get()
134+
)
135+
assert product is None
130136

131137

132138
def test_product_query(ct_platform_client: Client):

tests/platform/test_service_shipping_methods.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,13 @@ def test_shipping_method_with_id_get(ct_platform_client: Client):
3434
assert shipping_method.id
3535
assert shipping_method.key == "test-shipping-method"
3636

37-
with pytest.raises(HTTPError):
38-
ct_platform_client.with_project_key("unittest").shipping_methods().with_id(
39-
"invalid"
40-
).get()
37+
shipping_method = (
38+
ct_platform_client.with_project_key("unittest")
39+
.shipping_methods()
40+
.with_id("invalid")
41+
.get()
42+
)
43+
assert shipping_method is None
4144

4245

4346
def test_shipping_method_query(ct_platform_client: Client):

0 commit comments

Comments
 (0)