Skip to content

Commit

Permalink
update tests to handle changes for 404’s
Browse files Browse the repository at this point in the history
The generated code returns None instead of throwing an error when a 404
is returned
  • Loading branch information
mvantellingen committed Apr 6, 2024
1 parent 7b72d46 commit 658a839
Show file tree
Hide file tree
Showing 10 changed files with 101 additions and 63 deletions.
16 changes: 8 additions & 8 deletions tests/platform/test_service_cart_discounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def test_cart_discount_with_id(ct_platform_client: Client):
value=models.CartDiscountValueRelative(permyriad=10),
cart_predicate="",
sort_order="",
requires_discount_code=False
requires_discount_code=False,
)
)
)
Expand All @@ -33,13 +33,13 @@ def test_cart_discount_with_id(ct_platform_client: Client):
)
assert cart_discount.id

with pytest.raises(HTTPError):
(
ct_platform_client.with_project_key("unittest")
.cart_discounts()
.with_id("invalid")
.get()
)
cart_discount = (
ct_platform_client.with_project_key("unittest")
.cart_discounts()
.with_id("invalid")
.get()
)
assert cart_discount is None


def test_cart_discount_query(ct_platform_client: Client):
Expand Down
22 changes: 14 additions & 8 deletions tests/platform/test_service_categories.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,13 @@ def test_category_with_id_get(ct_platform_client: Client):
assert category.id
assert category.key == "test-category"

with pytest.raises(HTTPError):
ct_platform_client.with_project_key("unittest").categories().with_id(
"invalid"
).get()
category = (
ct_platform_client.with_project_key("unittest")
.categories()
.with_id("invalid")
.get()
)
assert category is None


def test_category_get_by_key(ct_platform_client: Client):
Expand Down Expand Up @@ -61,10 +64,13 @@ def test_category_get_by_key(ct_platform_client: Client):
assert category.id
assert category.key == "test-category"

with pytest.raises(HTTPError):
ct_platform_client.with_project_key("unittest").categories().with_key(
"invalid"
).get()
category = (
ct_platform_client.with_project_key("unittest")
.categories()
.with_key("invalid")
.get()
)
assert category is None


def test_category_query(ct_platform_client: Client):
Expand Down
11 changes: 7 additions & 4 deletions tests/platform/test_service_channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,13 @@ def test_channel_with_id_get(ct_platform_client: Client):
assert channel.id
assert channel.key == "test-channel"

with pytest.raises(HTTPError):
ct_platform_client.with_project_key("unittest").channels().with_id(
"invalid"
).get()
channel = (
ct_platform_client.with_project_key("unittest")
.channels()
.with_id("invalid")
.get()
)
assert channel is None


def test_channel_query(ct_platform_client: Client):
Expand Down
23 changes: 14 additions & 9 deletions tests/platform/test_service_custom_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,13 @@ def test_custom_object_get_by_container_and_key(ct_platform_client: Client):
assert custom_object.key == "test-object"
assert custom_object.value == 1234

with pytest.raises(HTTPError):
ct_platform_client.with_project_key(
"unittest"
).custom_objects().with_container_and_key("invalid", "invalid").get()
custom_object = (
ct_platform_client.with_project_key("unittest")
.custom_objects()
.with_container_and_key("invalid", "invalid")
.get()
)
assert custom_object is None


def test_custom_object_query(ct_platform_client: Client):
Expand Down Expand Up @@ -156,9 +159,11 @@ def test_delete_by_container_and_key(ct_platform_client: Client):

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

with pytest.raises(HTTPError):
ct_platform_client.with_project_key(
"unittest"
).custom_objects().with_container_and_key(
deleted_object = (
ct_platform_client.with_project_key("unittest")
.custom_objects()
.with_container_and_key(
container=custom_object.container, key=custom_object.key
).delete()
)
.delete()
)
11 changes: 7 additions & 4 deletions tests/platform/test_service_discount_codes.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,13 @@ def test_discount_code_with_id_get(ct_platform_client: Client):
assert discount_code.id
assert discount_code.code == "1337"

with pytest.raises(HTTPError):
ct_platform_client.with_project_key("unittest").discount_codes().with_id(
"invalid"
).get()
discount_code = (
ct_platform_client.with_project_key("unittest")
.discount_codes()
.with_id("invalid")
.get()
)
assert discount_code is None


