diff --git a/tests/test_customers.py b/tests/test_customers.py new file mode 100644 index 00000000..b9c4e659 --- /dev/null +++ b/tests/test_customers.py @@ -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.'] \ No newline at end of file diff --git a/tests/test_invoices.py b/tests/test_invoices.py index c7a220a5..22c44bd1 100644 --- a/tests/test_invoices.py +++ b/tests/test_invoices.py @@ -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) diff --git a/tests/test_subscriptions.py b/tests/test_subscriptions.py index a097d0ef..c5be3b0b 100644 --- a/tests/test_subscriptions.py +++ b/tests/test_subscriptions.py @@ -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, @@ -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,