Skip to content

Commit

Permalink
[DE-870] Test customer exception deserialization, fix exceptions in t…
Browse files Browse the repository at this point in the history
…ests
  • Loading branch information
maciej-nedza committed Jun 17, 2024
1 parent 44e988d commit d87e1c6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
22 changes: 22 additions & 0 deletions tests/test_customers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import pytest

from advancedbilling.exceptions.customer_error_response_exception import CustomerErrorResponseException
from advancedbilling.controllers.customers_controller import CustomersController
from advancedbilling.models.create_customer_request import CreateCustomerRequest
from tests.data import InitCases


class TestCustomers:
def test_invalid_customer_creation_throws_422_error(self, customers_controller: CustomersController):
customer_request = CreateCustomerRequest(InitCases.get_customer_request())
customers_controller.create_customer(
customer_request
)

with pytest.raises(CustomerErrorResponseException) as e:
customers_controller.create_customer(
customer_request
)

assert e.value.response_code == 422
assert e.value.errors == ['Reference: must be unique - that value has been taken.']
8 changes: 4 additions & 4 deletions tests/test_invoices.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,11 @@ def test_create_invoice_given_invalid_period_range_end_value_then_should_throw_e
CreateInvoiceRequest(InitCases.get_invoice_request_with_invalid_period()),
)

errors = exception_info.value.errors
errors = exception_info.value.errors

assert exception_info.value.response_code == 422
assert len(errors) == 1
assert errors == {"line_items[0].period_range_end": ["Must be greater or equal to period_range_start."]}
assert exception_info.value.response_code == 422
assert len(errors) == 1
assert errors == {"line_items[0].period_range_end": ["Must be greater or equal to period_range_start."]}

subscriptions_controller.purge_subscription(subscription.id, customer.id)
customers_controller.delete_customer(customer.id)
6 changes: 3 additions & 3 deletions tests/test_subscriptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ def test_create_subscription_given_existing_product_and_not_existing_customer_th
)
)

assert e.value.response_code == 422
assert e.value.message == "A Customer must be specified for the subscription to be valid."
assert e.value.response_code == 422
assert e.value.errors == ["A Customer must be specified for the subscription to be valid."]

def test_create_subscription_given_invalid_credentials_then_thrown_exception_with_401_status_code(
self,
Expand All @@ -159,7 +159,7 @@ def test_create_subscription_given_invalid_credentials_then_thrown_exception_wit
)
)

assert e.value.response_code == 401
assert e.value.response_code == 401

def test_list_subscriptions_filtering_by_metadata_given_filter_by_metadata_then_return_subscription_having_this_metadata(
self,
Expand Down

0 comments on commit d87e1c6

Please sign in to comment.