def test_discount_code_query(ct_platform_client: Client):
Expand Down
4 changes: 2 additions & 2 deletions tests/platform/test_service_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ def get_test_order():
total_gross=models.CentPrecisionMoney(
cent_amount=1000, currency_code="GBP", fraction_digits=2
),
tax_portions=[]
tax_portions=[],
),
shipping_method_state=models.ShippingMethodState.MATCHES_CART,
),
Expand Down Expand Up @@ -301,7 +301,7 @@ def get_test_order():
total_gross=models.CentPrecisionMoney(
cent_amount=1190, currency_code="GBP", fraction_digits=2
),
tax_portions=[]
tax_portions=[],
),
line_item_mode=models.LineItemMode.STANDARD,
)
Expand Down
22 changes: 14 additions & 8 deletions tests/platform/test_service_product_projections.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,13 @@ def test_product_projections_with_id_get(ct_platform_client: Client):


def test_product_projections_get_by_id_not_found(ct_platform_client: Client):
with pytest.raises(HTTPError):
ct_platform_client.with_project_key("unittest").products().with_id(
"invalid"
).get()
product = (
ct_platform_client.with_project_key("unittest")
.products()
.with_id("invalid")
.get()
)
assert product is None


def test_product_projections_get_by_key(ct_platform_client: Client):
Expand Down Expand Up @@ -83,10 +86,13 @@ def test_product_projections_query_parameters_are_passed(


def test_product_projections_get_by_key_not_found(ct_platform_client: Client):
with pytest.raises(HTTPError):
ct_platform_client.with_project_key("unittest").products().with_id(
"invalid"
).get()
product = (
ct_platform_client.with_project_key("unittest")
.products()
.with_id("invalid")
.get()
)
assert product is None


def test_product_projections_query(ct_platform_client: Client):
Expand Down
22 changes: 14 additions & 8 deletions tests/platform/test_service_product_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,13 @@ def test_product_types_with_id_get(ct_platform_client: Client):
assert product_type.id
assert product_type.key == "test-product-type"

with pytest.raises(HTTPError) as e:
ct_platform_client.with_project_key("unittest").product_types().with_id(
"invalid"
).get()
product_type = (
ct_platform_client.with_project_key("unittest")
.product_types()
.with_id("invalid")
.get()
)
assert product_type is None


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

with pytest.raises(HTTPError) as e:
ct_platform_client.with_project_key("unittest").product_types().with_id(
"invalid"
).get()
product_type = (
ct_platform_client.with_project_key("unittest")
.product_types()
.with_id("invalid")
.get()
)
assert product_type is None


def test_product_type_query(ct_platform_client: Client):
Expand Down
22 changes: 14 additions & 8 deletions tests/platform/test_service_products.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,13 @@ def test_products_with_id_get(ct_platform_client: Client):
assert product.id
assert product.key == "test-product"

with pytest.raises(HTTPError) as e:
ct_platform_client.with_project_key("unittest").products().with_id(
"invalid"
).get()
product = (
ct_platform_client.with_project_key("unittest")
.products()
.with_id("invalid")
.get()
)
assert product is None


def test_products_get_by_key(ct_platform_client: Client):
Expand Down Expand Up @@ -123,10 +126,13 @@ def test_products_get_by_key(ct_platform_client: Client):
assert product.id
assert product.key == "test-product"

with pytest.raises(HTTPError) as e:
ct_platform_client.with_project_key("unittest").products().with_key(
"invalid"
).get()
product = (
ct_platform_client.with_project_key("unittest")
.products()
.with_key("invalid")
.get()
)
assert product is None


def test_product_query(ct_platform_client: Client):
Expand Down
11 changes: 7 additions & 4 deletions tests/platform/test_service_shipping_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,13 @@ def test_shipping_method_with_id_get(ct_platform_client: Client):
assert shipping_method.id
assert shipping_method.key == "test-shipping-method"

with pytest.raises(HTTPError):
ct_platform_client.with_project_key("unittest").shipping_methods().with_id(
"invalid"
).get()
shipping_method = (
ct_platform_client.with_project_key("unittest")
.shipping_methods()
.with_id("invalid")
.get()
)
assert shipping_method is None


def test_shipping_method_query(ct_platform_client: Client):
Expand Down

0 comments on commit 658a839

Please sign in to comment.