diff --git a/CHANGELOG.md b/CHANGELOG.md index cb327dcd..98408665 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ +# 1.46.2 + +- Remove nose in favour of pytest +- Remove inaccessible MandateRequestConstraints resource + # 1.46.1 - Fix throwing error on empty 204 responses diff --git a/README.rst b/README.rst index 68fcf06b..2fe9b5ac 100644 --- a/README.rst +++ b/README.rst @@ -642,7 +642,7 @@ First, install the development dependencies: $ pip install -r requirements-dev.txt -To run the test suite against the current Python version, run ``nosetests``. +To run the test suite against the current Python version, run ``pytest``. To run the test suite against multiple Python versions, run ``tox``. diff --git a/gocardless_pro/__init__.py b/gocardless_pro/__init__.py index 43dfdc1f..1f815adb 100644 --- a/gocardless_pro/__init__.py +++ b/gocardless_pro/__init__.py @@ -2,5 +2,5 @@ from .client import Client -__version__ = '1.46.1' +__version__ = '1.46.2' diff --git a/gocardless_pro/api_client.py b/gocardless_pro/api_client.py index d168f56c..1a60a6fd 100644 --- a/gocardless_pro/api_client.py +++ b/gocardless_pro/api_client.py @@ -144,7 +144,7 @@ def _default_headers(self): 'Authorization': 'Bearer {0}'.format(self.access_token), 'Content-Type': 'application/json', 'GoCardless-Client-Library': 'gocardless-pro-python', - 'GoCardless-Client-Version': '1.46.1', + 'GoCardless-Client-Version': '1.46.2', 'User-Agent': self._user_agent(), 'GoCardless-Version': '2015-07-06', } @@ -153,7 +153,7 @@ def _user_agent(self): python_version = '.'.join(platform.python_version_tuple()[0:2]) vm_version = '{}.{}.{}-{}{}'.format(*sys.version_info) return ' '.join([ - 'gocardless-pro-python/1.46.1', + 'gocardless-pro-python/1.46.2', 'python/{0}'.format(python_version), '{0}/{1}'.format(platform.python_implementation(), vm_version), '{0}/{1}'.format(platform.system(), platform.release()), diff --git a/requirements-dev.txt b/requirements-dev.txt index 6032df4b..3845c98d 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,4 +1,3 @@ responses>=0.10.16;python_version>"3.4" responses<0.10.16;python_version<="3.4" -nose>=1.3.6 -pytest \ No newline at end of file +pytest diff --git a/setup.py b/setup.py index 6760770e..218625e1 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ setup( name = 'gocardless_pro', - version = '1.46.1', + version = '1.46.2', packages = find_packages(exclude=['tests']), install_requires = ['requests>=2.6', 'six'], author = 'GoCardless', diff --git a/tests/api_client_test.py b/tests/api_client_test.py index 11b6059c..d0f552d6 100644 --- a/tests/api_client_test.py +++ b/tests/api_client_test.py @@ -5,9 +5,9 @@ import json +import pytest import requests import responses -from nose.tools import assert_equals, assert_in, assert_raises from gocardless_pro import api_client from gocardless_pro import errors @@ -26,38 +26,37 @@ def test_uses_correct_url(): def test_authorization_header_present(): responses.add(responses.GET, 'http://example.com/test', body='{}') client.get('/test') - assert_equals(responses.calls[0].request.headers['authorization'], - 'Bearer ' + access_token) + assert responses.calls[0].request.headers['authorization'] == f'Bearer {access_token}' @responses.activate def test_includes_custom_header(): responses.add(responses.GET, 'http://example.com/test', body='{}') client.get('/test', headers={'Accept-Language': 'fr'}) - assert_equals(responses.calls[0].request.headers['accept-language'], 'fr') + assert responses.calls[0].request.headers['accept-language'] == 'fr' @responses.activate def test_includes_query_params(): responses.add(responses.GET, 'http://example.com/test', body='{}') client.get('/test', params={'page': '1'}) - assert_in('?page=1', responses.calls[0].request.url) + assert '?page=1' in responses.calls[0].request.url @responses.activate def test_post_includes_json_body(): responses.add(responses.POST, 'http://example.com/test', body='{}') client.post('/test', body={'name': 'Billy Jean'}) - assert_equals(responses.calls[0].request.body, '{"name": "Billy Jean"}') + assert responses.calls[0].request.body == '{"name": "Billy Jean"}' @responses.activate def test_put_includes_json_body(): responses.add(responses.PUT, 'http://example.com/test', body='{}') client.put('/test', body={'name': 'Billy Jean'}) - assert_equals(responses.calls[0].request.body, '{"name": "Billy Jean"}') + assert responses.calls[0].request.body == '{"name": "Billy Jean"}' @responses.activate def test_delete_includes_json_body(): responses.add(responses.DELETE, 'http://example.com/test', body='{}') client.delete('/test', body={'name': 'Billy Jean'}) - assert_equals(responses.calls[0].request.body, '{"name": "Billy Jean"}') + assert responses.calls[0].request.body == '{"name": "Billy Jean"}' @responses.activate def test_handles_validation_failed_error(): @@ -65,12 +64,11 @@ def test_handles_validation_failed_error(): responses.add(responses.POST, 'http://example.com/test', body=json.dumps(fixture), status=fixture['error']['code']) - with assert_raises(errors.ValidationFailedError) as assertion: + with pytest.raises(errors.ValidationFailedError) as exception: client.post('/test', body={'name': 'Billy Jean'}) - assert_equals(assertion.exception.documentation_url, - fixture['error']['documentation_url']) - assert_equals(assertion.exception.errors, fixture['error']['errors']) + assert exception.value.documentation_url == fixture['error']['documentation_url'] + assert exception.value.errors == fixture['error']['errors'] @responses.activate def test_handles_invalid_api_usage_error(): @@ -78,11 +76,11 @@ def test_handles_invalid_api_usage_error(): responses.add(responses.POST, 'http://example.com/test', body=json.dumps(fixture), status=fixture['error']['code']) - with assert_raises(errors.InvalidApiUsageError) as assertion: + with pytest.raises(errors.InvalidApiUsageError) as exception: client.post('/test', body={'name': 'Billy Jean'}) - assert_equals(assertion.exception.code, fixture['error']['code']) - assert_equals(assertion.exception.errors, fixture['error']['errors']) + assert exception.value.code == fixture['error']['code'] + assert exception.value.errors == fixture['error']['errors'] @responses.activate def test_handles_invalid_state_error(): @@ -90,11 +88,11 @@ def test_handles_invalid_state_error(): responses.add(responses.POST, 'http://example.com/test', body=json.dumps(fixture), status=fixture['error']['code']) - with assert_raises(errors.InvalidStateError) as assertion: + with pytest.raises(errors.InvalidStateError) as exception: client.post('/test', body={'name': 'Billy Jean'}) - assert_equals(assertion.exception.message, fixture['error']['message']) - assert_equals(assertion.exception.errors, fixture['error']['errors']) + assert exception.value.message == fixture['error']['message'] + assert exception.value.errors == fixture['error']['errors'] @responses.activate def test_handles_idempotent_creation_conflict_error(): @@ -102,12 +100,11 @@ def test_handles_idempotent_creation_conflict_error(): responses.add(responses.POST, 'http://example.com/test', body=json.dumps(fixture), status=fixture['error']['code']) - with assert_raises(errors.IdempotentCreationConflictError) as assertion: + with pytest.raises(errors.IdempotentCreationConflictError) as exception: client.post('/test', body={'name': 'Billy Jean'}) - assert_equals(assertion.exception.errors, fixture['error']['errors']) - assert_equals(assertion.exception.conflicting_resource_id, - fixture['error']['errors'][0]['links']['conflicting_resource_id']) + assert exception.value.errors == fixture['error']['errors'] + assert exception.value.conflicting_resource_id == fixture['error']['errors'][0]['links']['conflicting_resource_id'] @responses.activate def test_handles_gocardless_error(): @@ -115,30 +112,30 @@ def test_handles_gocardless_error(): responses.add(responses.POST, 'http://example.com/test', body=json.dumps(fixture), status=fixture['error']['code']) - with assert_raises(errors.GoCardlessInternalError) as assertion: + with pytest.raises(errors.GoCardlessInternalError) as exception: client.post('/test', body={'name': 'Billy Jean'}) - assert_equals(assertion.exception.type, fixture['error']['type']) - assert_equals(assertion.exception.request_id, fixture['error']['request_id']) + assert exception.value.type == fixture['error']['type'] + assert exception.value.request_id == fixture['error']['request_id'] @responses.activate def test_handles_malformed_response(): responses.add(responses.POST, 'http://example.com/test', body='not valid json...', status=200) - with assert_raises(errors.MalformedResponseError) as assertion: + with pytest.raises(errors.MalformedResponseError): client.post('/test', body={'name': 'Billy Jean'}) @responses.activate def test_handles_valid_empty_response(): responses.add(responses.DELETE, 'http://example.com/test', body='', status=204) client.delete('/test', body={'name': 'Billy Jean'}) - assert_equals(responses.calls[0].request.body, '{"name": "Billy Jean"}') + assert responses.calls[0].request.body == '{"name": "Billy Jean"}' @responses.activate def test_handles_invalid_empty_response(): responses.add(responses.POST, 'http://example.com/test', body='', status=201) - with assert_raises(errors.MalformedResponseError) as assertion: + with pytest.raises(errors.MalformedResponseError): client.post('/test', body={'name': 'Billy Jean'}) diff --git a/tests/client_test.py b/tests/client_test.py new file mode 100644 index 00000000..e4b7b062 --- /dev/null +++ b/tests/client_test.py @@ -0,0 +1,116 @@ +# WARNING: Do not edit by hand, this file was generated by Crank: +# +# https://github.com/gocardless/crank +# + +import pytest +import requests +import responses + +from gocardless_pro import Client +from gocardless_pro import services + +access_token = 'access-token-xyz' +client = Client(access_token=access_token, base_url='http://example.com') + +def test_requires_valid_environment(): + with pytest.raises(ValueError): + Client(access_token=access_token, environment='invalid') + + +def test_bank_authorisations_returns_service(): + assert isinstance(client.bank_authorisations, services.BankAuthorisationsService) + +def test_bank_details_lookups_returns_service(): + assert isinstance(client.bank_details_lookups, services.BankDetailsLookupsService) + +def test_billing_requests_returns_service(): + assert isinstance(client.billing_requests, services.BillingRequestsService) + +def test_billing_request_flows_returns_service(): + assert isinstance(client.billing_request_flows, services.BillingRequestFlowsService) + +def test_billing_request_templates_returns_service(): + assert isinstance(client.billing_request_templates, services.BillingRequestTemplatesService) + +def test_blocks_returns_service(): + assert isinstance(client.blocks, services.BlocksService) + +def test_creditors_returns_service(): + assert isinstance(client.creditors, services.CreditorsService) + +def test_creditor_bank_accounts_returns_service(): + assert isinstance(client.creditor_bank_accounts, services.CreditorBankAccountsService) + +def test_currency_exchange_rates_returns_service(): + assert isinstance(client.currency_exchange_rates, services.CurrencyExchangeRatesService) + +def test_customers_returns_service(): + assert isinstance(client.customers, services.CustomersService) + +def test_customer_bank_accounts_returns_service(): + assert isinstance(client.customer_bank_accounts, services.CustomerBankAccountsService) + +def test_customer_notifications_returns_service(): + assert isinstance(client.customer_notifications, services.CustomerNotificationsService) + +def test_events_returns_service(): + assert isinstance(client.events, services.EventsService) + +def test_instalment_schedules_returns_service(): + assert isinstance(client.instalment_schedules, services.InstalmentSchedulesService) + +def test_institutions_returns_service(): + assert isinstance(client.institutions, services.InstitutionsService) + +def test_mandates_returns_service(): + assert isinstance(client.mandates, services.MandatesService) + +def test_mandate_imports_returns_service(): + assert isinstance(client.mandate_imports, services.MandateImportsService) + +def test_mandate_import_entries_returns_service(): + assert isinstance(client.mandate_import_entries, services.MandateImportEntriesService) + +def test_mandate_pdfs_returns_service(): + assert isinstance(client.mandate_pdfs, services.MandatePdfsService) + +def test_negative_balance_limits_returns_service(): + assert isinstance(client.negative_balance_limits, services.NegativeBalanceLimitsService) + +def test_payer_authorisations_returns_service(): + assert isinstance(client.payer_authorisations, services.PayerAuthorisationsService) + +def test_payments_returns_service(): + assert isinstance(client.payments, services.PaymentsService) + +def test_payouts_returns_service(): + assert isinstance(client.payouts, services.PayoutsService) + +def test_payout_items_returns_service(): + assert isinstance(client.payout_items, services.PayoutItemsService) + +def test_redirect_flows_returns_service(): + assert isinstance(client.redirect_flows, services.RedirectFlowsService) + +def test_refunds_returns_service(): + assert isinstance(client.refunds, services.RefundsService) + +def test_scenario_simulators_returns_service(): + assert isinstance(client.scenario_simulators, services.ScenarioSimulatorsService) + +def test_scheme_identifiers_returns_service(): + assert isinstance(client.scheme_identifiers, services.SchemeIdentifiersService) + +def test_subscriptions_returns_service(): + assert isinstance(client.subscriptions, services.SubscriptionsService) + +def test_tax_rates_returns_service(): + assert isinstance(client.tax_rates, services.TaxRatesService) + +def test_verification_details_returns_service(): + assert isinstance(client.verification_details, services.VerificationDetailsService) + +def test_webhooks_returns_service(): + assert isinstance(client.webhooks, services.WebhooksService) + diff --git a/tests/error_test.py b/tests/error_test.py new file mode 100644 index 00000000..bbeade09 --- /dev/null +++ b/tests/error_test.py @@ -0,0 +1,61 @@ +# WARNING: Do not edit by hand, this file was generated by Crank: +# +# https://github.com/gocardless/crank +# + +from gocardless_pro import errors + +from . import helpers + +def test_invalid_state_error_message(): + fixture = helpers.load_fixture('invalid_state_error') + response_errors = fixture.get('error').get('errors', []) + error = errors.ApiError.exception_for(fixture['error']['code'],fixture['error']['type'], response_errors) + assert errors.InvalidStateError == error + error = error(fixture['error']) + assert str(error) == 'Mandate is already active or being submitted' + +def test_invalid_api_usage_message(): + fixture = helpers.load_fixture('invalid_api_usage_error') + response_errors = fixture.get('error').get('errors', []) + error = errors.ApiError.exception_for(fixture['error']['code'],fixture['error']['type'], response_errors) + assert errors.InvalidApiUsageError == error + error = error(fixture['error']) + assert str(error) == 'Invalid document structure (Root element must be an object.)' + +def test_validation_failed_message(): + fixture = helpers.load_fixture('validation_failed_error') + response_errors = fixture.get('error').get('errors', []) + error = errors.ApiError.exception_for(fixture['error']['code'],fixture['error']['type'], response_errors) + assert errors.ValidationFailedError == error + error = error(fixture['error']) + + branch_error = 'branch_code must be a number /customer_bank_accounts/branch_code' + country_error = 'country_code is invalid /customer_bank_accounts/country_code' + + expected = f'Validation failed ({branch_error}, {country_error})' + assert str(error) == expected + +def test_validation_failed_duplicate_bank_account_message(): + fixture = helpers.load_fixture('validation_failed_duplicate_bank_account_error') + response_errors = fixture.get('error').get('errors', []) + error = errors.ApiError.exception_for(fixture['error']['code'],fixture['error']['type'], response_errors) + assert errors.ValidationFailedError == error + error = error(fixture['error']) + assert str(error) == 'Bank account already exists' + +def test_gocardless_error_message(): + fixture = helpers.load_fixture('gocardless_error') + response_errors = fixture.get('error').get('errors', []) + error = errors.ApiError.exception_for(fixture['error']['code'],fixture['error']['type'], response_errors) + assert errors.GoCardlessInternalError == error + error = error(fixture['error']) + assert str(error) == 'Uh-oh!' + +def test_idempotent_creation_conflict_error_message(): + fixture = helpers.idempotent_creation_conflict_body('PM00001078ZJJN') + error = errors.ApiError.exception_for(fixture['error']['code'],fixture['error']['type'], fixture['error']['errors']) + assert errors.IdempotentCreationConflictError == error + error = error(fixture['error']) + assert str(error) == 'None (A resource has already been created with this idempotency key)' + assert error.conflicting_resource_id == "PM00001078ZJJN" diff --git a/tests/fixtures/bank_authorisations.json b/tests/fixtures/bank_authorisations.json index 105faba8..3efd094f 100644 --- a/tests/fixtures/bank_authorisations.json +++ b/tests/fixtures/bank_authorisations.json @@ -3,12 +3,12 @@ "method": "POST", "path_template": "/bank_authorisations", "url_params": [], - "body": {"bank_authorisations":{"authorisation_type":"example authorisation_type 8081","authorised_at":"2020-01-01T12:00:00.000Z","created_at":"2023-09-19T09:24:12.824Z","expires_at":"2023-09-19T09:24:12.824Z","id":"BAU123","last_visited_at":"2020-01-01T12:00:00.000Z","links":{"billing_request":"BRQ123","institution":"monzo"},"qr_code_url":"https://pay.gocardless.com/obauth/BAU123/qr_code","redirect_uri":"https://my-website.com/abc/callback","url":"https://pay.gocardless.com/obauth/BAU123"}} + "body": {"bank_authorisations":{"authorisation_type":"example authorisation_type 8081","authorised_at":"2020-01-01T12:00:00.000Z","created_at":"2023-09-19T14:17:04.929Z","expires_at":"2023-09-19T14:17:04.929Z","id":"BAU123","last_visited_at":"2020-01-01T12:00:00.000Z","links":{"billing_request":"BRQ123","institution":"monzo"},"qr_code_url":"https://pay.gocardless.com/obauth/BAU123/qr_code","redirect_uri":"https://my-website.com/abc/callback","url":"https://pay.gocardless.com/obauth/BAU123"}} }, "get": { "method": "GET", "path_template": "/bank_authorisations/:identity", "url_params": ["BAU123"], - "body": {"bank_authorisations":{"authorisation_type":"example authorisation_type 7887","authorised_at":"2020-01-01T12:00:00.000Z","created_at":"2023-09-19T09:24:12.824Z","expires_at":"2023-09-19T09:24:12.824Z","id":"BAU123","last_visited_at":"2020-01-01T12:00:00.000Z","links":{"billing_request":"BRQ123","institution":"monzo"},"qr_code_url":"https://pay.gocardless.com/obauth/BAU123/qr_code","redirect_uri":"https://my-website.com/abc/callback","url":"https://pay.gocardless.com/obauth/BAU123"}} + "body": {"bank_authorisations":{"authorisation_type":"example authorisation_type 7887","authorised_at":"2020-01-01T12:00:00.000Z","created_at":"2023-09-19T14:17:04.929Z","expires_at":"2023-09-19T14:17:04.929Z","id":"BAU123","last_visited_at":"2020-01-01T12:00:00.000Z","links":{"billing_request":"BRQ123","institution":"monzo"},"qr_code_url":"https://pay.gocardless.com/obauth/BAU123/qr_code","redirect_uri":"https://my-website.com/abc/callback","url":"https://pay.gocardless.com/obauth/BAU123"}} } } diff --git a/tests/fixtures/billing_request_flows.json b/tests/fixtures/billing_request_flows.json index 81e16b42..7fa798da 100644 --- a/tests/fixtures/billing_request_flows.json +++ b/tests/fixtures/billing_request_flows.json @@ -3,12 +3,12 @@ "method": "POST", "path_template": "/billing_request_flows", "url_params": [], - "body": {"billing_request_flows":{"authorisation_url":"https://monzo.com/abc-123-things","auto_fulfil":false,"created_at":"2023-09-19T09:24:12.828Z","exit_uri":"https://my-website.com/abc/callback","expires_at":"2023-09-19T09:24:12.828Z","id":"BRF123","language":"en","links":{"billing_request":"BRQ123"},"lock_bank_account":false,"lock_currency":false,"lock_customer_details":true,"prefilled_bank_account":{"account_type":"savings"},"prefilled_customer":{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","city":"London","company_name":"Hamilton Trading Ltd.","country_code":"GB","danish_identity_number":"220550-6218","email":"user@example.com","family_name":"Osborne","given_name":"Frank","postal_code":"NW1 6XE","region":"Greater London","swedish_identity_number":"556564-5404"},"redirect_uri":"https://my-website.com/abc/callback","session_token":"sesh_123","show_redirect_buttons":false,"show_success_redirect_button":true}} + "body": {"billing_request_flows":{"authorisation_url":"https://monzo.com/abc-123-things","auto_fulfil":false,"created_at":"2023-09-19T14:17:04.934Z","exit_uri":"https://my-website.com/abc/callback","expires_at":"2023-09-19T14:17:04.934Z","id":"BRF123","language":"en","links":{"billing_request":"BRQ123"},"lock_bank_account":false,"lock_currency":true,"lock_customer_details":false,"prefilled_bank_account":{"account_type":"savings"},"prefilled_customer":{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","city":"London","company_name":"Hamilton Trading Ltd.","country_code":"GB","danish_identity_number":"220550-6218","email":"user@example.com","family_name":"Osborne","given_name":"Frank","postal_code":"NW1 6XE","region":"Greater London","swedish_identity_number":"556564-5404"},"redirect_uri":"https://my-website.com/abc/callback","session_token":"sesh_123","show_redirect_buttons":true,"show_success_redirect_button":false}} }, "initialise": { "method": "POST", "path_template": "/billing_request_flows/:identity/actions/initialise", "url_params": ["BRF123"], - "body": {"billing_request_flows":{"authorisation_url":"https://monzo.com/abc-123-things","auto_fulfil":true,"created_at":"2023-09-19T09:24:12.828Z","exit_uri":"https://my-website.com/abc/callback","expires_at":"2023-09-19T09:24:12.828Z","id":"BRF123","language":"en","links":{"billing_request":"BRQ123"},"lock_bank_account":true,"lock_currency":false,"lock_customer_details":false,"prefilled_bank_account":{"account_type":"savings"},"prefilled_customer":{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","city":"London","company_name":"Hamilton Trading Ltd.","country_code":"GB","danish_identity_number":"220550-6218","email":"user@example.com","family_name":"Osborne","given_name":"Frank","postal_code":"NW1 6XE","region":"Greater London","swedish_identity_number":"556564-5404"},"redirect_uri":"https://my-website.com/abc/callback","session_token":"sesh_123","show_redirect_buttons":true,"show_success_redirect_button":false}} + "body": {"billing_request_flows":{"authorisation_url":"https://monzo.com/abc-123-things","auto_fulfil":true,"created_at":"2023-09-19T14:17:04.934Z","exit_uri":"https://my-website.com/abc/callback","expires_at":"2023-09-19T14:17:04.934Z","id":"BRF123","language":"en","links":{"billing_request":"BRQ123"},"lock_bank_account":true,"lock_currency":false,"lock_customer_details":false,"prefilled_bank_account":{"account_type":"savings"},"prefilled_customer":{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","city":"London","company_name":"Hamilton Trading Ltd.","country_code":"GB","danish_identity_number":"220550-6218","email":"user@example.com","family_name":"Osborne","given_name":"Frank","postal_code":"NW1 6XE","region":"Greater London","swedish_identity_number":"556564-5404"},"redirect_uri":"https://my-website.com/abc/callback","session_token":"sesh_123","show_redirect_buttons":true,"show_success_redirect_button":false}} } } diff --git a/tests/fixtures/billing_requests.json b/tests/fixtures/billing_requests.json index 0aabba0a..3c5a6f2f 100644 --- a/tests/fixtures/billing_requests.json +++ b/tests/fixtures/billing_requests.json @@ -3,72 +3,72 @@ "method": "POST", "path_template": "/billing_requests", "url_params": [], - "body": {"billing_requests":{"actions":[{"available_currencies":["example available_currencies 495"],"bank_authorisation":{"adapter":"example adapter 5466","authorisation_type":"example authorisation_type 1528"},"collect_customer_details":{"default_country_code":"example default_country_code 1445","incomplete_fields":{"customer":["example customer 3237"],"customer_billing_detail":["example customer_billing_detail 9106"]}},"completes_actions":["collect_bank_account"],"institution_guess_status":"pending","required":true,"requires_actions":["collect_bank_account"],"status":"pending","type":"collect_bank_details"}],"created_at":"2015-01-01T12:00:00.000Z","fallback_enabled":false,"id":"BRQ123","links":{"bank_authorisation":"example bank_authorisation 4728","creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","customer_billing_detail":"example customer_billing_detail 3274","mandate_request":"MRQ123","mandate_request_mandate":"MD123","organisation":"OR123","payment_request":"PRQ123","payment_request_payment":"PM123"},"mandate_request":{"authorisation_source":"web","constraints":{"end_date":"example end_date 1318","max_amount_per_payment":4425,"periodic_limits":[{"alignment":"calendar","max_payments":2540,"max_total_amount":694,"period":"day"}],"start_date":"example start_date 8511"},"currency":"GBP","description":"Top-up Payment","links":{"mandate":"example mandate 2081"},"metadata":{},"scheme":"bacs","verify":"recommended"},"metadata":{},"payment_request":{"amount":1000,"app_fee":100,"currency":"GBP","description":"Top-up Payment","links":{"payment":"example payment 6258"},"metadata":{},"scheme":"faster_payments"},"purpose_code":"dependant_support","resources":{"customer":{"company_name":"Hamilton Trading Ltd.","created_at":"2014-01-01T12:00:00.000Z","email":"user@example.com","family_name":"Osborne","given_name":"Frank","id":"CU123","language":"en","metadata":{},"phone_number":"+64 4 817 9999"},"customer_bank_account":{"account_holder_name":"Billie Jean","account_number_ending":"1234","account_type":"savings","bank_name":"BARCLAYS BANK PLC","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","enabled":true,"id":"BA123","links":{"customer":"example customer 4059"},"metadata":{}},"customer_billing_detail":{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","city":"London","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","danish_identity_number":"220550-6218","id":"CU123","ip_address":"127.0.0.1","postal_code":"NW1 6XE","region":"Greater London","schemes":["example schemes 1847"],"swedish_identity_number":"556564-5404"}},"status":"pending"}} + "body": {"billing_requests":{"actions":[{"available_currencies":["example available_currencies 8047"],"bank_authorisation":{"adapter":"example adapter 9106","authorisation_type":"example authorisation_type 495"},"collect_customer_details":{"default_country_code":"example default_country_code 5466","incomplete_fields":{"customer":["example customer 1528"],"customer_billing_detail":["example customer_billing_detail 6258"]}},"completes_actions":["collect_bank_account"],"institution_guess_status":"pending","required":true,"requires_actions":["collect_bank_account"],"status":"pending","type":"collect_bank_details"}],"created_at":"2015-01-01T12:00:00.000Z","fallback_enabled":false,"id":"BRQ123","links":{"bank_authorisation":"example bank_authorisation 2081","creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","customer_billing_detail":"example customer_billing_detail 1318","mandate_request":"MRQ123","mandate_request_mandate":"MD123","organisation":"OR123","payment_request":"PRQ123","payment_request_payment":"PM123"},"mandate_request":{"authorisation_source":"paper","constraints":{"end_date":"example end_date 694","max_amount_per_payment":8511,"periodic_limits":[{"alignment":"calendar","max_payments":3274,"max_total_amount":4728,"period":"flexible"}],"start_date":"example start_date 1211"},"currency":"GBP","description":"Top-up Payment","links":{"mandate":"example mandate 3300"},"metadata":{},"scheme":"bacs","verify":"minimum"},"metadata":{},"payment_request":{"amount":1000,"app_fee":100,"currency":"GBP","description":"Top-up Payment","links":{"payment":"example payment 3237"},"metadata":{},"scheme":"faster_payments"},"purpose_code":"government","resources":{"customer":{"company_name":"Hamilton Trading Ltd.","created_at":"2014-01-01T12:00:00.000Z","email":"user@example.com","family_name":"Osborne","given_name":"Frank","id":"CU123","language":"en","metadata":{},"phone_number":"+64 4 817 9999"},"customer_bank_account":{"account_holder_name":"Billie Jean","account_number_ending":"1234","account_type":"savings","bank_name":"BARCLAYS BANK PLC","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","enabled":true,"id":"BA123","links":{"customer":"example customer 4059"},"metadata":{}},"customer_billing_detail":{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","city":"London","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","danish_identity_number":"220550-6218","id":"CU123","ip_address":"127.0.0.1","postal_code":"NW1 6XE","region":"Greater London","schemes":["example schemes 1847"],"swedish_identity_number":"556564-5404"}},"status":"pending"}} }, "collect_customer_details": { "method": "POST", "path_template": "/billing_requests/:identity/actions/collect_customer_details", "url_params": ["BRQ123"], - "body": {"billing_requests":{"actions":[{"available_currencies":["example available_currencies 3015"],"bank_authorisation":{"adapter":"example adapter 5541","authorisation_type":"example authorisation_type 408"},"collect_customer_details":{"default_country_code":"example default_country_code 8287","incomplete_fields":{"customer":["example customer 2888"],"customer_billing_detail":["example customer_billing_detail 2790"]}},"completes_actions":["collect_bank_account"],"institution_guess_status":"pending","required":true,"requires_actions":["collect_bank_account"],"status":"pending","type":"collect_bank_details"}],"created_at":"2015-01-01T12:00:00.000Z","fallback_enabled":true,"id":"BRQ123","links":{"bank_authorisation":"example bank_authorisation 7387","creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","customer_billing_detail":"example customer_billing_detail 6831","mandate_request":"MRQ123","mandate_request_mandate":"MD123","organisation":"OR123","payment_request":"PRQ123","payment_request_payment":"PM123"},"mandate_request":{"authorisation_source":"telephone","constraints":{"end_date":"example end_date 631","max_amount_per_payment":1485,"periodic_limits":[{"alignment":"calendar","max_payments":5194,"max_total_amount":3090,"period":"year"}],"start_date":"example start_date 563"},"currency":"GBP","description":"Top-up Payment","links":{"mandate":"example mandate 1737"},"metadata":{},"scheme":"bacs","verify":"minimum"},"metadata":{},"payment_request":{"amount":1000,"app_fee":100,"currency":"GBP","description":"Top-up Payment","links":{"payment":"example payment 9947"},"metadata":{},"scheme":"faster_payments"},"purpose_code":"pension","resources":{"customer":{"company_name":"Hamilton Trading Ltd.","created_at":"2014-01-01T12:00:00.000Z","email":"user@example.com","family_name":"Osborne","given_name":"Frank","id":"CU123","language":"en","metadata":{},"phone_number":"+64 4 817 9999"},"customer_bank_account":{"account_holder_name":"Billie Jean","account_number_ending":"1234","account_type":"savings","bank_name":"BARCLAYS BANK PLC","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","enabled":true,"id":"BA123","links":{"customer":"example customer 4324"},"metadata":{}},"customer_billing_detail":{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","city":"London","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","danish_identity_number":"220550-6218","id":"CU123","ip_address":"127.0.0.1","postal_code":"NW1 6XE","region":"Greater London","schemes":["example schemes 4078"],"swedish_identity_number":"556564-5404"}},"status":"pending"}} + "body": {"billing_requests":{"actions":[{"available_currencies":["example available_currencies 563"],"bank_authorisation":{"adapter":"example adapter 1485","authorisation_type":"example authorisation_type 5026"},"collect_customer_details":{"default_country_code":"example default_country_code 6413","incomplete_fields":{"customer":["example customer 3090"],"customer_billing_detail":["example customer_billing_detail 5194"]}},"completes_actions":["collect_bank_account"],"institution_guess_status":"pending","required":true,"requires_actions":["collect_bank_account"],"status":"pending","type":"collect_bank_details"}],"created_at":"2015-01-01T12:00:00.000Z","fallback_enabled":false,"id":"BRQ123","links":{"bank_authorisation":"example bank_authorisation 9947","creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","customer_billing_detail":"example customer_billing_detail 8287","mandate_request":"MRQ123","mandate_request_mandate":"MD123","organisation":"OR123","payment_request":"PRQ123","payment_request_payment":"PM123"},"mandate_request":{"authorisation_source":"telephone","constraints":{"end_date":"example end_date 408","max_amount_per_payment":7387,"periodic_limits":[{"alignment":"creation_date","max_payments":5356,"max_total_amount":5429,"period":"week"}],"start_date":"example start_date 5541"},"currency":"GBP","description":"Top-up Payment","links":{"mandate":"example mandate 3015"},"metadata":{},"scheme":"bacs","verify":"when_available"},"metadata":{},"payment_request":{"amount":1000,"app_fee":100,"currency":"GBP","description":"Top-up Payment","links":{"payment":"example payment 4147"},"metadata":{},"scheme":"faster_payments"},"purpose_code":"utility","resources":{"customer":{"company_name":"Hamilton Trading Ltd.","created_at":"2014-01-01T12:00:00.000Z","email":"user@example.com","family_name":"Osborne","given_name":"Frank","id":"CU123","language":"en","metadata":{},"phone_number":"+64 4 817 9999"},"customer_bank_account":{"account_holder_name":"Billie Jean","account_number_ending":"1234","account_type":"savings","bank_name":"BARCLAYS BANK PLC","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","enabled":true,"id":"BA123","links":{"customer":"example customer 4324"},"metadata":{}},"customer_billing_detail":{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","city":"London","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","danish_identity_number":"220550-6218","id":"CU123","ip_address":"127.0.0.1","postal_code":"NW1 6XE","region":"Greater London","schemes":["example schemes 4078"],"swedish_identity_number":"556564-5404"}},"status":"pending"}} }, "collect_bank_account": { "method": "POST", "path_template": "/billing_requests/:identity/actions/collect_bank_account", "url_params": ["BRQ123"], - "body": {"billing_requests":{"actions":[{"available_currencies":["example available_currencies 2199"],"bank_authorisation":{"adapter":"example adapter 6159","authorisation_type":"example authorisation_type 1353"},"collect_customer_details":{"default_country_code":"example default_country_code 1957","incomplete_fields":{"customer":["example customer 3721"],"customer_billing_detail":["example customer_billing_detail 7189"]}},"completes_actions":["collect_bank_account"],"institution_guess_status":"pending","required":true,"requires_actions":["collect_bank_account"],"status":"pending","type":"collect_bank_details"}],"created_at":"2015-01-01T12:00:00.000Z","fallback_enabled":false,"id":"BRQ123","links":{"bank_authorisation":"example bank_authorisation 4783","creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","customer_billing_detail":"example customer_billing_detail 5746","mandate_request":"MRQ123","mandate_request_mandate":"MD123","organisation":"OR123","payment_request":"PRQ123","payment_request_payment":"PM123"},"mandate_request":{"authorisation_source":"telephone","constraints":{"end_date":"example end_date 8266","max_amount_per_payment":9703,"periodic_limits":[{"alignment":"creation_date","max_payments":8510,"max_total_amount":2451,"period":"day"}],"start_date":"example start_date 156"},"currency":"GBP","description":"Top-up Payment","links":{"mandate":"example mandate 4538"},"metadata":{},"scheme":"bacs","verify":"minimum"},"metadata":{},"payment_request":{"amount":1000,"app_fee":100,"currency":"GBP","description":"Top-up Payment","links":{"payment":"example payment 3000"},"metadata":{},"scheme":"faster_payments"},"purpose_code":"personal","resources":{"customer":{"company_name":"Hamilton Trading Ltd.","created_at":"2014-01-01T12:00:00.000Z","email":"user@example.com","family_name":"Osborne","given_name":"Frank","id":"CU123","language":"en","metadata":{},"phone_number":"+64 4 817 9999"},"customer_bank_account":{"account_holder_name":"Billie Jean","account_number_ending":"1234","account_type":"savings","bank_name":"BARCLAYS BANK PLC","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","enabled":true,"id":"BA123","links":{"customer":"example customer 5561"},"metadata":{}},"customer_billing_detail":{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","city":"London","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","danish_identity_number":"220550-6218","id":"CU123","ip_address":"127.0.0.1","postal_code":"NW1 6XE","region":"Greater London","schemes":["example schemes 7202"],"swedish_identity_number":"556564-5404"}},"status":"pending"}} + "body": {"billing_requests":{"actions":[{"available_currencies":["example available_currencies 8266"],"bank_authorisation":{"adapter":"example adapter 2605","authorisation_type":"example authorisation_type 156"},"collect_customer_details":{"default_country_code":"example default_country_code 9828","incomplete_fields":{"customer":["example customer 5561"],"customer_billing_detail":["example customer_billing_detail 7202"]}},"completes_actions":["collect_bank_account"],"institution_guess_status":"pending","required":true,"requires_actions":["collect_bank_account"],"status":"pending","type":"collect_bank_details"}],"created_at":"2015-01-01T12:00:00.000Z","fallback_enabled":false,"id":"BRQ123","links":{"bank_authorisation":"example bank_authorisation 1353","creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","customer_billing_detail":"example customer_billing_detail 6159","mandate_request":"MRQ123","mandate_request_mandate":"MD123","organisation":"OR123","payment_request":"PRQ123","payment_request_payment":"PM123"},"mandate_request":{"authorisation_source":"paper","constraints":{"end_date":"example end_date 2199","max_amount_per_payment":3000,"periodic_limits":[{"alignment":"creation_date","max_payments":4538,"max_total_amount":2888,"period":"day"}],"start_date":"example start_date 7189"},"currency":"GBP","description":"Top-up Payment","links":{"mandate":"example mandate 8510"},"metadata":{},"scheme":"bacs","verify":"always"},"metadata":{},"payment_request":{"amount":1000,"app_fee":100,"currency":"GBP","description":"Top-up Payment","links":{"payment":"example payment 1957"},"metadata":{},"scheme":"faster_payments"},"purpose_code":"personal","resources":{"customer":{"company_name":"Hamilton Trading Ltd.","created_at":"2014-01-01T12:00:00.000Z","email":"user@example.com","family_name":"Osborne","given_name":"Frank","id":"CU123","language":"en","metadata":{},"phone_number":"+64 4 817 9999"},"customer_bank_account":{"account_holder_name":"Billie Jean","account_number_ending":"1234","account_type":"savings","bank_name":"BARCLAYS BANK PLC","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","enabled":true,"id":"BA123","links":{"customer":"example customer 5746"},"metadata":{}},"customer_billing_detail":{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","city":"London","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","danish_identity_number":"220550-6218","id":"CU123","ip_address":"127.0.0.1","postal_code":"NW1 6XE","region":"Greater London","schemes":["example schemes 4783"],"swedish_identity_number":"556564-5404"}},"status":"pending"}} }, "confirm_payer_details": { "method": "POST", "path_template": "/billing_requests/:identity/actions/confirm_payer_details", "url_params": ["BRQ123"], - "body": {"billing_requests":{"actions":[{"available_currencies":["example available_currencies 5094"],"bank_authorisation":{"adapter":"example adapter 1577","authorisation_type":"example authorisation_type 7463"},"collect_customer_details":{"default_country_code":"example default_country_code 9002","incomplete_fields":{"customer":["example customer 9718"],"customer_billing_detail":["example customer_billing_detail 5447"]}},"completes_actions":["collect_bank_account"],"institution_guess_status":"pending","required":true,"requires_actions":["collect_bank_account"],"status":"pending","type":"collect_bank_details"}],"created_at":"2015-01-01T12:00:00.000Z","fallback_enabled":true,"id":"BRQ123","links":{"bank_authorisation":"example bank_authorisation 1137","creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","customer_billing_detail":"example customer_billing_detail 3133","mandate_request":"MRQ123","mandate_request_mandate":"MD123","organisation":"OR123","payment_request":"PRQ123","payment_request_payment":"PM123"},"mandate_request":{"authorisation_source":"telephone","constraints":{"end_date":"example end_date 59","max_amount_per_payment":3033,"periodic_limits":[{"alignment":"calendar","max_payments":2002,"max_total_amount":3891,"period":"year"}],"start_date":"example start_date 9241"},"currency":"GBP","description":"Top-up Payment","links":{"mandate":"example mandate 9107"},"metadata":{},"scheme":"bacs","verify":"when_available"},"metadata":{},"payment_request":{"amount":1000,"app_fee":100,"currency":"GBP","description":"Top-up Payment","links":{"payment":"example payment 7996"},"metadata":{},"scheme":"faster_payments"},"purpose_code":"mortgage","resources":{"customer":{"company_name":"Hamilton Trading Ltd.","created_at":"2014-01-01T12:00:00.000Z","email":"user@example.com","family_name":"Osborne","given_name":"Frank","id":"CU123","language":"en","metadata":{},"phone_number":"+64 4 817 9999"},"customer_bank_account":{"account_holder_name":"Billie Jean","account_number_ending":"1234","account_type":"savings","bank_name":"BARCLAYS BANK PLC","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","enabled":true,"id":"BA123","links":{"customer":"example customer 953"},"metadata":{}},"customer_billing_detail":{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","city":"London","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","danish_identity_number":"220550-6218","id":"CU123","ip_address":"127.0.0.1","postal_code":"NW1 6XE","region":"Greater London","schemes":["example schemes 8623"],"swedish_identity_number":"556564-5404"}},"status":"pending"}} + "body": {"billing_requests":{"actions":[{"available_currencies":["example available_currencies 5094"],"bank_authorisation":{"adapter":"example adapter 9718","authorisation_type":"example authorisation_type 5447"},"collect_customer_details":{"default_country_code":"example default_country_code 7996","incomplete_fields":{"customer":["example customer 1577"],"customer_billing_detail":["example customer_billing_detail 7463"]}},"completes_actions":["collect_bank_account"],"institution_guess_status":"pending","required":true,"requires_actions":["collect_bank_account"],"status":"pending","type":"collect_bank_details"}],"created_at":"2015-01-01T12:00:00.000Z","fallback_enabled":true,"id":"BRQ123","links":{"bank_authorisation":"example bank_authorisation 2546","creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","customer_billing_detail":"example customer_billing_detail 9336","mandate_request":"MRQ123","mandate_request_mandate":"MD123","organisation":"OR123","payment_request":"PRQ123","payment_request_payment":"PM123"},"mandate_request":{"authorisation_source":"paper","constraints":{"end_date":"example end_date 8623","max_amount_per_payment":953,"periodic_limits":[{"alignment":"creation_date","max_payments":9241,"max_total_amount":3133,"period":"month"}],"start_date":"example start_date 6420"},"currency":"GBP","description":"Top-up Payment","links":{"mandate":"example mandate 3891"},"metadata":{},"scheme":"bacs","verify":"always"},"metadata":{},"payment_request":{"amount":1000,"app_fee":100,"currency":"GBP","description":"Top-up Payment","links":{"payment":"example payment 9002"},"metadata":{},"scheme":"faster_payments"},"purpose_code":"mortgage","resources":{"customer":{"company_name":"Hamilton Trading Ltd.","created_at":"2014-01-01T12:00:00.000Z","email":"user@example.com","family_name":"Osborne","given_name":"Frank","id":"CU123","language":"en","metadata":{},"phone_number":"+64 4 817 9999"},"customer_bank_account":{"account_holder_name":"Billie Jean","account_number_ending":"1234","account_type":"savings","bank_name":"BARCLAYS BANK PLC","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","enabled":true,"id":"BA123","links":{"customer":"example customer 8878"},"metadata":{}},"customer_billing_detail":{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","city":"London","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","danish_identity_number":"220550-6218","id":"CU123","ip_address":"127.0.0.1","postal_code":"NW1 6XE","region":"Greater London","schemes":["example schemes 2002"],"swedish_identity_number":"556564-5404"}},"status":"pending"}} }, "fulfil": { "method": "POST", "path_template": "/billing_requests/:identity/actions/fulfil", "url_params": ["BRQ123"], - "body": {"billing_requests":{"actions":[{"available_currencies":["example available_currencies 3410"],"bank_authorisation":{"adapter":"example adapter 5285","authorisation_type":"example authorisation_type 8590"},"collect_customer_details":{"default_country_code":"example default_country_code 8553","incomplete_fields":{"customer":["example customer 3632"],"customer_billing_detail":["example customer_billing_detail 3098"]}},"completes_actions":["collect_bank_account"],"institution_guess_status":"pending","required":true,"requires_actions":["collect_bank_account"],"status":"pending","type":"collect_bank_details"}],"created_at":"2015-01-01T12:00:00.000Z","fallback_enabled":false,"id":"BRQ123","links":{"bank_authorisation":"example bank_authorisation 1297","creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","customer_billing_detail":"example customer_billing_detail 5384","mandate_request":"MRQ123","mandate_request_mandate":"MD123","organisation":"OR123","payment_request":"PRQ123","payment_request_payment":"PM123"},"mandate_request":{"authorisation_source":"telephone","constraints":{"end_date":"example end_date 1598","max_amount_per_payment":7425,"periodic_limits":[{"alignment":"creation_date","max_payments":1515,"max_total_amount":1351,"period":"month"}],"start_date":"example start_date 2205"},"currency":"GBP","description":"Top-up Payment","links":{"mandate":"example mandate 9843"},"metadata":{},"scheme":"bacs","verify":"minimum"},"metadata":{},"payment_request":{"amount":1000,"app_fee":100,"currency":"GBP","description":"Top-up Payment","links":{"payment":"example payment 8010"},"metadata":{},"scheme":"faster_payments"},"purpose_code":"other","resources":{"customer":{"company_name":"Hamilton Trading Ltd.","created_at":"2014-01-01T12:00:00.000Z","email":"user@example.com","family_name":"Osborne","given_name":"Frank","id":"CU123","language":"en","metadata":{},"phone_number":"+64 4 817 9999"},"customer_bank_account":{"account_holder_name":"Billie Jean","account_number_ending":"1234","account_type":"savings","bank_name":"BARCLAYS BANK PLC","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","enabled":true,"id":"BA123","links":{"customer":"example customer 8591"},"metadata":{}},"customer_billing_detail":{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","city":"London","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","danish_identity_number":"220550-6218","id":"CU123","ip_address":"127.0.0.1","postal_code":"NW1 6XE","region":"Greater London","schemes":["example schemes 8582"],"swedish_identity_number":"556564-5404"}},"status":"pending"}} + "body": {"billing_requests":{"actions":[{"available_currencies":["example available_currencies 8590"],"bank_authorisation":{"adapter":"example adapter 8591","authorisation_type":"example authorisation_type 8582"},"collect_customer_details":{"default_country_code":"example default_country_code 8553","incomplete_fields":{"customer":["example customer 3632"],"customer_billing_detail":["example customer_billing_detail 3098"]}},"completes_actions":["collect_bank_account"],"institution_guess_status":"pending","required":true,"requires_actions":["collect_bank_account"],"status":"pending","type":"collect_bank_details"}],"created_at":"2015-01-01T12:00:00.000Z","fallback_enabled":false,"id":"BRQ123","links":{"bank_authorisation":"example bank_authorisation 552","creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","customer_billing_detail":"example customer_billing_detail 6503","mandate_request":"MRQ123","mandate_request_mandate":"MD123","organisation":"OR123","payment_request":"PRQ123","payment_request_payment":"PM123"},"mandate_request":{"authorisation_source":"paper","constraints":{"end_date":"example end_date 1598","max_amount_per_payment":7425,"periodic_limits":[{"alignment":"creation_date","max_payments":3687,"max_total_amount":9757,"period":"day"}],"start_date":"example start_date 2205"},"currency":"GBP","description":"Top-up Payment","links":{"mandate":"example mandate 9843"},"metadata":{},"scheme":"bacs","verify":"when_available"},"metadata":{},"payment_request":{"amount":1000,"app_fee":100,"currency":"GBP","description":"Top-up Payment","links":{"payment":"example payment 5285"},"metadata":{},"scheme":"faster_payments"},"purpose_code":"other","resources":{"customer":{"company_name":"Hamilton Trading Ltd.","created_at":"2014-01-01T12:00:00.000Z","email":"user@example.com","family_name":"Osborne","given_name":"Frank","id":"CU123","language":"en","metadata":{},"phone_number":"+64 4 817 9999"},"customer_bank_account":{"account_holder_name":"Billie Jean","account_number_ending":"1234","account_type":"savings","bank_name":"BARCLAYS BANK PLC","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","enabled":true,"id":"BA123","links":{"customer":"example customer 5384"},"metadata":{}},"customer_billing_detail":{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","city":"London","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","danish_identity_number":"220550-6218","id":"CU123","ip_address":"127.0.0.1","postal_code":"NW1 6XE","region":"Greater London","schemes":["example schemes 1297"],"swedish_identity_number":"556564-5404"}},"status":"pending"}} }, "cancel": { "method": "POST", "path_template": "/billing_requests/:identity/actions/cancel", "url_params": ["BRQ123"], - "body": {"billing_requests":{"actions":[{"available_currencies":["example available_currencies 9819"],"bank_authorisation":{"adapter":"example adapter 6052","authorisation_type":"example authorisation_type 8981"},"collect_customer_details":{"default_country_code":"example default_country_code 7175","incomplete_fields":{"customer":["example customer 4885"],"customer_billing_detail":["example customer_billing_detail 5710"]}},"completes_actions":["collect_bank_account"],"institution_guess_status":"pending","required":true,"requires_actions":["collect_bank_account"],"status":"pending","type":"collect_bank_details"}],"created_at":"2015-01-01T12:00:00.000Z","fallback_enabled":true,"id":"BRQ123","links":{"bank_authorisation":"example bank_authorisation 1528","creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","customer_billing_detail":"example customer_billing_detail 2818","mandate_request":"MRQ123","mandate_request_mandate":"MD123","organisation":"OR123","payment_request":"PRQ123","payment_request_payment":"PM123"},"mandate_request":{"authorisation_source":"web","constraints":{"end_date":"example end_date 5894","max_amount_per_payment":7726,"periodic_limits":[{"alignment":"calendar","max_payments":2079,"max_total_amount":3981,"period":"month"}],"start_date":"example start_date 9271"},"currency":"GBP","description":"Top-up Payment","links":{"mandate":"example mandate 6137"},"metadata":{},"scheme":"bacs","verify":"recommended"},"metadata":{},"payment_request":{"amount":1000,"app_fee":100,"currency":"GBP","description":"Top-up Payment","links":{"payment":"example payment 4384"},"metadata":{},"scheme":"faster_payments"},"purpose_code":"tax","resources":{"customer":{"company_name":"Hamilton Trading Ltd.","created_at":"2014-01-01T12:00:00.000Z","email":"user@example.com","family_name":"Osborne","given_name":"Frank","id":"CU123","language":"en","metadata":{},"phone_number":"+64 4 817 9999"},"customer_bank_account":{"account_holder_name":"Billie Jean","account_number_ending":"1234","account_type":"savings","bank_name":"BARCLAYS BANK PLC","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","enabled":true,"id":"BA123","links":{"customer":"example customer 3749"},"metadata":{}},"customer_billing_detail":{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","city":"London","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","danish_identity_number":"220550-6218","id":"CU123","ip_address":"127.0.0.1","postal_code":"NW1 6XE","region":"Greater London","schemes":["example schemes 1387"],"swedish_identity_number":"556564-5404"}},"status":"pending"}} + "body": {"billing_requests":{"actions":[{"available_currencies":["example available_currencies 3749"],"bank_authorisation":{"adapter":"example adapter 6052","authorisation_type":"example authorisation_type 7175"},"collect_customer_details":{"default_country_code":"example default_country_code 4885","incomplete_fields":{"customer":["example customer 5710"],"customer_billing_detail":["example customer_billing_detail 1387"]}},"completes_actions":["collect_bank_account"],"institution_guess_status":"pending","required":true,"requires_actions":["collect_bank_account"],"status":"pending","type":"collect_bank_details"}],"created_at":"2015-01-01T12:00:00.000Z","fallback_enabled":true,"id":"BRQ123","links":{"bank_authorisation":"example bank_authorisation 7903","creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","customer_billing_detail":"example customer_billing_detail 4384","mandate_request":"MRQ123","mandate_request_mandate":"MD123","organisation":"OR123","payment_request":"PRQ123","payment_request_payment":"PM123"},"mandate_request":{"authorisation_source":"telephone","constraints":{"end_date":"example end_date 3086","max_amount_per_payment":5802,"periodic_limits":[{"alignment":"creation_date","max_payments":3981,"max_total_amount":1270,"period":"week"}],"start_date":"example start_date 493"},"currency":"GBP","description":"Top-up Payment","links":{"mandate":"example mandate 7726"},"metadata":{},"scheme":"bacs","verify":"when_available"},"metadata":{},"payment_request":{"amount":1000,"app_fee":100,"currency":"GBP","description":"Top-up Payment","links":{"payment":"example payment 8981"},"metadata":{},"scheme":"faster_payments"},"purpose_code":"utility","resources":{"customer":{"company_name":"Hamilton Trading Ltd.","created_at":"2014-01-01T12:00:00.000Z","email":"user@example.com","family_name":"Osborne","given_name":"Frank","id":"CU123","language":"en","metadata":{},"phone_number":"+64 4 817 9999"},"customer_bank_account":{"account_holder_name":"Billie Jean","account_number_ending":"1234","account_type":"savings","bank_name":"BARCLAYS BANK PLC","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","enabled":true,"id":"BA123","links":{"customer":"example customer 2818"},"metadata":{}},"customer_billing_detail":{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","city":"London","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","danish_identity_number":"220550-6218","id":"CU123","ip_address":"127.0.0.1","postal_code":"NW1 6XE","region":"Greater London","schemes":["example schemes 1528"],"swedish_identity_number":"556564-5404"}},"status":"pending"}} }, "list": { "method": "GET", "path_template": "/billing_requests", "url_params": [], - "body": {"billing_requests":[{"created_at":"2015-01-01T12:00:00.000Z","id":"BRQ123","links":{"bank_authorisation":"example bank_authorisation 7351","creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","customer_billing_detail":"example customer_billing_detail 8844","mandate_request":"MRQ123","mandate_request_mandate":"MD123","organisation":"OR123","payment_request":"PRQ123","payment_request_payment":"PM123"},"mandate_request":{"authorisation_source":"paper","constraints":{"end_date":"example end_date 4547","max_amount_per_payment":3612,"periodic_limits":[{"alignment":"calendar","max_payments":7839,"max_total_amount":3616,"period":"month"}],"start_date":"example start_date 1224"},"currency":"GBP","description":"Top-up Payment","links":{"mandate":"example mandate 8076"},"metadata":{},"scheme":"bacs","verify":"always"},"metadata":{},"payment_request":{"amount":1000,"app_fee":100,"currency":"GBP","description":"Top-up Payment","links":{"payment":"example payment 3640"},"metadata":{},"scheme":"faster_payments"},"status":"pending"},{"created_at":"2015-01-01T12:00:00.000Z","id":"BRQ123","links":{"bank_authorisation":"example bank_authorisation 1223","creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","customer_billing_detail":"example customer_billing_detail 7822","mandate_request":"MRQ123","mandate_request_mandate":"MD123","organisation":"OR123","payment_request":"PRQ123","payment_request_payment":"PM123"},"mandate_request":{"authorisation_source":"telephone","constraints":{"end_date":"example end_date 3231","max_amount_per_payment":9183,"periodic_limits":[{"alignment":"calendar","max_payments":90,"max_total_amount":4801,"period":"year"}],"start_date":"example start_date 3767"},"currency":"GBP","description":"Top-up Payment","links":{"mandate":"example mandate 2305"},"metadata":{},"scheme":"bacs","verify":"minimum"},"metadata":{},"payment_request":{"amount":1000,"app_fee":100,"currency":"GBP","description":"Top-up Payment","links":{"payment":"example payment 8154"},"metadata":{},"scheme":"faster_payments"},"status":"pending"}],"meta":{"cursors":{"after":"example after 7342","before":"example before 4208"},"limit":50}} + "body": {"billing_requests":[{"created_at":"2015-01-01T12:00:00.000Z","id":"BRQ123","links":{"bank_authorisation":"example bank_authorisation 3612","creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","customer_billing_detail":"example customer_billing_detail 4547","mandate_request":"MRQ123","mandate_request_mandate":"MD123","organisation":"OR123","payment_request":"PRQ123","payment_request_payment":"PM123"},"mandate_request":{"authorisation_source":"telephone","constraints":{"end_date":"example end_date 8076","max_amount_per_payment":1532,"periodic_limits":[{"alignment":"calendar","max_payments":540,"max_total_amount":7839,"period":"week"}],"start_date":"example start_date 7051"},"currency":"GBP","description":"Top-up Payment","links":{"mandate":"example mandate 8844"},"metadata":{},"scheme":"bacs","verify":"always"},"metadata":{},"payment_request":{"amount":1000,"app_fee":100,"currency":"GBP","description":"Top-up Payment","links":{"payment":"example payment 1224"},"metadata":{},"scheme":"faster_payments"},"status":"pending"},{"created_at":"2015-01-01T12:00:00.000Z","id":"BRQ123","links":{"bank_authorisation":"example bank_authorisation 9183","creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","customer_billing_detail":"example customer_billing_detail 2305","mandate_request":"MRQ123","mandate_request_mandate":"MD123","organisation":"OR123","payment_request":"PRQ123","payment_request_payment":"PM123"},"mandate_request":{"authorisation_source":"web","constraints":{"end_date":"example end_date 8154","max_amount_per_payment":7822,"periodic_limits":[{"alignment":"creation_date","max_payments":2258,"max_total_amount":1602,"period":"week"}],"start_date":"example start_date 7578"},"currency":"GBP","description":"Top-up Payment","links":{"mandate":"example mandate 90"},"metadata":{},"scheme":"bacs","verify":"recommended"},"metadata":{},"payment_request":{"amount":1000,"app_fee":100,"currency":"GBP","description":"Top-up Payment","links":{"payment":"example payment 364"},"metadata":{},"scheme":"faster_payments"},"status":"pending"}],"meta":{"cursors":{"after":"example after 4208","before":"example before 7342"},"limit":50}} }, "get": { "method": "GET", "path_template": "/billing_requests/:identity", "url_params": ["BRQ123"], - "body": {"billing_requests":{"actions":[{"available_currencies":["example available_currencies 4904"],"bank_authorisation":{"adapter":"example adapter 1166","authorisation_type":"example authorisation_type 1968"},"collect_customer_details":{"default_country_code":"example default_country_code 3710","incomplete_fields":{"customer":["example customer 4535"],"customer_billing_detail":["example customer_billing_detail 440"]}},"completes_actions":["collect_bank_account"],"institution_guess_status":"pending","required":true,"requires_actions":["collect_bank_account"],"status":"pending","type":"collect_bank_details"}],"created_at":"2015-01-01T12:00:00.000Z","fallback_enabled":false,"id":"BRQ123","links":{"bank_authorisation":"example bank_authorisation 2984","creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","customer_billing_detail":"example customer_billing_detail 870","mandate_request":"MRQ123","mandate_request_mandate":"MD123","organisation":"OR123","payment_request":"PRQ123","payment_request_payment":"PM123"},"mandate_request":{"authorisation_source":"paper","constraints":{"end_date":"example end_date 9700","max_amount_per_payment":1359,"periodic_limits":[{"alignment":"creation_date","max_payments":4415,"max_total_amount":3430,"period":"flexible"}],"start_date":"example start_date 9513"},"currency":"GBP","description":"Top-up Payment","links":{"mandate":"example mandate 4657"},"metadata":{},"scheme":"bacs","verify":"when_available"},"metadata":{},"payment_request":{"amount":1000,"app_fee":100,"currency":"GBP","description":"Top-up Payment","links":{"payment":"example payment 783"},"metadata":{},"scheme":"faster_payments"},"purpose_code":"personal","resources":{"customer":{"company_name":"Hamilton Trading Ltd.","created_at":"2014-01-01T12:00:00.000Z","email":"user@example.com","family_name":"Osborne","given_name":"Frank","id":"CU123","language":"en","metadata":{},"phone_number":"+64 4 817 9999"},"customer_bank_account":{"account_holder_name":"Billie Jean","account_number_ending":"1234","account_type":"savings","bank_name":"BARCLAYS BANK PLC","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","enabled":true,"id":"BA123","links":{"customer":"example customer 565"},"metadata":{}},"customer_billing_detail":{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","city":"London","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","danish_identity_number":"220550-6218","id":"CU123","ip_address":"127.0.0.1","postal_code":"NW1 6XE","region":"Greater London","schemes":["example schemes 8010"],"swedish_identity_number":"556564-5404"}},"status":"pending"}} + "body": {"billing_requests":{"actions":[{"available_currencies":["example available_currencies 783"],"bank_authorisation":{"adapter":"example adapter 6720","authorisation_type":"example authorisation_type 1359"},"collect_customer_details":{"default_country_code":"example default_country_code 8247","incomplete_fields":{"customer":["example customer 2984"],"customer_billing_detail":["example customer_billing_detail 870"]}},"completes_actions":["collect_bank_account"],"institution_guess_status":"pending","required":true,"requires_actions":["collect_bank_account"],"status":"pending","type":"collect_bank_details"}],"created_at":"2015-01-01T12:00:00.000Z","fallback_enabled":false,"id":"BRQ123","links":{"bank_authorisation":"example bank_authorisation 7743","creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","customer_billing_detail":"example customer_billing_detail 1968","mandate_request":"MRQ123","mandate_request_mandate":"MD123","organisation":"OR123","payment_request":"PRQ123","payment_request_payment":"PM123"},"mandate_request":{"authorisation_source":"telephone","constraints":{"end_date":"example end_date 3430","max_amount_per_payment":9513,"periodic_limits":[{"alignment":"creation_date","max_payments":4415,"max_total_amount":4657,"period":"month"}],"start_date":"example start_date 3039"},"currency":"GBP","description":"Top-up Payment","links":{"mandate":"example mandate 4904"},"metadata":{},"scheme":"bacs","verify":"minimum"},"metadata":{},"payment_request":{"amount":1000,"app_fee":100,"currency":"GBP","description":"Top-up Payment","links":{"payment":"example payment 4535"},"metadata":{},"scheme":"faster_payments"},"purpose_code":"salary","resources":{"customer":{"company_name":"Hamilton Trading Ltd.","created_at":"2014-01-01T12:00:00.000Z","email":"user@example.com","family_name":"Osborne","given_name":"Frank","id":"CU123","language":"en","metadata":{},"phone_number":"+64 4 817 9999"},"customer_bank_account":{"account_holder_name":"Billie Jean","account_number_ending":"1234","account_type":"savings","bank_name":"BARCLAYS BANK PLC","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","enabled":true,"id":"BA123","links":{"customer":"example customer 8010"},"metadata":{}},"customer_billing_detail":{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","city":"London","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","danish_identity_number":"220550-6218","id":"CU123","ip_address":"127.0.0.1","postal_code":"NW1 6XE","region":"Greater London","schemes":["example schemes 565"],"swedish_identity_number":"556564-5404"}},"status":"pending"}} }, "notify": { "method": "POST", "path_template": "/billing_requests/:identity/actions/notify", "url_params": ["BRQ123"], - "body": {"billing_requests":{"actions":[{"available_currencies":["example available_currencies 5695"],"bank_authorisation":{"adapter":"example adapter 8666","authorisation_type":"example authorisation_type 6200"},"collect_customer_details":{"default_country_code":"example default_country_code 7920","incomplete_fields":{"customer":["example customer 2048"],"customer_billing_detail":["example customer_billing_detail 6756"]}},"completes_actions":["collect_bank_account"],"institution_guess_status":"pending","required":true,"requires_actions":["collect_bank_account"],"status":"pending","type":"collect_bank_details"}],"created_at":"2015-01-01T12:00:00.000Z","fallback_enabled":false,"id":"BRQ123","links":{"bank_authorisation":"example bank_authorisation 1092","creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","customer_billing_detail":"example customer_billing_detail 8831","mandate_request":"MRQ123","mandate_request_mandate":"MD123","organisation":"OR123","payment_request":"PRQ123","payment_request_payment":"PM123"},"mandate_request":{"authorisation_source":"paper","constraints":{"end_date":"example end_date 5399","max_amount_per_payment":1162,"periodic_limits":[{"alignment":"creation_date","max_payments":1888,"max_total_amount":292,"period":"month"}],"start_date":"example start_date 5320"},"currency":"GBP","description":"Top-up Payment","links":{"mandate":"example mandate 7886"},"metadata":{},"scheme":"bacs","verify":"recommended"},"metadata":{},"payment_request":{"amount":1000,"app_fee":100,"currency":"GBP","description":"Top-up Payment","links":{"payment":"example payment 6829"},"metadata":{},"scheme":"faster_payments"},"purpose_code":"loan","resources":{"customer":{"company_name":"Hamilton Trading Ltd.","created_at":"2014-01-01T12:00:00.000Z","email":"user@example.com","family_name":"Osborne","given_name":"Frank","id":"CU123","language":"en","metadata":{},"phone_number":"+64 4 817 9999"},"customer_bank_account":{"account_holder_name":"Billie Jean","account_number_ending":"1234","account_type":"savings","bank_name":"BARCLAYS BANK PLC","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","enabled":true,"id":"BA123","links":{"customer":"example customer 9456"},"metadata":{}},"customer_billing_detail":{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","city":"London","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","danish_identity_number":"220550-6218","id":"CU123","ip_address":"127.0.0.1","postal_code":"NW1 6XE","region":"Greater London","schemes":["example schemes 6629"],"swedish_identity_number":"556564-5404"}},"status":"pending"}} + "body": {"billing_requests":{"actions":[{"available_currencies":["example available_currencies 9888"],"bank_authorisation":{"adapter":"example adapter 3447","authorisation_type":"example authorisation_type 292"},"collect_customer_details":{"default_country_code":"example default_country_code 1888","incomplete_fields":{"customer":["example customer 9103"],"customer_billing_detail":["example customer_billing_detail 6611"]}},"completes_actions":["collect_bank_account"],"institution_guess_status":"pending","required":true,"requires_actions":["collect_bank_account"],"status":"pending","type":"collect_bank_details"}],"created_at":"2015-01-01T12:00:00.000Z","fallback_enabled":true,"id":"BRQ123","links":{"bank_authorisation":"example bank_authorisation 7886","creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","customer_billing_detail":"example customer_billing_detail 5320","mandate_request":"MRQ123","mandate_request_mandate":"MD123","organisation":"OR123","payment_request":"PRQ123","payment_request_payment":"PM123"},"mandate_request":{"authorisation_source":"web","constraints":{"end_date":"example end_date 9456","max_amount_per_payment":6629,"periodic_limits":[{"alignment":"calendar","max_payments":5695,"max_total_amount":6756,"period":"year"}],"start_date":"example start_date 6200"},"currency":"GBP","description":"Top-up Payment","links":{"mandate":"example mandate 7920"},"metadata":{},"scheme":"bacs","verify":"recommended"},"metadata":{},"payment_request":{"amount":1000,"app_fee":100,"currency":"GBP","description":"Top-up Payment","links":{"payment":"example payment 1162"},"metadata":{},"scheme":"faster_payments"},"purpose_code":"loan","resources":{"customer":{"company_name":"Hamilton Trading Ltd.","created_at":"2014-01-01T12:00:00.000Z","email":"user@example.com","family_name":"Osborne","given_name":"Frank","id":"CU123","language":"en","metadata":{},"phone_number":"+64 4 817 9999"},"customer_bank_account":{"account_holder_name":"Billie Jean","account_number_ending":"1234","account_type":"savings","bank_name":"BARCLAYS BANK PLC","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","enabled":true,"id":"BA123","links":{"customer":"example customer 7577"},"metadata":{}},"customer_billing_detail":{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","city":"London","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","danish_identity_number":"220550-6218","id":"CU123","ip_address":"127.0.0.1","postal_code":"NW1 6XE","region":"Greater London","schemes":["example schemes 8831"],"swedish_identity_number":"556564-5404"}},"status":"pending"}} }, "fallback": { "method": "POST", "path_template": "/billing_requests/:identity/actions/fallback", "url_params": ["BRQ123"], - "body": {"billing_requests":{"actions":[{"available_currencies":["example available_currencies 8652"],"bank_authorisation":{"adapter":"example adapter 7807","authorisation_type":"example authorisation_type 6157"},"collect_customer_details":{"default_country_code":"example default_country_code 8318","incomplete_fields":{"customer":["example customer 3756"],"customer_billing_detail":["example customer_billing_detail 2019"]}},"completes_actions":["collect_bank_account"],"institution_guess_status":"pending","required":true,"requires_actions":["collect_bank_account"],"status":"pending","type":"collect_bank_details"}],"created_at":"2015-01-01T12:00:00.000Z","fallback_enabled":true,"id":"BRQ123","links":{"bank_authorisation":"example bank_authorisation 1853","creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","customer_billing_detail":"example customer_billing_detail 8795","mandate_request":"MRQ123","mandate_request_mandate":"MD123","organisation":"OR123","payment_request":"PRQ123","payment_request_payment":"PM123"},"mandate_request":{"authorisation_source":"telephone","constraints":{"end_date":"example end_date 2632","max_amount_per_payment":2520,"periodic_limits":[{"alignment":"creation_date","max_payments":7029,"max_total_amount":3922,"period":"day"}],"start_date":"example start_date 60"},"currency":"GBP","description":"Top-up Payment","links":{"mandate":"example mandate 9386"},"metadata":{},"scheme":"bacs","verify":"minimum"},"metadata":{},"payment_request":{"amount":1000,"app_fee":100,"currency":"GBP","description":"Top-up Payment","links":{"payment":"example payment 8470"},"metadata":{},"scheme":"faster_payments"},"purpose_code":"pension","resources":{"customer":{"company_name":"Hamilton Trading Ltd.","created_at":"2014-01-01T12:00:00.000Z","email":"user@example.com","family_name":"Osborne","given_name":"Frank","id":"CU123","language":"en","metadata":{},"phone_number":"+64 4 817 9999"},"customer_bank_account":{"account_holder_name":"Billie Jean","account_number_ending":"1234","account_type":"savings","bank_name":"BARCLAYS BANK PLC","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","enabled":true,"id":"BA123","links":{"customer":"example customer 2181"},"metadata":{}},"customer_billing_detail":{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","city":"London","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","danish_identity_number":"220550-6218","id":"CU123","ip_address":"127.0.0.1","postal_code":"NW1 6XE","region":"Greater London","schemes":["example schemes 8675"],"swedish_identity_number":"556564-5404"}},"status":"pending"}} + "body": {"billing_requests":{"actions":[{"available_currencies":["example available_currencies 3756"],"bank_authorisation":{"adapter":"example adapter 2019","authorisation_type":"example authorisation_type 7807"},"collect_customer_details":{"default_country_code":"example default_country_code 6157","incomplete_fields":{"customer":["example customer 8675"],"customer_billing_detail":["example customer_billing_detail 8652"]}},"completes_actions":["collect_bank_account"],"institution_guess_status":"pending","required":true,"requires_actions":["collect_bank_account"],"status":"pending","type":"collect_bank_details"}],"created_at":"2015-01-01T12:00:00.000Z","fallback_enabled":true,"id":"BRQ123","links":{"bank_authorisation":"example bank_authorisation 2181","creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","customer_billing_detail":"example customer_billing_detail 1853","mandate_request":"MRQ123","mandate_request_mandate":"MD123","organisation":"OR123","payment_request":"PRQ123","payment_request_payment":"PM123"},"mandate_request":{"authorisation_source":"telephone","constraints":{"end_date":"example end_date 8470","max_amount_per_payment":8996,"periodic_limits":[{"alignment":"calendar","max_payments":9386,"max_total_amount":260,"period":"day"}],"start_date":"example start_date 1393"},"currency":"GBP","description":"Top-up Payment","links":{"mandate":"example mandate 417"},"metadata":{},"scheme":"bacs","verify":"always"},"metadata":{},"payment_request":{"amount":1000,"app_fee":100,"currency":"GBP","description":"Top-up Payment","links":{"payment":"example payment 8318"},"metadata":{},"scheme":"faster_payments"},"purpose_code":"gambling","resources":{"customer":{"company_name":"Hamilton Trading Ltd.","created_at":"2014-01-01T12:00:00.000Z","email":"user@example.com","family_name":"Osborne","given_name":"Frank","id":"CU123","language":"en","metadata":{},"phone_number":"+64 4 817 9999"},"customer_bank_account":{"account_holder_name":"Billie Jean","account_number_ending":"1234","account_type":"savings","bank_name":"BARCLAYS BANK PLC","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","enabled":true,"id":"BA123","links":{"customer":"example customer 1661"},"metadata":{}},"customer_billing_detail":{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","city":"London","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","danish_identity_number":"220550-6218","id":"CU123","ip_address":"127.0.0.1","postal_code":"NW1 6XE","region":"Greater London","schemes":["example schemes 7029"],"swedish_identity_number":"556564-5404"}},"status":"pending"}} }, "choose_currency": { "method": "POST", "path_template": "/billing_requests/:identity/actions/choose_currency", "url_params": ["BRQ123"], - "body": {"billing_requests":{"actions":[{"available_currencies":["example available_currencies 1719"],"bank_authorisation":{"adapter":"example adapter 5014","authorisation_type":"example authorisation_type 1040"},"collect_customer_details":{"default_country_code":"example default_country_code 8662","incomplete_fields":{"customer":["example customer 5740"],"customer_billing_detail":["example customer_billing_detail 6000"]}},"completes_actions":["collect_bank_account"],"institution_guess_status":"pending","required":true,"requires_actions":["collect_bank_account"],"status":"pending","type":"collect_bank_details"}],"created_at":"2015-01-01T12:00:00.000Z","fallback_enabled":true,"id":"BRQ123","links":{"bank_authorisation":"example bank_authorisation 1079","creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","customer_billing_detail":"example customer_billing_detail 2954","mandate_request":"MRQ123","mandate_request_mandate":"MD123","organisation":"OR123","payment_request":"PRQ123","payment_request_payment":"PM123"},"mandate_request":{"authorisation_source":"web","constraints":{"end_date":"example end_date 1181","max_amount_per_payment":1757,"periodic_limits":[{"alignment":"calendar","max_payments":4637,"max_total_amount":7039,"period":"day"}],"start_date":"example start_date 1533"},"currency":"GBP","description":"Top-up Payment","links":{"mandate":"example mandate 9551"},"metadata":{},"scheme":"bacs","verify":"minimum"},"metadata":{},"payment_request":{"amount":1000,"app_fee":100,"currency":"GBP","description":"Top-up Payment","links":{"payment":"example payment 2060"},"metadata":{},"scheme":"faster_payments"},"purpose_code":"mortgage","resources":{"customer":{"company_name":"Hamilton Trading Ltd.","created_at":"2014-01-01T12:00:00.000Z","email":"user@example.com","family_name":"Osborne","given_name":"Frank","id":"CU123","language":"en","metadata":{},"phone_number":"+64 4 817 9999"},"customer_bank_account":{"account_holder_name":"Billie Jean","account_number_ending":"1234","account_type":"savings","bank_name":"BARCLAYS BANK PLC","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","enabled":true,"id":"BA123","links":{"customer":"example customer 1509"},"metadata":{}},"customer_billing_detail":{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","city":"London","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","danish_identity_number":"220550-6218","id":"CU123","ip_address":"127.0.0.1","postal_code":"NW1 6XE","region":"Greater London","schemes":["example schemes 6685"],"swedish_identity_number":"556564-5404"}},"status":"pending"}} + "body": {"billing_requests":{"actions":[{"available_currencies":["example available_currencies 1215"],"bank_authorisation":{"adapter":"example adapter 5561","authorisation_type":"example authorisation_type 1533"},"collect_customer_details":{"default_country_code":"example default_country_code 2804","incomplete_fields":{"customer":["example customer 6685"],"customer_billing_detail":["example customer_billing_detail 1509"]}},"completes_actions":["collect_bank_account"],"institution_guess_status":"pending","required":true,"requires_actions":["collect_bank_account"],"status":"pending","type":"collect_bank_details"}],"created_at":"2015-01-01T12:00:00.000Z","fallback_enabled":false,"id":"BRQ123","links":{"bank_authorisation":"example bank_authorisation 8662","creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","customer_billing_detail":"example customer_billing_detail 1040","mandate_request":"MRQ123","mandate_request_mandate":"MD123","organisation":"OR123","payment_request":"PRQ123","payment_request_payment":"PM123"},"mandate_request":{"authorisation_source":"paper","constraints":{"end_date":"example end_date 1464","max_amount_per_payment":2060,"periodic_limits":[{"alignment":"calendar","max_payments":1757,"max_total_amount":1181,"period":"week"}],"start_date":"example start_date 600"},"currency":"GBP","description":"Top-up Payment","links":{"mandate":"example mandate 2954"},"metadata":{},"scheme":"bacs","verify":"always"},"metadata":{},"payment_request":{"amount":1000,"app_fee":100,"currency":"GBP","description":"Top-up Payment","links":{"payment":"example payment 4637"},"metadata":{},"scheme":"faster_payments"},"purpose_code":"mortgage","resources":{"customer":{"company_name":"Hamilton Trading Ltd.","created_at":"2014-01-01T12:00:00.000Z","email":"user@example.com","family_name":"Osborne","given_name":"Frank","id":"CU123","language":"en","metadata":{},"phone_number":"+64 4 817 9999"},"customer_bank_account":{"account_holder_name":"Billie Jean","account_number_ending":"1234","account_type":"savings","bank_name":"BARCLAYS BANK PLC","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","enabled":true,"id":"BA123","links":{"customer":"example customer 1719"},"metadata":{}},"customer_billing_detail":{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","city":"London","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","danish_identity_number":"220550-6218","id":"CU123","ip_address":"127.0.0.1","postal_code":"NW1 6XE","region":"Greater London","schemes":["example schemes 5014"],"swedish_identity_number":"556564-5404"}},"status":"pending"}} }, "select_institution": { "method": "POST", "path_template": "/billing_requests/:identity/actions/select_institution", "url_params": ["BRQ123"], - "body": {"billing_requests":{"actions":[{"available_currencies":["example available_currencies 3524"],"bank_authorisation":{"adapter":"example adapter 1606","authorisation_type":"example authorisation_type 7293"},"collect_customer_details":{"default_country_code":"example default_country_code 9648","incomplete_fields":{"customer":["example customer 7420"],"customer_billing_detail":["example customer_billing_detail 3352"]}},"completes_actions":["collect_bank_account"],"institution_guess_status":"pending","required":true,"requires_actions":["collect_bank_account"],"status":"pending","type":"collect_bank_details"}],"created_at":"2015-01-01T12:00:00.000Z","fallback_enabled":false,"id":"BRQ123","links":{"bank_authorisation":"example bank_authorisation 235","creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","customer_billing_detail":"example customer_billing_detail 6443","mandate_request":"MRQ123","mandate_request_mandate":"MD123","organisation":"OR123","payment_request":"PRQ123","payment_request_payment":"PM123"},"mandate_request":{"authorisation_source":"web","constraints":{"end_date":"example end_date 3472","max_amount_per_payment":1544,"periodic_limits":[{"alignment":"calendar","max_payments":2869,"max_total_amount":574,"period":"week"}],"start_date":"example start_date 3338"},"currency":"GBP","description":"Top-up Payment","links":{"mandate":"example mandate 1237"},"metadata":{},"scheme":"bacs","verify":"when_available"},"metadata":{},"payment_request":{"amount":1000,"app_fee":100,"currency":"GBP","description":"Top-up Payment","links":{"payment":"example payment 2390"},"metadata":{},"scheme":"faster_payments"},"purpose_code":"retail","resources":{"customer":{"company_name":"Hamilton Trading Ltd.","created_at":"2014-01-01T12:00:00.000Z","email":"user@example.com","family_name":"Osborne","given_name":"Frank","id":"CU123","language":"en","metadata":{},"phone_number":"+64 4 817 9999"},"customer_bank_account":{"account_holder_name":"Billie Jean","account_number_ending":"1234","account_type":"savings","bank_name":"BARCLAYS BANK PLC","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","enabled":true,"id":"BA123","links":{"customer":"example customer 3173"},"metadata":{}},"customer_billing_detail":{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","city":"London","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","danish_identity_number":"220550-6218","id":"CU123","ip_address":"127.0.0.1","postal_code":"NW1 6XE","region":"Greater London","schemes":["example schemes 9284"],"swedish_identity_number":"556564-5404"}},"status":"pending"}} + "body": {"billing_requests":{"actions":[{"available_currencies":["example available_currencies 7293"],"bank_authorisation":{"adapter":"example adapter 1237","authorisation_type":"example authorisation_type 3524"},"collect_customer_details":{"default_country_code":"example default_country_code 1606","incomplete_fields":{"customer":["example customer 9648"],"customer_billing_detail":["example customer_billing_detail 3352"]}},"completes_actions":["collect_bank_account"],"institution_guess_status":"pending","required":true,"requires_actions":["collect_bank_account"],"status":"pending","type":"collect_bank_details"}],"created_at":"2015-01-01T12:00:00.000Z","fallback_enabled":true,"id":"BRQ123","links":{"bank_authorisation":"example bank_authorisation 8622","creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","customer_billing_detail":"example customer_billing_detail 7420","mandate_request":"MRQ123","mandate_request_mandate":"MD123","organisation":"OR123","payment_request":"PRQ123","payment_request_payment":"PM123"},"mandate_request":{"authorisation_source":"web","constraints":{"end_date":"example end_date 8070","max_amount_per_payment":6336,"periodic_limits":[{"alignment":"creation_date","max_payments":1544,"max_total_amount":3472,"period":"year"}],"start_date":"example start_date 2174"},"currency":"GBP","description":"Top-up Payment","links":{"mandate":"example mandate 2869"},"metadata":{},"scheme":"bacs","verify":"when_available"},"metadata":{},"payment_request":{"amount":1000,"app_fee":100,"currency":"GBP","description":"Top-up Payment","links":{"payment":"example payment 235"},"metadata":{},"scheme":"faster_payments"},"purpose_code":"utility","resources":{"customer":{"company_name":"Hamilton Trading Ltd.","created_at":"2014-01-01T12:00:00.000Z","email":"user@example.com","family_name":"Osborne","given_name":"Frank","id":"CU123","language":"en","metadata":{},"phone_number":"+64 4 817 9999"},"customer_bank_account":{"account_holder_name":"Billie Jean","account_number_ending":"1234","account_type":"savings","bank_name":"BARCLAYS BANK PLC","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","enabled":true,"id":"BA123","links":{"customer":"example customer 421"},"metadata":{}},"customer_billing_detail":{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","city":"London","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","danish_identity_number":"220550-6218","id":"CU123","ip_address":"127.0.0.1","postal_code":"NW1 6XE","region":"Greater London","schemes":["example schemes 6443"],"swedish_identity_number":"556564-5404"}},"status":"pending"}} } } diff --git a/tests/fixtures/blocks.json b/tests/fixtures/blocks.json index 57d2ac72..aefd5767 100644 --- a/tests/fixtures/blocks.json +++ b/tests/fixtures/blocks.json @@ -15,7 +15,7 @@ "method": "GET", "path_template": "/blocks", "url_params": [], - "body": {"blocks":[{"active":true,"block_type":"example block_type 3653","created_at":"2014-01-01T12:00:00.000Z","id":"BLC123","reason_description":"example reason_description 8284","reason_type":"example reason_type 6774","resource_reference":"example@example.com","updated_at":"2014-01-01T12:00:00.000Z"},{"active":true,"block_type":"example block_type 2375","created_at":"2014-01-01T12:00:00.000Z","id":"BLC123","reason_description":"example reason_description 106","reason_type":"example reason_type 1874","resource_reference":"example@example.com","updated_at":"2014-01-01T12:00:00.000Z"}],"meta":{"cursors":{"after":"example after 6537","before":"example before 2286"},"limit":50}} + "body": {"blocks":[{"active":true,"block_type":"example block_type 8284","created_at":"2014-01-01T12:00:00.000Z","id":"BLC123","reason_description":"example reason_description 1874","reason_type":"example reason_type 2375","resource_reference":"example@example.com","updated_at":"2014-01-01T12:00:00.000Z"},{"active":true,"block_type":"example block_type 2286","created_at":"2014-01-01T12:00:00.000Z","id":"BLC123","reason_description":"example reason_description 6537","reason_type":"example reason_type 106","resource_reference":"example@example.com","updated_at":"2014-01-01T12:00:00.000Z"}],"meta":{"cursors":{"after":"example after 3653","before":"example before 6774"},"limit":50}} }, "disable": { "method": "POST", diff --git a/tests/fixtures/creditors.json b/tests/fixtures/creditors.json index 7ccf1c88..1ed5ecf5 100644 --- a/tests/fixtures/creditors.json +++ b/tests/fixtures/creditors.json @@ -3,24 +3,24 @@ "method": "POST", "path_template": "/creditors", "url_params": [], - "body": {"creditors":{"address_line1":"338-346 Goswell Road","address_line2":"Islington","address_line3":"example address_line3 928","bank_reference_prefix":"ACME","can_create_refunds":false,"city":"London","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","creditor_type":"company","custom_payment_pages_enabled":true,"fx_payout_currency":"EUR","id":"CR123","links":{"default_aud_payout_account":"BA234","default_cad_payout_account":"BA792","default_dkk_payout_account":"BA790","default_eur_payout_account":"BA456","default_gbp_payout_account":"BA123","default_nzd_payout_account":"BA791","default_sek_payout_account":"BA789","default_usd_payout_account":"BA792"},"logo_url":"https://uploads.gocardless.com/logo.png","mandate_imports_enabled":true,"merchant_responsible_for_notifications":true,"name":"Acme","postal_code":"EC1V 7LQ","region":"example region 7477","scheme_identifiers":[{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","can_specify_mandate_reference":false,"city":"London","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","email":"user@example.com","id":"SU123","minimum_advance_notice":3,"name":"example name 4926","phone_number":"+44 20 1234 1234","postal_code":"NW1 6XE","reference":"example reference 5516","region":"Greater London","scheme":"bacs","status":"pending"}],"verification_status":"action_required"}} + "body": {"creditors":{"address_line1":"338-346 Goswell Road","address_line2":"Islington","address_line3":"example address_line3 4926","bank_reference_prefix":"ACME","can_create_refunds":false,"city":"London","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","creditor_type":"company","custom_payment_pages_enabled":true,"fx_payout_currency":"EUR","id":"CR123","links":{"default_aud_payout_account":"BA234","default_cad_payout_account":"BA792","default_dkk_payout_account":"BA790","default_eur_payout_account":"BA456","default_gbp_payout_account":"BA123","default_nzd_payout_account":"BA791","default_sek_payout_account":"BA789","default_usd_payout_account":"BA792"},"logo_url":"https://uploads.gocardless.com/logo.png","mandate_imports_enabled":true,"merchant_responsible_for_notifications":true,"name":"Acme","postal_code":"EC1V 7LQ","region":"example region 7477","scheme_identifiers":[{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","can_specify_mandate_reference":false,"city":"London","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","email":"user@example.com","id":"SU123","minimum_advance_notice":3,"name":"example name 5516","phone_number":"+44 20 1234 1234","postal_code":"NW1 6XE","reference":"example reference 928","region":"Greater London","scheme":"bacs","status":"pending"}],"verification_status":"action_required"}} }, "list": { "method": "GET", "path_template": "/creditors", "url_params": [], - "body": {"creditors":[{"address_line1":"338-346 Goswell Road","address_line2":"Islington","address_line3":"example address_line3 6051","bank_reference_prefix":"ACME","can_create_refunds":false,"city":"London","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","creditor_type":"company","custom_payment_pages_enabled":true,"fx_payout_currency":"EUR","id":"CR123","links":{"default_aud_payout_account":"BA234","default_cad_payout_account":"BA792","default_dkk_payout_account":"BA790","default_eur_payout_account":"BA456","default_gbp_payout_account":"BA123","default_nzd_payout_account":"BA791","default_sek_payout_account":"BA789","default_usd_payout_account":"BA792"},"logo_url":"https://uploads.gocardless.com/logo.png","mandate_imports_enabled":true,"merchant_responsible_for_notifications":true,"name":"Acme","postal_code":"EC1V 7LQ","region":"example region 9105","scheme_identifiers":[{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","can_specify_mandate_reference":false,"city":"London","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","email":"user@example.com","id":"SU123","minimum_advance_notice":3,"name":"example name 6789","phone_number":"+44 20 1234 1234","postal_code":"NW1 6XE","reference":"example reference 7762","region":"Greater London","scheme":"bacs","status":"pending"}],"verification_status":"action_required"},{"address_line1":"338-346 Goswell Road","address_line2":"Islington","address_line3":"example address_line3 4698","bank_reference_prefix":"ACME","can_create_refunds":false,"city":"London","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","creditor_type":"company","custom_payment_pages_enabled":true,"fx_payout_currency":"EUR","id":"CR123","links":{"default_aud_payout_account":"BA234","default_cad_payout_account":"BA792","default_dkk_payout_account":"BA790","default_eur_payout_account":"BA456","default_gbp_payout_account":"BA123","default_nzd_payout_account":"BA791","default_sek_payout_account":"BA789","default_usd_payout_account":"BA792"},"logo_url":"https://uploads.gocardless.com/logo.png","mandate_imports_enabled":true,"merchant_responsible_for_notifications":true,"name":"Acme","postal_code":"EC1V 7LQ","region":"example region 2409","scheme_identifiers":[{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","can_specify_mandate_reference":false,"city":"London","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","email":"user@example.com","id":"SU123","minimum_advance_notice":3,"name":"example name 9430","phone_number":"+44 20 1234 1234","postal_code":"NW1 6XE","reference":"example reference 2887","region":"Greater London","scheme":"bacs","status":"pending"}],"verification_status":"action_required"}],"meta":{"cursors":{"after":"example after 7412","before":"example before 5036"},"limit":50}} + "body": {"creditors":[{"address_line1":"338-346 Goswell Road","address_line2":"Islington","address_line3":"example address_line3 7412","bank_reference_prefix":"ACME","can_create_refunds":false,"city":"London","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","creditor_type":"company","custom_payment_pages_enabled":true,"fx_payout_currency":"EUR","id":"CR123","links":{"default_aud_payout_account":"BA234","default_cad_payout_account":"BA792","default_dkk_payout_account":"BA790","default_eur_payout_account":"BA456","default_gbp_payout_account":"BA123","default_nzd_payout_account":"BA791","default_sek_payout_account":"BA789","default_usd_payout_account":"BA792"},"logo_url":"https://uploads.gocardless.com/logo.png","mandate_imports_enabled":true,"merchant_responsible_for_notifications":true,"name":"Acme","postal_code":"EC1V 7LQ","region":"example region 9105","scheme_identifiers":[{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","can_specify_mandate_reference":false,"city":"London","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","email":"user@example.com","id":"SU123","minimum_advance_notice":3,"name":"example name 5036","phone_number":"+44 20 1234 1234","postal_code":"NW1 6XE","reference":"example reference 6051","region":"Greater London","scheme":"bacs","status":"pending"}],"verification_status":"action_required"},{"address_line1":"338-346 Goswell Road","address_line2":"Islington","address_line3":"example address_line3 6789","bank_reference_prefix":"ACME","can_create_refunds":false,"city":"London","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","creditor_type":"company","custom_payment_pages_enabled":true,"fx_payout_currency":"EUR","id":"CR123","links":{"default_aud_payout_account":"BA234","default_cad_payout_account":"BA792","default_dkk_payout_account":"BA790","default_eur_payout_account":"BA456","default_gbp_payout_account":"BA123","default_nzd_payout_account":"BA791","default_sek_payout_account":"BA789","default_usd_payout_account":"BA792"},"logo_url":"https://uploads.gocardless.com/logo.png","mandate_imports_enabled":true,"merchant_responsible_for_notifications":true,"name":"Acme","postal_code":"EC1V 7LQ","region":"example region 7762","scheme_identifiers":[{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","can_specify_mandate_reference":false,"city":"London","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","email":"user@example.com","id":"SU123","minimum_advance_notice":3,"name":"example name 2887","phone_number":"+44 20 1234 1234","postal_code":"NW1 6XE","reference":"example reference 4698","region":"Greater London","scheme":"bacs","status":"pending"}],"verification_status":"action_required"}],"meta":{"cursors":{"after":"example after 2409","before":"example before 9430"},"limit":50}} }, "get": { "method": "GET", "path_template": "/creditors/:identity", "url_params": ["CR123"], - "body": {"creditors":{"address_line1":"338-346 Goswell Road","address_line2":"Islington","address_line3":"example address_line3 9159","bank_reference_prefix":"ACME","can_create_refunds":false,"city":"London","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","creditor_type":"company","custom_payment_pages_enabled":true,"fx_payout_currency":"EUR","id":"CR123","links":{"default_aud_payout_account":"BA234","default_cad_payout_account":"BA792","default_dkk_payout_account":"BA790","default_eur_payout_account":"BA456","default_gbp_payout_account":"BA123","default_nzd_payout_account":"BA791","default_sek_payout_account":"BA789","default_usd_payout_account":"BA792"},"logo_url":"https://uploads.gocardless.com/logo.png","mandate_imports_enabled":true,"merchant_responsible_for_notifications":true,"name":"Acme","postal_code":"EC1V 7LQ","region":"example region 1128","scheme_identifiers":[{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","can_specify_mandate_reference":false,"city":"London","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","email":"user@example.com","id":"SU123","minimum_advance_notice":3,"name":"example name 6861","phone_number":"+44 20 1234 1234","postal_code":"NW1 6XE","reference":"example reference 8602","region":"Greater London","scheme":"bacs","status":"pending"}],"verification_status":"action_required"}} + "body": {"creditors":{"address_line1":"338-346 Goswell Road","address_line2":"Islington","address_line3":"example address_line3 6861","bank_reference_prefix":"ACME","can_create_refunds":false,"city":"London","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","creditor_type":"company","custom_payment_pages_enabled":true,"fx_payout_currency":"EUR","id":"CR123","links":{"default_aud_payout_account":"BA234","default_cad_payout_account":"BA792","default_dkk_payout_account":"BA790","default_eur_payout_account":"BA456","default_gbp_payout_account":"BA123","default_nzd_payout_account":"BA791","default_sek_payout_account":"BA789","default_usd_payout_account":"BA792"},"logo_url":"https://uploads.gocardless.com/logo.png","mandate_imports_enabled":true,"merchant_responsible_for_notifications":true,"name":"Acme","postal_code":"EC1V 7LQ","region":"example region 8602","scheme_identifiers":[{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","can_specify_mandate_reference":false,"city":"London","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","email":"user@example.com","id":"SU123","minimum_advance_notice":3,"name":"example name 9159","phone_number":"+44 20 1234 1234","postal_code":"NW1 6XE","reference":"example reference 1128","region":"Greater London","scheme":"bacs","status":"pending"}],"verification_status":"action_required"}} }, "update": { "method": "PUT", "path_template": "/creditors/:identity", "url_params": ["CR123"], - "body": {"creditors":{"address_line1":"338-346 Goswell Road","address_line2":"Islington","address_line3":"example address_line3 7871","bank_reference_prefix":"ACME","can_create_refunds":false,"city":"London","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","creditor_type":"company","custom_payment_pages_enabled":true,"fx_payout_currency":"EUR","id":"CR123","links":{"default_aud_payout_account":"BA234","default_cad_payout_account":"BA792","default_dkk_payout_account":"BA790","default_eur_payout_account":"BA456","default_gbp_payout_account":"BA123","default_nzd_payout_account":"BA791","default_sek_payout_account":"BA789","default_usd_payout_account":"BA792"},"logo_url":"https://uploads.gocardless.com/logo.png","mandate_imports_enabled":true,"merchant_responsible_for_notifications":true,"name":"Acme","postal_code":"EC1V 7LQ","region":"example region 7653","scheme_identifiers":[{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","can_specify_mandate_reference":false,"city":"London","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","email":"user@example.com","id":"SU123","minimum_advance_notice":3,"name":"example name 8345","phone_number":"+44 20 1234 1234","postal_code":"NW1 6XE","reference":"example reference 7418","region":"Greater London","scheme":"bacs","status":"pending"}],"verification_status":"action_required"}} + "body": {"creditors":{"address_line1":"338-346 Goswell Road","address_line2":"Islington","address_line3":"example address_line3 7653","bank_reference_prefix":"ACME","can_create_refunds":false,"city":"London","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","creditor_type":"company","custom_payment_pages_enabled":true,"fx_payout_currency":"EUR","id":"CR123","links":{"default_aud_payout_account":"BA234","default_cad_payout_account":"BA792","default_dkk_payout_account":"BA790","default_eur_payout_account":"BA456","default_gbp_payout_account":"BA123","default_nzd_payout_account":"BA791","default_sek_payout_account":"BA789","default_usd_payout_account":"BA792"},"logo_url":"https://uploads.gocardless.com/logo.png","mandate_imports_enabled":true,"merchant_responsible_for_notifications":true,"name":"Acme","postal_code":"EC1V 7LQ","region":"example region 7871","scheme_identifiers":[{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","can_specify_mandate_reference":false,"city":"London","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","email":"user@example.com","id":"SU123","minimum_advance_notice":3,"name":"example name 8345","phone_number":"+44 20 1234 1234","postal_code":"NW1 6XE","reference":"example reference 7418","region":"Greater London","scheme":"bacs","status":"pending"}],"verification_status":"action_required"}} } } diff --git a/tests/fixtures/customer_bank_accounts.json b/tests/fixtures/customer_bank_accounts.json index 8be5f09a..8508eddb 100644 --- a/tests/fixtures/customer_bank_accounts.json +++ b/tests/fixtures/customer_bank_accounts.json @@ -9,7 +9,7 @@ "method": "GET", "path_template": "/customer_bank_accounts", "url_params": [], - "body": {"customer_bank_accounts":[{"account_holder_name":"Billie Jean","account_number_ending":"1234","account_type":"savings","bank_name":"BARCLAYS BANK PLC","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","enabled":true,"id":"BA123","links":{"customer":"example customer 556"},"metadata":{}},{"account_holder_name":"Billie Jean","account_number_ending":"1234","account_type":"savings","bank_name":"BARCLAYS BANK PLC","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","enabled":true,"id":"BA123","links":{"customer":"example customer 7695"},"metadata":{}}],"meta":{"cursors":{"after":"example after 580","before":"example before 4834"},"limit":50}} + "body": {"customer_bank_accounts":[{"account_holder_name":"Billie Jean","account_number_ending":"1234","account_type":"savings","bank_name":"BARCLAYS BANK PLC","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","enabled":true,"id":"BA123","links":{"customer":"example customer 580"},"metadata":{}},{"account_holder_name":"Billie Jean","account_number_ending":"1234","account_type":"savings","bank_name":"BARCLAYS BANK PLC","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","enabled":true,"id":"BA123","links":{"customer":"example customer 4834"},"metadata":{}}],"meta":{"cursors":{"after":"example after 7695","before":"example before 556"},"limit":50}} }, "get": { "method": "GET", diff --git a/tests/fixtures/customer_notifications.json b/tests/fixtures/customer_notifications.json index a4e8d9cd..ef60b394 100644 --- a/tests/fixtures/customer_notifications.json +++ b/tests/fixtures/customer_notifications.json @@ -3,6 +3,6 @@ "method": "POST", "path_template": "/customer_notifications/:identity/actions/handle", "url_params": ["PCN123"], - "body": {"customer_notifications":{"action_taken":"example action_taken 4993","action_taken_at":"2023-09-19T09:24:12.835Z","action_taken_by":"example action_taken_by 2175","id":"PCN123","links":{"customer":"CU123","event":"EV123","mandate":"MD123","payment":"PM123","refund":"RF123","subscription":"SB123"},"type":"payment_created"}} + "body": {"customer_notifications":{"action_taken":"example action_taken 2175","action_taken_at":"2023-09-19T14:17:04.944Z","action_taken_by":"example action_taken_by 4993","id":"PCN123","links":{"customer":"CU123","event":"EV123","mandate":"MD123","payment":"PM123","refund":"RF123","subscription":"SB123"},"type":"payment_created"}} } } diff --git a/tests/fixtures/customers.json b/tests/fixtures/customers.json index cc5c8adc..48502ed6 100644 --- a/tests/fixtures/customers.json +++ b/tests/fixtures/customers.json @@ -9,7 +9,7 @@ "method": "GET", "path_template": "/customers", "url_params": [], - "body": {"customers":[{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","city":"London","company_name":"Hamilton Trading Ltd.","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","danish_identity_number":"220550-6218","email":"user@example.com","family_name":"Osborne","given_name":"Frank","id":"CU123","language":"en","metadata":{},"phone_number":"+64 4 817 9999","postal_code":"NW1 6XE","region":"Greater London","swedish_identity_number":"556564-5404"},{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","city":"London","company_name":"Hamilton Trading Ltd.","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","danish_identity_number":"220550-6218","email":"user@example.com","family_name":"Osborne","given_name":"Frank","id":"CU123","language":"en","metadata":{},"phone_number":"+64 4 817 9999","postal_code":"NW1 6XE","region":"Greater London","swedish_identity_number":"556564-5404"}],"meta":{"cursors":{"after":"example after 7276","before":"example before 1509"},"limit":50}} + "body": {"customers":[{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","city":"London","company_name":"Hamilton Trading Ltd.","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","danish_identity_number":"220550-6218","email":"user@example.com","family_name":"Osborne","given_name":"Frank","id":"CU123","language":"en","metadata":{},"phone_number":"+64 4 817 9999","postal_code":"NW1 6XE","region":"Greater London","swedish_identity_number":"556564-5404"},{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","city":"London","company_name":"Hamilton Trading Ltd.","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","danish_identity_number":"220550-6218","email":"user@example.com","family_name":"Osborne","given_name":"Frank","id":"CU123","language":"en","metadata":{},"phone_number":"+64 4 817 9999","postal_code":"NW1 6XE","region":"Greater London","swedish_identity_number":"556564-5404"}],"meta":{"cursors":{"after":"example after 1509","before":"example before 7276"},"limit":50}} }, "get": { "method": "GET", diff --git a/tests/fixtures/events.json b/tests/fixtures/events.json index 83d6baa4..1ee71af8 100644 --- a/tests/fixtures/events.json +++ b/tests/fixtures/events.json @@ -3,12 +3,12 @@ "method": "GET", "path_template": "/events", "url_params": [], - "body": {"events":[{"action":"cancelled","created_at":"2014-01-01T12:00:00.000Z","customer_notifications":[{"deadline":"2023-09-19T09:24:12.836Z","id":"PCN123","mandatory":false,"type":"example type 3380"}],"details":{"bank_account_id":"BA123","cause":"bank_account_disabled","currency":"GBP","description":"Customer's bank account closed","not_retried_reason":"failure_filter_applied","origin":"bank","property":"fx_payout_currency","reason_code":"ADDACS-B","scheme":"bacs","will_attempt_retry":true},"id":"EV123","links":{"bank_authorisation":"BAU123","billing_request":"BRQ123","billing_request_flow":"BRF123","creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","instalment_schedule":"IS123","mandate":"MD123","mandate_request_mandate":"MD123","new_customer_bank_account":"BA123","new_mandate":"MD123","organisation":"OR123","parent_event":"EV123","payer_authorisation":"PAU123","payment":"PM123","payment_request_payment":"PM123","payout":"PO123","previous_customer_bank_account":"BA123","refund":"RF123","scheme_identifier":"SU123","subscription":"SB123"},"metadata":{},"resource_metadata":{},"resource_type":"mandates"},{"action":"cancelled","created_at":"2014-01-01T12:00:00.000Z","customer_notifications":[{"deadline":"2023-09-19T09:24:12.836Z","id":"PCN123","mandatory":true,"type":"example type 2631"}],"details":{"bank_account_id":"BA123","cause":"bank_account_disabled","currency":"GBP","description":"Customer's bank account closed","not_retried_reason":"failure_filter_applied","origin":"bank","property":"fx_payout_currency","reason_code":"ADDACS-B","scheme":"bacs","will_attempt_retry":true},"id":"EV123","links":{"bank_authorisation":"BAU123","billing_request":"BRQ123","billing_request_flow":"BRF123","creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","instalment_schedule":"IS123","mandate":"MD123","mandate_request_mandate":"MD123","new_customer_bank_account":"BA123","new_mandate":"MD123","organisation":"OR123","parent_event":"EV123","payer_authorisation":"PAU123","payment":"PM123","payment_request_payment":"PM123","payout":"PO123","previous_customer_bank_account":"BA123","refund":"RF123","scheme_identifier":"SU123","subscription":"SB123"},"metadata":{},"resource_metadata":{},"resource_type":"mandates"}],"meta":{"cursors":{"after":"example after 2884","before":"example before 8558"},"limit":50}} + "body": {"events":[{"action":"cancelled","created_at":"2014-01-01T12:00:00.000Z","customer_notifications":[{"deadline":"2023-09-19T14:17:04.945Z","id":"PCN123","mandatory":true,"type":"example type 2631"}],"details":{"bank_account_id":"BA123","cause":"bank_account_disabled","currency":"GBP","description":"Customer's bank account closed","not_retried_reason":"failure_filter_applied","origin":"bank","property":"fx_payout_currency","reason_code":"ADDACS-B","scheme":"bacs","will_attempt_retry":true},"id":"EV123","links":{"bank_authorisation":"BAU123","billing_request":"BRQ123","billing_request_flow":"BRF123","creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","instalment_schedule":"IS123","mandate":"MD123","mandate_request_mandate":"MD123","new_customer_bank_account":"BA123","new_mandate":"MD123","organisation":"OR123","parent_event":"EV123","payer_authorisation":"PAU123","payment":"PM123","payment_request_payment":"PM123","payout":"PO123","previous_customer_bank_account":"BA123","refund":"RF123","scheme_identifier":"SU123","subscription":"SB123"},"metadata":{},"resource_metadata":{},"resource_type":"mandates"},{"action":"cancelled","created_at":"2014-01-01T12:00:00.000Z","customer_notifications":[{"deadline":"2023-09-19T14:17:04.945Z","id":"PCN123","mandatory":true,"type":"example type 8558"}],"details":{"bank_account_id":"BA123","cause":"bank_account_disabled","currency":"GBP","description":"Customer's bank account closed","not_retried_reason":"failure_filter_applied","origin":"bank","property":"fx_payout_currency","reason_code":"ADDACS-B","scheme":"bacs","will_attempt_retry":true},"id":"EV123","links":{"bank_authorisation":"BAU123","billing_request":"BRQ123","billing_request_flow":"BRF123","creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","instalment_schedule":"IS123","mandate":"MD123","mandate_request_mandate":"MD123","new_customer_bank_account":"BA123","new_mandate":"MD123","organisation":"OR123","parent_event":"EV123","payer_authorisation":"PAU123","payment":"PM123","payment_request_payment":"PM123","payout":"PO123","previous_customer_bank_account":"BA123","refund":"RF123","scheme_identifier":"SU123","subscription":"SB123"},"metadata":{},"resource_metadata":{},"resource_type":"mandates"}],"meta":{"cursors":{"after":"example after 3808","before":"example before 3380"},"limit":50}} }, "get": { "method": "GET", "path_template": "/events/:identity", "url_params": ["EV123"], - "body": {"events":{"action":"cancelled","created_at":"2014-01-01T12:00:00.000Z","customer_notifications":[{"deadline":"2023-09-19T09:24:12.836Z","id":"PCN123","mandatory":false,"type":"example type 442"}],"details":{"bank_account_id":"BA123","cause":"bank_account_disabled","currency":"GBP","description":"Customer's bank account closed","not_retried_reason":"failure_filter_applied","origin":"bank","property":"fx_payout_currency","reason_code":"ADDACS-B","scheme":"bacs","will_attempt_retry":true},"id":"EV123","links":{"bank_authorisation":"BAU123","billing_request":"BRQ123","billing_request_flow":"BRF123","creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","instalment_schedule":"IS123","mandate":"MD123","mandate_request_mandate":"MD123","new_customer_bank_account":"BA123","new_mandate":"MD123","organisation":"OR123","parent_event":"EV123","payer_authorisation":"PAU123","payment":"PM123","payment_request_payment":"PM123","payout":"PO123","previous_customer_bank_account":"BA123","refund":"RF123","scheme_identifier":"SU123","subscription":"SB123"},"metadata":{},"resource_metadata":{},"resource_type":"mandates"}} + "body": {"events":{"action":"cancelled","created_at":"2014-01-01T12:00:00.000Z","customer_notifications":[{"deadline":"2023-09-19T14:17:04.946Z","id":"PCN123","mandatory":false,"type":"example type 442"}],"details":{"bank_account_id":"BA123","cause":"bank_account_disabled","currency":"GBP","description":"Customer's bank account closed","not_retried_reason":"failure_filter_applied","origin":"bank","property":"fx_payout_currency","reason_code":"ADDACS-B","scheme":"bacs","will_attempt_retry":true},"id":"EV123","links":{"bank_authorisation":"BAU123","billing_request":"BRQ123","billing_request_flow":"BRF123","creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","instalment_schedule":"IS123","mandate":"MD123","mandate_request_mandate":"MD123","new_customer_bank_account":"BA123","new_mandate":"MD123","organisation":"OR123","parent_event":"EV123","payer_authorisation":"PAU123","payment":"PM123","payment_request_payment":"PM123","payout":"PO123","previous_customer_bank_account":"BA123","refund":"RF123","scheme_identifier":"SU123","subscription":"SB123"},"metadata":{},"resource_metadata":{},"resource_type":"mandates"}} } } diff --git a/tests/fixtures/mandates.json b/tests/fixtures/mandates.json index 49d93b5e..1034b0e0 100644 --- a/tests/fixtures/mandates.json +++ b/tests/fixtures/mandates.json @@ -3,36 +3,36 @@ "method": "POST", "path_template": "/mandates", "url_params": [], - "body": {"mandates":{"authorisation_source":"telephone","consent_parameters":{"end_date":"example end_date 3740","max_amount_per_payment":8531,"periods":[{"max_amount_per_period":9731,"max_payments_per_period":2574,"period":"year"}],"start_date":"example start_date 1306"},"created_at":"2014-01-01T12:00:00.000Z","funds_settlement":"managed","id":"MD123","links":{"creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","new_mandate":"MD123"},"metadata":{},"next_possible_charge_date":"2014-10-27","payments_require_approval":false,"reference":"REF-123","scheme":"bacs","status":"pending_submission","verified_at":"2021-01-01T12:00:00.000Z"}} + "body": {"mandates":{"authorisation_source":"telephone","consent_parameters":{"end_date":"example end_date 5048","max_amount_per_payment":5513,"periods":[{"max_amount_per_period":2574,"max_payments_per_period":1306,"period":"week"}],"start_date":"example start_date 3740"},"created_at":"2014-01-01T12:00:00.000Z","funds_settlement":"direct","id":"MD123","links":{"creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","new_mandate":"MD123"},"metadata":{},"next_possible_charge_date":"2014-10-27","payments_require_approval":false,"reference":"REF-123","scheme":"bacs","status":"pending_submission","verified_at":"2021-01-01T12:00:00.000Z"}} }, "list": { "method": "GET", "path_template": "/mandates", "url_params": [], - "body": {"mandates":[{"authorisation_source":"paper","consent_parameters":{"end_date":"example end_date 2332","max_amount_per_payment":2677,"periods":[{"max_amount_per_period":3654,"max_payments_per_period":3483,"period":"month"}],"start_date":"example start_date 4330"},"created_at":"2014-01-01T12:00:00.000Z","funds_settlement":"managed","id":"MD123","links":{"creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","new_mandate":"MD123"},"metadata":{},"next_possible_charge_date":"2014-10-27","payments_require_approval":false,"reference":"REF-123","scheme":"bacs","status":"pending_submission","verified_at":"2021-01-01T12:00:00.000Z"},{"authorisation_source":"web","consent_parameters":{"end_date":"example end_date 6765","max_amount_per_payment":604,"periods":[{"max_amount_per_period":8398,"max_payments_per_period":3421,"period":"year"}],"start_date":"example start_date 8956"},"created_at":"2014-01-01T12:00:00.000Z","funds_settlement":"managed","id":"MD123","links":{"creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","new_mandate":"MD123"},"metadata":{},"next_possible_charge_date":"2014-10-27","payments_require_approval":false,"reference":"REF-123","scheme":"bacs","status":"pending_submission","verified_at":"2021-01-01T12:00:00.000Z"}],"meta":{"cursors":{"after":"example after 6494","before":"example before 45"},"limit":50}} + "body": {"mandates":[{"authorisation_source":"paper","consent_parameters":{"end_date":"example end_date 4187","max_amount_per_payment":5402,"periods":[{"max_amount_per_period":3654,"max_payments_per_period":3483,"period":"day"}],"start_date":"example start_date 2686"},"created_at":"2014-01-01T12:00:00.000Z","funds_settlement":"managed","id":"MD123","links":{"creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","new_mandate":"MD123"},"metadata":{},"next_possible_charge_date":"2014-10-27","payments_require_approval":false,"reference":"REF-123","scheme":"bacs","status":"pending_submission","verified_at":"2021-01-01T12:00:00.000Z"},{"authorisation_source":"web","consent_parameters":{"end_date":"example end_date 8398","max_amount_per_payment":8956,"periods":[{"max_amount_per_period":922,"max_payments_per_period":45,"period":"day"}],"start_date":"example start_date 6494"},"created_at":"2014-01-01T12:00:00.000Z","funds_settlement":"direct","id":"MD123","links":{"creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","new_mandate":"MD123"},"metadata":{},"next_possible_charge_date":"2014-10-27","payments_require_approval":false,"reference":"REF-123","scheme":"bacs","status":"pending_submission","verified_at":"2021-01-01T12:00:00.000Z"}],"meta":{"cursors":{"after":"example after 2332","before":"example before 2677"},"limit":50}} }, "get": { "method": "GET", "path_template": "/mandates/:identity", "url_params": ["MD123"], - "body": {"mandates":{"authorisation_source":"telephone","consent_parameters":{"end_date":"example end_date 8999","max_amount_per_payment":4024,"periods":[{"max_amount_per_period":1420,"max_payments_per_period":2044,"period":"flexible"}],"start_date":"example start_date 4806"},"created_at":"2014-01-01T12:00:00.000Z","funds_settlement":"direct","id":"MD123","links":{"creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","new_mandate":"MD123"},"metadata":{},"next_possible_charge_date":"2014-10-27","payments_require_approval":false,"reference":"REF-123","scheme":"bacs","status":"pending_submission","verified_at":"2021-01-01T12:00:00.000Z"}} + "body": {"mandates":{"authorisation_source":"telephone","consent_parameters":{"end_date":"example end_date 2044","max_amount_per_payment":7759,"periods":[{"max_amount_per_period":4024,"max_payments_per_period":4806,"period":"flexible"}],"start_date":"example start_date 1420"},"created_at":"2014-01-01T12:00:00.000Z","funds_settlement":"managed","id":"MD123","links":{"creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","new_mandate":"MD123"},"metadata":{},"next_possible_charge_date":"2014-10-27","payments_require_approval":false,"reference":"REF-123","scheme":"bacs","status":"pending_submission","verified_at":"2021-01-01T12:00:00.000Z"}} }, "update": { "method": "PUT", "path_template": "/mandates/:identity", "url_params": ["MD123"], - "body": {"mandates":{"authorisation_source":"web","consent_parameters":{"end_date":"example end_date 8089","max_amount_per_payment":5814,"periods":[{"max_amount_per_period":7774,"max_payments_per_period":8475,"period":"year"}],"start_date":"example start_date 5740"},"created_at":"2014-01-01T12:00:00.000Z","funds_settlement":"direct","id":"MD123","links":{"creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","new_mandate":"MD123"},"metadata":{},"next_possible_charge_date":"2014-10-27","payments_require_approval":false,"reference":"REF-123","scheme":"bacs","status":"pending_submission","verified_at":"2021-01-01T12:00:00.000Z"}} + "body": {"mandates":{"authorisation_source":"paper","consent_parameters":{"end_date":"example end_date 8089","max_amount_per_payment":3357,"periods":[{"max_amount_per_period":8475,"max_payments_per_period":8853,"period":"flexible"}],"start_date":"example start_date 5740"},"created_at":"2014-01-01T12:00:00.000Z","funds_settlement":"direct","id":"MD123","links":{"creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","new_mandate":"MD123"},"metadata":{},"next_possible_charge_date":"2014-10-27","payments_require_approval":false,"reference":"REF-123","scheme":"bacs","status":"pending_submission","verified_at":"2021-01-01T12:00:00.000Z"}} }, "cancel": { "method": "POST", "path_template": "/mandates/:identity/actions/cancel", "url_params": ["MD123"], - "body": {"mandates":{"authorisation_source":"paper","consent_parameters":{"end_date":"example end_date 4203","max_amount_per_payment":1581,"periods":[{"max_amount_per_period":6985,"max_payments_per_period":3131,"period":"week"}],"start_date":"example start_date 5629"},"created_at":"2014-01-01T12:00:00.000Z","funds_settlement":"direct","id":"MD123","links":{"creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","new_mandate":"MD123"},"metadata":{},"next_possible_charge_date":"2014-10-27","payments_require_approval":false,"reference":"REF-123","scheme":"bacs","status":"pending_submission","verified_at":"2021-01-01T12:00:00.000Z"}} + "body": {"mandates":{"authorisation_source":"web","consent_parameters":{"end_date":"example end_date 1695","max_amount_per_payment":3131,"periods":[{"max_amount_per_period":5629,"max_payments_per_period":7051,"period":"day"}],"start_date":"example start_date 4203"},"created_at":"2014-01-01T12:00:00.000Z","funds_settlement":"direct","id":"MD123","links":{"creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","new_mandate":"MD123"},"metadata":{},"next_possible_charge_date":"2014-10-27","payments_require_approval":false,"reference":"REF-123","scheme":"bacs","status":"pending_submission","verified_at":"2021-01-01T12:00:00.000Z"}} }, "reinstate": { "method": "POST", "path_template": "/mandates/:identity/actions/reinstate", "url_params": ["MD123"], - "body": {"mandates":{"authorisation_source":"telephone","consent_parameters":{"end_date":"example end_date 8372","max_amount_per_payment":5275,"periods":[{"max_amount_per_period":1262,"max_payments_per_period":973,"period":"month"}],"start_date":"example start_date 7092"},"created_at":"2014-01-01T12:00:00.000Z","funds_settlement":"direct","id":"MD123","links":{"creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","new_mandate":"MD123"},"metadata":{},"next_possible_charge_date":"2014-10-27","payments_require_approval":false,"reference":"REF-123","scheme":"bacs","status":"pending_submission","verified_at":"2021-01-01T12:00:00.000Z"}} + "body": {"mandates":{"authorisation_source":"telephone","consent_parameters":{"end_date":"example end_date 7092","max_amount_per_payment":8372,"periods":[{"max_amount_per_period":5275,"max_payments_per_period":4377,"period":"month"}],"start_date":"example start_date 973"},"created_at":"2014-01-01T12:00:00.000Z","funds_settlement":"direct","id":"MD123","links":{"creditor":"CR123","customer":"CU123","customer_bank_account":"BA123","new_mandate":"MD123"},"metadata":{},"next_possible_charge_date":"2014-10-27","payments_require_approval":false,"reference":"REF-123","scheme":"bacs","status":"pending_submission","verified_at":"2021-01-01T12:00:00.000Z"}} } } diff --git a/tests/fixtures/negative_balance_limits.json b/tests/fixtures/negative_balance_limits.json index 8e55c107..8214e2e8 100644 --- a/tests/fixtures/negative_balance_limits.json +++ b/tests/fixtures/negative_balance_limits.json @@ -3,7 +3,7 @@ "method": "GET", "path_template": "/negative_balance_limits", "url_params": [], - "body": {"meta":{"cursors":{"after":"example after 1406","before":"example before 2205"},"limit":50},"negative_balance_limits":[{"balance_limit":10000,"created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","id":"NBL123","links":{"creator_user":"US123","creditor":"CR123"}},{"balance_limit":10000,"created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","id":"NBL123","links":{"creator_user":"US123","creditor":"CR123"}}]} + "body": {"meta":{"cursors":{"after":"example after 2205","before":"example before 1406"},"limit":50},"negative_balance_limits":[{"balance_limit":10000,"created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","id":"NBL123","links":{"creator_user":"US123","creditor":"CR123"}},{"balance_limit":10000,"created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","id":"NBL123","links":{"creator_user":"US123","creditor":"CR123"}}]} }, "create": { "method": "POST", diff --git a/tests/fixtures/payer_authorisations.json b/tests/fixtures/payer_authorisations.json index d752f7ff..ffb31dc5 100644 --- a/tests/fixtures/payer_authorisations.json +++ b/tests/fixtures/payer_authorisations.json @@ -3,30 +3,30 @@ "method": "GET", "path_template": "/payer_authorisations/:identity", "url_params": ["PA123"], - "body": {"payer_authorisations":{"bank_account":{"account_holder_name":"Billie Jean","account_number":"55779911","account_number_ending":"1234","account_number_suffix":"00","account_type":"savings","bank_code":"example bank_code 894","branch_code":"20-00-00","country_code":"GB","currency":"EUR","iban":"GB60BARC20000055779911","metadata":{}},"created_at":"2020-01-01T12:00:00.000Z","customer":{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","city":"London","company_name":"Hamilton Trading Ltd.","country_code":"GB","danish_identity_number":"220550-6218","email":"user@example.com","family_name":"Osborne","given_name":"Frank","locale":"en-GB","metadata":{},"postal_code":"NW1 6XE","region":"Greater London","swedish_identity_number":"556564-5404"},"id":"PA123","incomplete_fields":[{"field":"example field 2474","message":"example message 3544","request_pointer":"example request_pointer 1723"}],"links":{"bank_account":"BA123","customer":"CU123","mandate":"MD123"},"mandate":{"metadata":{},"payer_ip_address":"127.0.0.1","reference":"REF-123","scheme":"bacs"},"status":"created"}} + "body": {"payer_authorisations":{"bank_account":{"account_holder_name":"Billie Jean","account_number":"55779911","account_number_ending":"1234","account_number_suffix":"00","account_type":"savings","bank_code":"example bank_code 2474","branch_code":"20-00-00","country_code":"GB","currency":"EUR","iban":"GB60BARC20000055779911","metadata":{}},"created_at":"2020-01-01T12:00:00.000Z","customer":{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","city":"London","company_name":"Hamilton Trading Ltd.","country_code":"GB","danish_identity_number":"220550-6218","email":"user@example.com","family_name":"Osborne","given_name":"Frank","locale":"en-GB","metadata":{},"postal_code":"NW1 6XE","region":"Greater London","swedish_identity_number":"556564-5404"},"id":"PA123","incomplete_fields":[{"field":"example field 3544","message":"example message 1723","request_pointer":"example request_pointer 894"}],"links":{"bank_account":"BA123","customer":"CU123","mandate":"MD123"},"mandate":{"metadata":{},"payer_ip_address":"127.0.0.1","reference":"REF-123","scheme":"bacs"},"status":"created"}} }, "create": { "method": "POST", "path_template": "/payer_authorisations", "url_params": [], - "body": {"payer_authorisations":{"bank_account":{"account_holder_name":"Billie Jean","account_number":"55779911","account_number_ending":"1234","account_number_suffix":"00","account_type":"savings","bank_code":"example bank_code 3922","branch_code":"20-00-00","country_code":"GB","currency":"EUR","iban":"GB60BARC20000055779911","metadata":{}},"created_at":"2020-01-01T12:00:00.000Z","customer":{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","city":"London","company_name":"Hamilton Trading Ltd.","country_code":"GB","danish_identity_number":"220550-6218","email":"user@example.com","family_name":"Osborne","given_name":"Frank","locale":"en-GB","metadata":{},"postal_code":"NW1 6XE","region":"Greater London","swedish_identity_number":"556564-5404"},"id":"PA123","incomplete_fields":[{"field":"example field 7574","message":"example message 8610","request_pointer":"example request_pointer 8033"}],"links":{"bank_account":"BA123","customer":"CU123","mandate":"MD123"},"mandate":{"metadata":{},"payer_ip_address":"127.0.0.1","reference":"REF-123","scheme":"bacs"},"status":"created"}} + "body": {"payer_authorisations":{"bank_account":{"account_holder_name":"Billie Jean","account_number":"55779911","account_number_ending":"1234","account_number_suffix":"00","account_type":"savings","bank_code":"example bank_code 8610","branch_code":"20-00-00","country_code":"GB","currency":"EUR","iban":"GB60BARC20000055779911","metadata":{}},"created_at":"2020-01-01T12:00:00.000Z","customer":{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","city":"London","company_name":"Hamilton Trading Ltd.","country_code":"GB","danish_identity_number":"220550-6218","email":"user@example.com","family_name":"Osborne","given_name":"Frank","locale":"en-GB","metadata":{},"postal_code":"NW1 6XE","region":"Greater London","swedish_identity_number":"556564-5404"},"id":"PA123","incomplete_fields":[{"field":"example field 7574","message":"example message 3922","request_pointer":"example request_pointer 8033"}],"links":{"bank_account":"BA123","customer":"CU123","mandate":"MD123"},"mandate":{"metadata":{},"payer_ip_address":"127.0.0.1","reference":"REF-123","scheme":"bacs"},"status":"created"}} }, "update": { "method": "PUT", "path_template": "/payer_authorisations/:identity", "url_params": ["PA123"], - "body": {"payer_authorisations":{"bank_account":{"account_holder_name":"Billie Jean","account_number":"55779911","account_number_ending":"1234","account_number_suffix":"00","account_type":"savings","bank_code":"example bank_code 30","branch_code":"20-00-00","country_code":"GB","currency":"EUR","iban":"GB60BARC20000055779911","metadata":{}},"created_at":"2020-01-01T12:00:00.000Z","customer":{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","city":"London","company_name":"Hamilton Trading Ltd.","country_code":"GB","danish_identity_number":"220550-6218","email":"user@example.com","family_name":"Osborne","given_name":"Frank","locale":"en-GB","metadata":{},"postal_code":"NW1 6XE","region":"Greater London","swedish_identity_number":"556564-5404"},"id":"PA123","incomplete_fields":[{"field":"example field 9914","message":"example message 2523","request_pointer":"example request_pointer 5395"}],"links":{"bank_account":"BA123","customer":"CU123","mandate":"MD123"},"mandate":{"metadata":{},"payer_ip_address":"127.0.0.1","reference":"REF-123","scheme":"bacs"},"status":"created"}} + "body": {"payer_authorisations":{"bank_account":{"account_holder_name":"Billie Jean","account_number":"55779911","account_number_ending":"1234","account_number_suffix":"00","account_type":"savings","bank_code":"example bank_code 30","branch_code":"20-00-00","country_code":"GB","currency":"EUR","iban":"GB60BARC20000055779911","metadata":{}},"created_at":"2020-01-01T12:00:00.000Z","customer":{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","city":"London","company_name":"Hamilton Trading Ltd.","country_code":"GB","danish_identity_number":"220550-6218","email":"user@example.com","family_name":"Osborne","given_name":"Frank","locale":"en-GB","metadata":{},"postal_code":"NW1 6XE","region":"Greater London","swedish_identity_number":"556564-5404"},"id":"PA123","incomplete_fields":[{"field":"example field 5395","message":"example message 9914","request_pointer":"example request_pointer 2523"}],"links":{"bank_account":"BA123","customer":"CU123","mandate":"MD123"},"mandate":{"metadata":{},"payer_ip_address":"127.0.0.1","reference":"REF-123","scheme":"bacs"},"status":"created"}} }, "submit": { "method": "POST", "path_template": "/payer_authorisations/:identity/actions/submit", "url_params": ["PA123"], - "body": {"payer_authorisations":{"bank_account":{"account_holder_name":"Billie Jean","account_number":"55779911","account_number_ending":"1234","account_number_suffix":"00","account_type":"savings","bank_code":"example bank_code 7650","branch_code":"20-00-00","country_code":"GB","currency":"EUR","iban":"GB60BARC20000055779911","metadata":{}},"created_at":"2020-01-01T12:00:00.000Z","customer":{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","city":"London","company_name":"Hamilton Trading Ltd.","country_code":"GB","danish_identity_number":"220550-6218","email":"user@example.com","family_name":"Osborne","given_name":"Frank","locale":"en-GB","metadata":{},"postal_code":"NW1 6XE","region":"Greater London","swedish_identity_number":"556564-5404"},"id":"PA123","incomplete_fields":[{"field":"example field 909","message":"example message 9277","request_pointer":"example request_pointer 5645"}],"links":{"bank_account":"BA123","customer":"CU123","mandate":"MD123"},"mandate":{"metadata":{},"payer_ip_address":"127.0.0.1","reference":"REF-123","scheme":"bacs"},"status":"created"}} + "body": {"payer_authorisations":{"bank_account":{"account_holder_name":"Billie Jean","account_number":"55779911","account_number_ending":"1234","account_number_suffix":"00","account_type":"savings","bank_code":"example bank_code 5645","branch_code":"20-00-00","country_code":"GB","currency":"EUR","iban":"GB60BARC20000055779911","metadata":{}},"created_at":"2020-01-01T12:00:00.000Z","customer":{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","city":"London","company_name":"Hamilton Trading Ltd.","country_code":"GB","danish_identity_number":"220550-6218","email":"user@example.com","family_name":"Osborne","given_name":"Frank","locale":"en-GB","metadata":{},"postal_code":"NW1 6XE","region":"Greater London","swedish_identity_number":"556564-5404"},"id":"PA123","incomplete_fields":[{"field":"example field 7650","message":"example message 909","request_pointer":"example request_pointer 9277"}],"links":{"bank_account":"BA123","customer":"CU123","mandate":"MD123"},"mandate":{"metadata":{},"payer_ip_address":"127.0.0.1","reference":"REF-123","scheme":"bacs"},"status":"created"}} }, "confirm": { "method": "POST", "path_template": "/payer_authorisations/:identity/actions/confirm", "url_params": ["PA123"], - "body": {"payer_authorisations":{"bank_account":{"account_holder_name":"Billie Jean","account_number":"55779911","account_number_ending":"1234","account_number_suffix":"00","account_type":"savings","bank_code":"example bank_code 2734","branch_code":"20-00-00","country_code":"GB","currency":"EUR","iban":"GB60BARC20000055779911","metadata":{}},"created_at":"2020-01-01T12:00:00.000Z","customer":{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","city":"London","company_name":"Hamilton Trading Ltd.","country_code":"GB","danish_identity_number":"220550-6218","email":"user@example.com","family_name":"Osborne","given_name":"Frank","locale":"en-GB","metadata":{},"postal_code":"NW1 6XE","region":"Greater London","swedish_identity_number":"556564-5404"},"id":"PA123","incomplete_fields":[{"field":"example field 7208","message":"example message 8198","request_pointer":"example request_pointer 671"}],"links":{"bank_account":"BA123","customer":"CU123","mandate":"MD123"},"mandate":{"metadata":{},"payer_ip_address":"127.0.0.1","reference":"REF-123","scheme":"bacs"},"status":"created"}} + "body": {"payer_authorisations":{"bank_account":{"account_holder_name":"Billie Jean","account_number":"55779911","account_number_ending":"1234","account_number_suffix":"00","account_type":"savings","bank_code":"example bank_code 671","branch_code":"20-00-00","country_code":"GB","currency":"EUR","iban":"GB60BARC20000055779911","metadata":{}},"created_at":"2020-01-01T12:00:00.000Z","customer":{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","city":"London","company_name":"Hamilton Trading Ltd.","country_code":"GB","danish_identity_number":"220550-6218","email":"user@example.com","family_name":"Osborne","given_name":"Frank","locale":"en-GB","metadata":{},"postal_code":"NW1 6XE","region":"Greater London","swedish_identity_number":"556564-5404"},"id":"PA123","incomplete_fields":[{"field":"example field 7208","message":"example message 8198","request_pointer":"example request_pointer 2734"}],"links":{"bank_account":"BA123","customer":"CU123","mandate":"MD123"},"mandate":{"metadata":{},"payer_ip_address":"127.0.0.1","reference":"REF-123","scheme":"bacs"},"status":"created"}} } } diff --git a/tests/fixtures/payments.json b/tests/fixtures/payments.json index 69016f2c..2e8d79c1 100644 --- a/tests/fixtures/payments.json +++ b/tests/fixtures/payments.json @@ -9,7 +9,7 @@ "method": "GET", "path_template": "/payments", "url_params": [], - "body": {"meta":{"cursors":{"after":"example after 7587","before":"example before 9326"},"limit":50},"payments":[{"amount":1000,"amount_refunded":150,"charge_date":"2014-05-21","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","description":"One-off upgrade fee","fx":{"estimated_exchange_rate":"1.1234567890","exchange_rate":"1.1234567890","fx_amount":1150,"fx_currency":"EUR"},"id":"PM123","links":{"creditor":"CR123","instalment_schedule":"IS123","mandate":"MD123","payout":"PO123","subscription":"SU123"},"metadata":{},"reference":"WINEBOX001","retry_if_possible":false,"status":"submitted"},{"amount":1000,"amount_refunded":150,"charge_date":"2014-05-21","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","description":"One-off upgrade fee","fx":{"estimated_exchange_rate":"1.1234567890","exchange_rate":"1.1234567890","fx_amount":1150,"fx_currency":"EUR"},"id":"PM123","links":{"creditor":"CR123","instalment_schedule":"IS123","mandate":"MD123","payout":"PO123","subscription":"SU123"},"metadata":{},"reference":"WINEBOX001","retry_if_possible":true,"status":"submitted"}]} + "body": {"meta":{"cursors":{"after":"example after 9326","before":"example before 7587"},"limit":50},"payments":[{"amount":1000,"amount_refunded":150,"charge_date":"2014-05-21","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","description":"One-off upgrade fee","fx":{"estimated_exchange_rate":"1.1234567890","exchange_rate":"1.1234567890","fx_amount":1150,"fx_currency":"EUR"},"id":"PM123","links":{"creditor":"CR123","instalment_schedule":"IS123","mandate":"MD123","payout":"PO123","subscription":"SU123"},"metadata":{},"reference":"WINEBOX001","retry_if_possible":false,"status":"submitted"},{"amount":1000,"amount_refunded":150,"charge_date":"2014-05-21","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","description":"One-off upgrade fee","fx":{"estimated_exchange_rate":"1.1234567890","exchange_rate":"1.1234567890","fx_amount":1150,"fx_currency":"EUR"},"id":"PM123","links":{"creditor":"CR123","instalment_schedule":"IS123","mandate":"MD123","payout":"PO123","subscription":"SU123"},"metadata":{},"reference":"WINEBOX001","retry_if_possible":true,"status":"submitted"}]} }, "get": { "method": "GET", diff --git a/tests/fixtures/payout_items.json b/tests/fixtures/payout_items.json index 7096cbea..6aa33147 100644 --- a/tests/fixtures/payout_items.json +++ b/tests/fixtures/payout_items.json @@ -3,6 +3,6 @@ "method": "GET", "path_template": "/payout_items", "url_params": [], - "body": {"meta":{"cursors":{"after":"example after 8374","before":"example before 3920"},"limit":50},"payout_items":[{"amount":"45.0","links":{"mandate":"MD123","payment":"PM123","refund":"RF123"},"taxes":[{"amount":"1.1","currency":"EUR","destination_amount":"1.1","destination_currency":"EUR","exchange_rate":"1.11205","tax_rate_id":"GB_VAT_1"}],"type":"payment_paid_out"},{"amount":"45.0","links":{"mandate":"MD123","payment":"PM123","refund":"RF123"},"taxes":[{"amount":"1.1","currency":"EUR","destination_amount":"1.1","destination_currency":"EUR","exchange_rate":"1.11205","tax_rate_id":"GB_VAT_1"}],"type":"payment_paid_out"}]} + "body": {"meta":{"cursors":{"after":"example after 3920","before":"example before 8374"},"limit":50},"payout_items":[{"amount":"45.0","links":{"mandate":"MD123","payment":"PM123","refund":"RF123"},"taxes":[{"amount":"1.1","currency":"EUR","destination_amount":"1.1","destination_currency":"EUR","exchange_rate":"1.11205","tax_rate_id":"GB_VAT_1"}],"type":"payment_paid_out"},{"amount":"45.0","links":{"mandate":"MD123","payment":"PM123","refund":"RF123"},"taxes":[{"amount":"1.1","currency":"EUR","destination_amount":"1.1","destination_currency":"EUR","exchange_rate":"1.11205","tax_rate_id":"GB_VAT_1"}],"type":"payment_paid_out"}]} } } diff --git a/tests/fixtures/scheme_identifiers.json b/tests/fixtures/scheme_identifiers.json index ff42ee48..dfd8416f 100644 --- a/tests/fixtures/scheme_identifiers.json +++ b/tests/fixtures/scheme_identifiers.json @@ -9,7 +9,7 @@ "method": "GET", "path_template": "/scheme_identifiers", "url_params": [], - "body": {"meta":{"cursors":{"after":"example after 1446","before":"example before 325"},"limit":50},"scheme_identifiers":[{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","can_specify_mandate_reference":false,"city":"London","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","email":"user@example.com","id":"SU123","minimum_advance_notice":3,"name":"example name 7913","phone_number":"+44 20 1234 1234","postal_code":"NW1 6XE","reference":"example reference 6872","region":"Greater London","scheme":"bacs","status":"pending"},{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","can_specify_mandate_reference":false,"city":"London","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","email":"user@example.com","id":"SU123","minimum_advance_notice":3,"name":"example name 5214","phone_number":"+44 20 1234 1234","postal_code":"NW1 6XE","reference":"example reference 9959","region":"Greater London","scheme":"bacs","status":"pending"}]} + "body": {"meta":{"cursors":{"after":"example after 1446","before":"example before 325"},"limit":50},"scheme_identifiers":[{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","can_specify_mandate_reference":false,"city":"London","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","email":"user@example.com","id":"SU123","minimum_advance_notice":3,"name":"example name 7913","phone_number":"+44 20 1234 1234","postal_code":"NW1 6XE","reference":"example reference 6872","region":"Greater London","scheme":"bacs","status":"pending"},{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","can_specify_mandate_reference":false,"city":"London","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","email":"user@example.com","id":"SU123","minimum_advance_notice":3,"name":"example name 9959","phone_number":"+44 20 1234 1234","postal_code":"NW1 6XE","reference":"example reference 5214","region":"Greater London","scheme":"bacs","status":"pending"}]} }, "get": { "method": "GET", diff --git a/tests/fixtures/subscriptions.json b/tests/fixtures/subscriptions.json index 3244316b..87a51e1d 100644 --- a/tests/fixtures/subscriptions.json +++ b/tests/fixtures/subscriptions.json @@ -9,7 +9,7 @@ "method": "GET", "path_template": "/subscriptions", "url_params": [], - "body": {"meta":{"cursors":{"after":"example after 8223","before":"example before 1488"},"limit":50},"subscriptions":[{"amount":1000,"app_fee":100,"count":5,"created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","day_of_month":28,"earliest_charge_date_after_resume":"2014-11-03","end_date":"2015-10-21","id":"SB123","interval":1,"interval_unit":"monthly","links":{"mandate":"MD123"},"metadata":{},"month":"january","name":"12 month subscription","payment_reference":"GOLDPLAN","retry_if_possible":false,"start_date":"2014-10-21","status":"active","upcoming_payments":[{"amount":2500,"charge_date":"2014-11-03"}]},{"amount":1000,"app_fee":100,"count":5,"created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","day_of_month":28,"earliest_charge_date_after_resume":"2014-11-03","end_date":"2015-10-21","id":"SB123","interval":1,"interval_unit":"monthly","links":{"mandate":"MD123"},"metadata":{},"month":"january","name":"12 month subscription","payment_reference":"GOLDPLAN","retry_if_possible":true,"start_date":"2014-10-21","status":"active","upcoming_payments":[{"amount":2500,"charge_date":"2014-11-03"}]}]} + "body": {"meta":{"cursors":{"after":"example after 6487","before":"example before 1436"},"limit":50},"subscriptions":[{"amount":1000,"app_fee":100,"count":5,"created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","day_of_month":28,"earliest_charge_date_after_resume":"2014-11-03","end_date":"2015-10-21","id":"SB123","interval":1,"interval_unit":"monthly","links":{"mandate":"MD123"},"metadata":{},"month":"january","name":"12 month subscription","payment_reference":"GOLDPLAN","retry_if_possible":false,"start_date":"2014-10-21","status":"active","upcoming_payments":[{"amount":2500,"charge_date":"2014-11-03"}]},{"amount":1000,"app_fee":100,"count":5,"created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","day_of_month":28,"earliest_charge_date_after_resume":"2014-11-03","end_date":"2015-10-21","id":"SB123","interval":1,"interval_unit":"monthly","links":{"mandate":"MD123"},"metadata":{},"month":"january","name":"12 month subscription","payment_reference":"GOLDPLAN","retry_if_possible":false,"start_date":"2014-10-21","status":"active","upcoming_payments":[{"amount":2500,"charge_date":"2014-11-03"}]}]} }, "get": { "method": "GET", diff --git a/tests/fixtures/tax_rates.json b/tests/fixtures/tax_rates.json index 0aabf6a3..0407d9af 100644 --- a/tests/fixtures/tax_rates.json +++ b/tests/fixtures/tax_rates.json @@ -3,7 +3,7 @@ "method": "GET", "path_template": "/tax_rates", "url_params": [], - "body": {"meta":{"cursors":{"after":"example after 3176","before":"example before 8730"},"limit":50},"tax_rates":[{"end_date":"2014-01-01","id":"GB_VAT_1","jurisdiction":"GBP","percentage":"20.0","start_date":"2014-01-01","type":"VAT"},{"end_date":"2014-01-01","id":"GB_VAT_1","jurisdiction":"GBP","percentage":"20.0","start_date":"2014-01-01","type":"VAT"}]} + "body": {"meta":{"cursors":{"after":"example after 8730","before":"example before 3176"},"limit":50},"tax_rates":[{"end_date":"2014-01-01","id":"GB_VAT_1","jurisdiction":"GBP","percentage":"20.0","start_date":"2014-01-01","type":"VAT"},{"end_date":"2014-01-01","id":"GB_VAT_1","jurisdiction":"GBP","percentage":"20.0","start_date":"2014-01-01","type":"VAT"}]} }, "get": { "method": "GET", diff --git a/tests/fixtures/validation_failed_error.json b/tests/fixtures/validation_failed_error.json index a02a01f3..56163fe6 100644 --- a/tests/fixtures/validation_failed_error.json +++ b/tests/fixtures/validation_failed_error.json @@ -8,10 +8,12 @@ "errors": [ { "message": "must be a number", - "field": "branch_code" + "field": "branch_code", + "request_pointer": "/customer_bank_accounts/branch_code" }, { "message": "is invalid", - "field": "country_code" + "field": "country_code", + "request_pointer": "/customer_bank_accounts/country_code" } ] } diff --git a/tests/fixtures/verification_details.json b/tests/fixtures/verification_details.json index 715eafe4..5a30ab60 100644 --- a/tests/fixtures/verification_details.json +++ b/tests/fixtures/verification_details.json @@ -3,12 +3,12 @@ "method": "POST", "path_template": "/verification_details", "url_params": [], - "body": {"verification_details":{"address_line1":"338-346 Goswell Road","address_line2":"Islington","address_line3":"example address_line3 8051","city":"London","company_number":"07495895","description":"Wine and cheese seller","directors":[{"city":"London","country_code":"GB","date_of_birth":"1986-02-19","family_name":"Jones","given_name":"Tom","postal_code":"EC1V 7LQ","street":"example street 1300"}],"links":{"creditor":"CR123"},"name":"Acme Limited","postal_code":"EC1V 7LQ"}} + "body": {"verification_details":{"address_line1":"338-346 Goswell Road","address_line2":"Islington","address_line3":"example address_line3 1300","city":"London","company_number":"07495895","description":"Wine and cheese seller","directors":[{"city":"London","country_code":"GB","date_of_birth":"1986-02-19","family_name":"Jones","given_name":"Tom","postal_code":"EC1V 7LQ","street":"example street 8051"}],"links":{"creditor":"CR123"},"name":"Acme Limited","postal_code":"EC1V 7LQ"}} }, "list": { "method": "GET", "path_template": "/verification_details", "url_params": [], - "body": {"meta":{"cursors":{"after":"example after 7045","before":"example before 541"},"limit":50},"verification_details":[{"address_line1":"338-346 Goswell Road","address_line2":"Islington","address_line3":"example address_line3 8619","city":"London","company_number":"07495895","description":"Wine and cheese seller","directors":[{"city":"London","country_code":"GB","date_of_birth":"1986-02-19","family_name":"Jones","given_name":"Tom","postal_code":"EC1V 7LQ","street":"example street 9434"}],"links":{"creditor":"CR123"},"name":"Acme Limited","postal_code":"EC1V 7LQ"},{"address_line1":"338-346 Goswell Road","address_line2":"Islington","address_line3":"example address_line3 913","city":"London","company_number":"07495895","description":"Wine and cheese seller","directors":[{"city":"London","country_code":"GB","date_of_birth":"1986-02-19","family_name":"Jones","given_name":"Tom","postal_code":"EC1V 7LQ","street":"example street 5666"}],"links":{"creditor":"CR123"},"name":"Acme Limited","postal_code":"EC1V 7LQ"}]} + "body": {"meta":{"cursors":{"after":"example after 7045","before":"example before 541"},"limit":50},"verification_details":[{"address_line1":"338-346 Goswell Road","address_line2":"Islington","address_line3":"example address_line3 8619","city":"London","company_number":"07495895","description":"Wine and cheese seller","directors":[{"city":"London","country_code":"GB","date_of_birth":"1986-02-19","family_name":"Jones","given_name":"Tom","postal_code":"EC1V 7LQ","street":"example street 9434"}],"links":{"creditor":"CR123"},"name":"Acme Limited","postal_code":"EC1V 7LQ"},{"address_line1":"338-346 Goswell Road","address_line2":"Islington","address_line3":"example address_line3 5666","city":"London","company_number":"07495895","description":"Wine and cheese seller","directors":[{"city":"London","country_code":"GB","date_of_birth":"1986-02-19","family_name":"Jones","given_name":"Tom","postal_code":"EC1V 7LQ","street":"example street 913"}],"links":{"creditor":"CR123"},"name":"Acme Limited","postal_code":"EC1V 7LQ"}]} } } diff --git a/tests/fixtures/webhooks.json b/tests/fixtures/webhooks.json index c5490bd2..a31a3c51 100644 --- a/tests/fixtures/webhooks.json +++ b/tests/fixtures/webhooks.json @@ -3,18 +3,18 @@ "method": "GET", "path_template": "/webhooks", "url_params": [], - "body": {"meta":{"cursors":{"after":"example after 3322","before":"example before 2516"},"limit":50},"webhooks":[{"created_at":"2014-01-01T12:00:00.000Z","id":"WB123","is_test":true,"request_body":"example request_body 2239","request_headers":{},"response_body":"example response_body 7694","response_body_truncated":false,"response_code":6574,"response_headers":{},"response_headers_content_truncated":false,"response_headers_count_truncated":false,"successful":false,"url":"https://example.com/webhooks"},{"created_at":"2014-01-01T12:00:00.000Z","id":"WB123","is_test":false,"request_body":"example request_body 6216","request_headers":{},"response_body":"example response_body 1582","response_body_truncated":true,"response_code":9719,"response_headers":{},"response_headers_content_truncated":true,"response_headers_count_truncated":false,"successful":false,"url":"https://example.com/webhooks"}]} + "body": {"meta":{"cursors":{"after":"example after 3322","before":"example before 2516"},"limit":50},"webhooks":[{"created_at":"2014-01-01T12:00:00.000Z","id":"WB123","is_test":false,"request_body":"example request_body 6574","request_headers":{},"response_body":"example response_body 5642","response_body_truncated":false,"response_code":2239,"response_headers":{},"response_headers_content_truncated":false,"response_headers_count_truncated":true,"successful":false,"url":"https://example.com/webhooks"},{"created_at":"2014-01-01T12:00:00.000Z","id":"WB123","is_test":true,"request_body":"example request_body 6316","request_headers":{},"response_body":"example response_body 2088","response_body_truncated":false,"response_code":6813,"response_headers":{},"response_headers_content_truncated":true,"response_headers_count_truncated":false,"successful":false,"url":"https://example.com/webhooks"}]} }, "get": { "method": "GET", "path_template": "/webhooks/:identity", "url_params": ["WB123"], - "body": {"webhooks":{"created_at":"2014-01-01T12:00:00.000Z","id":"WB123","is_test":false,"request_body":"example request_body 9277","request_headers":{},"response_body":"example response_body 6301","response_body_truncated":true,"response_code":3963,"response_headers":{},"response_headers_content_truncated":false,"response_headers_count_truncated":false,"successful":false,"url":"https://example.com/webhooks"}} + "body": {"webhooks":{"created_at":"2014-01-01T12:00:00.000Z","id":"WB123","is_test":true,"request_body":"example request_body 9277","request_headers":{},"response_body":"example response_body 6301","response_body_truncated":false,"response_code":9555,"response_headers":{},"response_headers_content_truncated":false,"response_headers_count_truncated":false,"successful":true,"url":"https://example.com/webhooks"}} }, "retry": { "method": "POST", "path_template": "/webhooks/:identity/actions/retry", "url_params": ["WB123"], - "body": {"webhooks":{"created_at":"2014-01-01T12:00:00.000Z","id":"WB123","is_test":false,"request_body":"example request_body 3333","request_headers":{},"response_body":"example response_body 3875","response_body_truncated":false,"response_code":1552,"response_headers":{},"response_headers_content_truncated":false,"response_headers_count_truncated":true,"successful":true,"url":"https://example.com/webhooks"}} + "body": {"webhooks":{"created_at":"2014-01-01T12:00:00.000Z","id":"WB123","is_test":false,"request_body":"example request_body 7627","request_headers":{},"response_body":"example response_body 4534","response_body_truncated":false,"response_code":1552,"response_headers":{},"response_headers_content_truncated":false,"response_headers_count_truncated":false,"successful":false,"url":"https://example.com/webhooks"}} } } diff --git a/tests/integration/bank_authorisations_integration_test.py b/tests/integration/bank_authorisations_integration_test.py index 47b2e29e..3788e442 100644 --- a/tests/integration/bank_authorisations_integration_test.py +++ b/tests/integration/bank_authorisations_integration_test.py @@ -5,16 +5,9 @@ import json +import pytest import requests import responses -from nose.tools import ( - assert_equal, - assert_is_instance, - assert_is_none, - assert_is_not_none, - assert_not_equal, - assert_raises -) from gocardless_pro.errors import MalformedResponseError from gocardless_pro import resources @@ -30,21 +23,19 @@ def test_bank_authorisations_create(): response = helpers.client.bank_authorisations.create(*fixture['url_params']) body = fixture['body']['bank_authorisations'] - assert_is_instance(response, resources.BankAuthorisation) - assert_is_not_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal(response.authorisation_type, body.get('authorisation_type')) - assert_equal(response.authorised_at, body.get('authorised_at')) - assert_equal(response.created_at, body.get('created_at')) - assert_equal(response.expires_at, body.get('expires_at')) - assert_equal(response.id, body.get('id')) - assert_equal(response.last_visited_at, body.get('last_visited_at')) - assert_equal(response.qr_code_url, body.get('qr_code_url')) - assert_equal(response.redirect_uri, body.get('redirect_uri')) - assert_equal(response.url, body.get('url')) - assert_equal(response.links.billing_request, - body.get('links')['billing_request']) - assert_equal(response.links.institution, - body.get('links')['institution']) + assert isinstance(response, resources.BankAuthorisation) + assert responses.calls[-1].request.headers.get('Idempotency-Key') is not None + assert response.authorisation_type == body.get('authorisation_type') + assert response.authorised_at == body.get('authorised_at') + assert response.created_at == body.get('created_at') + assert response.expires_at == body.get('expires_at') + assert response.id == body.get('id') + assert response.last_visited_at == body.get('last_visited_at') + assert response.qr_code_url == body.get('qr_code_url') + assert response.redirect_uri == body.get('redirect_uri') + assert response.url == body.get('url') + assert response.links.billing_request == body.get('links')['billing_request'] + assert response.links.institution == body.get('links')['institution'] @responses.activate def test_bank_authorisations_create_new_idempotency_key_for_each_call(): @@ -52,40 +43,37 @@ def test_bank_authorisations_create_new_idempotency_key_for_each_call(): helpers.stub_response(fixture) helpers.client.bank_authorisations.create(*fixture['url_params']) helpers.client.bank_authorisations.create(*fixture['url_params']) - assert_not_equal(responses.calls[0].request.headers.get('Idempotency-Key'), - responses.calls[1].request.headers.get('Idempotency-Key')) + assert responses.calls[0].request.headers.get('Idempotency-Key') != responses.calls[1].request.headers.get('Idempotency-Key') def test_timeout_bank_authorisations_create_idempotency_conflict(): create_fixture = helpers.load_fixture('bank_authorisations')['create'] get_fixture = helpers.load_fixture('bank_authorisations')['get'] with helpers.stub_timeout_then_idempotency_conflict(create_fixture, get_fixture) as rsps: response = helpers.client.bank_authorisations.create(*create_fixture['url_params']) - assert_equal(2, len(rsps.calls)) + assert len(rsps.calls) == 2 - assert_is_instance(response, resources.BankAuthorisation) + assert isinstance(response, resources.BankAuthorisation) @responses.activate def test_timeout_bank_authorisations_create_retries(): fixture = helpers.load_fixture('bank_authorisations')['create'] with helpers.stub_timeout_then_response(fixture) as rsps: response = helpers.client.bank_authorisations.create(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['bank_authorisations'] - assert_is_instance(response, resources.BankAuthorisation) + assert isinstance(response, resources.BankAuthorisation) def test_502_bank_authorisations_create_retries(): fixture = helpers.load_fixture('bank_authorisations')['create'] with helpers.stub_502_then_response(fixture) as rsps: response = helpers.client.bank_authorisations.create(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['bank_authorisations'] - assert_is_instance(response, resources.BankAuthorisation) + assert isinstance(response, resources.BankAuthorisation) @responses.activate @@ -95,42 +83,38 @@ def test_bank_authorisations_get(): response = helpers.client.bank_authorisations.get(*fixture['url_params']) body = fixture['body']['bank_authorisations'] - assert_is_instance(response, resources.BankAuthorisation) - assert_is_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal(response.authorisation_type, body.get('authorisation_type')) - assert_equal(response.authorised_at, body.get('authorised_at')) - assert_equal(response.created_at, body.get('created_at')) - assert_equal(response.expires_at, body.get('expires_at')) - assert_equal(response.id, body.get('id')) - assert_equal(response.last_visited_at, body.get('last_visited_at')) - assert_equal(response.qr_code_url, body.get('qr_code_url')) - assert_equal(response.redirect_uri, body.get('redirect_uri')) - assert_equal(response.url, body.get('url')) - assert_equal(response.links.billing_request, - body.get('links')['billing_request']) - assert_equal(response.links.institution, - body.get('links')['institution']) + assert isinstance(response, resources.BankAuthorisation) + assert responses.calls[-1].request.headers.get('Idempotency-Key') is None + assert response.authorisation_type == body.get('authorisation_type') + assert response.authorised_at == body.get('authorised_at') + assert response.created_at == body.get('created_at') + assert response.expires_at == body.get('expires_at') + assert response.id == body.get('id') + assert response.last_visited_at == body.get('last_visited_at') + assert response.qr_code_url == body.get('qr_code_url') + assert response.redirect_uri == body.get('redirect_uri') + assert response.url == body.get('url') + assert response.links.billing_request == body.get('links')['billing_request'] + assert response.links.institution == body.get('links')['institution'] @responses.activate def test_timeout_bank_authorisations_get_retries(): fixture = helpers.load_fixture('bank_authorisations')['get'] with helpers.stub_timeout_then_response(fixture) as rsps: response = helpers.client.bank_authorisations.get(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['bank_authorisations'] - assert_is_instance(response, resources.BankAuthorisation) + assert isinstance(response, resources.BankAuthorisation) def test_502_bank_authorisations_get_retries(): fixture = helpers.load_fixture('bank_authorisations')['get'] with helpers.stub_502_then_response(fixture) as rsps: response = helpers.client.bank_authorisations.get(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['bank_authorisations'] - assert_is_instance(response, resources.BankAuthorisation) + assert isinstance(response, resources.BankAuthorisation) diff --git a/tests/integration/bank_details_lookups_integration_test.py b/tests/integration/bank_details_lookups_integration_test.py index fdf4227f..90d9d271 100644 --- a/tests/integration/bank_details_lookups_integration_test.py +++ b/tests/integration/bank_details_lookups_integration_test.py @@ -5,16 +5,9 @@ import json +import pytest import requests import responses -from nose.tools import ( - assert_equal, - assert_is_instance, - assert_is_none, - assert_is_not_none, - assert_not_equal, - assert_raises -) from gocardless_pro.errors import MalformedResponseError from gocardless_pro import resources @@ -30,32 +23,30 @@ def test_bank_details_lookups_create(): response = helpers.client.bank_details_lookups.create(*fixture['url_params']) body = fixture['body']['bank_details_lookups'] - assert_is_instance(response, resources.BankDetailsLookup) - assert_is_not_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal(response.available_debit_schemes, body.get('available_debit_schemes')) - assert_equal(response.bank_name, body.get('bank_name')) - assert_equal(response.bic, body.get('bic')) + assert isinstance(response, resources.BankDetailsLookup) + assert responses.calls[-1].request.headers.get('Idempotency-Key') is not None + assert response.available_debit_schemes == body.get('available_debit_schemes') + assert response.bank_name == body.get('bank_name') + assert response.bic == body.get('bic') @responses.activate def test_timeout_bank_details_lookups_create_retries(): fixture = helpers.load_fixture('bank_details_lookups')['create'] with helpers.stub_timeout_then_response(fixture) as rsps: response = helpers.client.bank_details_lookups.create(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['bank_details_lookups'] - assert_is_instance(response, resources.BankDetailsLookup) + assert isinstance(response, resources.BankDetailsLookup) def test_502_bank_details_lookups_create_retries(): fixture = helpers.load_fixture('bank_details_lookups')['create'] with helpers.stub_502_then_response(fixture) as rsps: response = helpers.client.bank_details_lookups.create(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['bank_details_lookups'] - assert_is_instance(response, resources.BankDetailsLookup) + assert isinstance(response, resources.BankDetailsLookup) diff --git a/tests/integration/billing_request_flows_integration_test.py b/tests/integration/billing_request_flows_integration_test.py index b50d9865..2e5af1b5 100644 --- a/tests/integration/billing_request_flows_integration_test.py +++ b/tests/integration/billing_request_flows_integration_test.py @@ -5,16 +5,9 @@ import json +import pytest import requests import responses -from nose.tools import ( - assert_equal, - assert_is_instance, - assert_is_none, - assert_is_not_none, - assert_not_equal, - assert_raises -) from gocardless_pro.errors import MalformedResponseError from gocardless_pro import resources @@ -30,75 +23,58 @@ def test_billing_request_flows_create(): response = helpers.client.billing_request_flows.create(*fixture['url_params']) body = fixture['body']['billing_request_flows'] - assert_is_instance(response, resources.BillingRequestFlow) - assert_is_not_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal(response.authorisation_url, body.get('authorisation_url')) - assert_equal(response.auto_fulfil, body.get('auto_fulfil')) - assert_equal(response.created_at, body.get('created_at')) - assert_equal(response.exit_uri, body.get('exit_uri')) - assert_equal(response.expires_at, body.get('expires_at')) - assert_equal(response.id, body.get('id')) - assert_equal(response.language, body.get('language')) - assert_equal(response.lock_bank_account, body.get('lock_bank_account')) - assert_equal(response.lock_currency, body.get('lock_currency')) - assert_equal(response.lock_customer_details, body.get('lock_customer_details')) - assert_equal(response.redirect_uri, body.get('redirect_uri')) - assert_equal(response.session_token, body.get('session_token')) - assert_equal(response.show_redirect_buttons, body.get('show_redirect_buttons')) - assert_equal(response.show_success_redirect_button, body.get('show_success_redirect_button')) - assert_equal(response.links.billing_request, - body.get('links')['billing_request']) - assert_equal(response.prefilled_bank_account.account_type, - body.get('prefilled_bank_account')['account_type']) - assert_equal(response.prefilled_customer.address_line1, - body.get('prefilled_customer')['address_line1']) - assert_equal(response.prefilled_customer.address_line2, - body.get('prefilled_customer')['address_line2']) - assert_equal(response.prefilled_customer.address_line3, - body.get('prefilled_customer')['address_line3']) - assert_equal(response.prefilled_customer.city, - body.get('prefilled_customer')['city']) - assert_equal(response.prefilled_customer.company_name, - body.get('prefilled_customer')['company_name']) - assert_equal(response.prefilled_customer.country_code, - body.get('prefilled_customer')['country_code']) - assert_equal(response.prefilled_customer.danish_identity_number, - body.get('prefilled_customer')['danish_identity_number']) - assert_equal(response.prefilled_customer.email, - body.get('prefilled_customer')['email']) - assert_equal(response.prefilled_customer.family_name, - body.get('prefilled_customer')['family_name']) - assert_equal(response.prefilled_customer.given_name, - body.get('prefilled_customer')['given_name']) - assert_equal(response.prefilled_customer.postal_code, - body.get('prefilled_customer')['postal_code']) - assert_equal(response.prefilled_customer.region, - body.get('prefilled_customer')['region']) - assert_equal(response.prefilled_customer.swedish_identity_number, - body.get('prefilled_customer')['swedish_identity_number']) + assert isinstance(response, resources.BillingRequestFlow) + assert responses.calls[-1].request.headers.get('Idempotency-Key') is not None + assert response.authorisation_url == body.get('authorisation_url') + assert response.auto_fulfil == body.get('auto_fulfil') + assert response.created_at == body.get('created_at') + assert response.exit_uri == body.get('exit_uri') + assert response.expires_at == body.get('expires_at') + assert response.id == body.get('id') + assert response.language == body.get('language') + assert response.lock_bank_account == body.get('lock_bank_account') + assert response.lock_currency == body.get('lock_currency') + assert response.lock_customer_details == body.get('lock_customer_details') + assert response.redirect_uri == body.get('redirect_uri') + assert response.session_token == body.get('session_token') + assert response.show_redirect_buttons == body.get('show_redirect_buttons') + assert response.show_success_redirect_button == body.get('show_success_redirect_button') + assert response.links.billing_request == body.get('links')['billing_request'] + assert response.prefilled_bank_account.account_type == body.get('prefilled_bank_account')['account_type'] + assert response.prefilled_customer.address_line1 == body.get('prefilled_customer')['address_line1'] + assert response.prefilled_customer.address_line2 == body.get('prefilled_customer')['address_line2'] + assert response.prefilled_customer.address_line3 == body.get('prefilled_customer')['address_line3'] + assert response.prefilled_customer.city == body.get('prefilled_customer')['city'] + assert response.prefilled_customer.company_name == body.get('prefilled_customer')['company_name'] + assert response.prefilled_customer.country_code == body.get('prefilled_customer')['country_code'] + assert response.prefilled_customer.danish_identity_number == body.get('prefilled_customer')['danish_identity_number'] + assert response.prefilled_customer.email == body.get('prefilled_customer')['email'] + assert response.prefilled_customer.family_name == body.get('prefilled_customer')['family_name'] + assert response.prefilled_customer.given_name == body.get('prefilled_customer')['given_name'] + assert response.prefilled_customer.postal_code == body.get('prefilled_customer')['postal_code'] + assert response.prefilled_customer.region == body.get('prefilled_customer')['region'] + assert response.prefilled_customer.swedish_identity_number == body.get('prefilled_customer')['swedish_identity_number'] @responses.activate def test_timeout_billing_request_flows_create_retries(): fixture = helpers.load_fixture('billing_request_flows')['create'] with helpers.stub_timeout_then_response(fixture) as rsps: response = helpers.client.billing_request_flows.create(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['billing_request_flows'] - assert_is_instance(response, resources.BillingRequestFlow) + assert isinstance(response, resources.BillingRequestFlow) def test_502_billing_request_flows_create_retries(): fixture = helpers.load_fixture('billing_request_flows')['create'] with helpers.stub_502_then_response(fixture) as rsps: response = helpers.client.billing_request_flows.create(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['billing_request_flows'] - assert_is_instance(response, resources.BillingRequestFlow) + assert isinstance(response, resources.BillingRequestFlow) @responses.activate @@ -108,64 +84,49 @@ def test_billing_request_flows_initialise(): response = helpers.client.billing_request_flows.initialise(*fixture['url_params']) body = fixture['body']['billing_request_flows'] - assert_is_instance(response, resources.BillingRequestFlow) - assert_is_not_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal(response.authorisation_url, body.get('authorisation_url')) - assert_equal(response.auto_fulfil, body.get('auto_fulfil')) - assert_equal(response.created_at, body.get('created_at')) - assert_equal(response.exit_uri, body.get('exit_uri')) - assert_equal(response.expires_at, body.get('expires_at')) - assert_equal(response.id, body.get('id')) - assert_equal(response.language, body.get('language')) - assert_equal(response.lock_bank_account, body.get('lock_bank_account')) - assert_equal(response.lock_currency, body.get('lock_currency')) - assert_equal(response.lock_customer_details, body.get('lock_customer_details')) - assert_equal(response.redirect_uri, body.get('redirect_uri')) - assert_equal(response.session_token, body.get('session_token')) - assert_equal(response.show_redirect_buttons, body.get('show_redirect_buttons')) - assert_equal(response.show_success_redirect_button, body.get('show_success_redirect_button')) - assert_equal(response.links.billing_request, - body.get('links')['billing_request']) - assert_equal(response.prefilled_bank_account.account_type, - body.get('prefilled_bank_account')['account_type']) - assert_equal(response.prefilled_customer.address_line1, - body.get('prefilled_customer')['address_line1']) - assert_equal(response.prefilled_customer.address_line2, - body.get('prefilled_customer')['address_line2']) - assert_equal(response.prefilled_customer.address_line3, - body.get('prefilled_customer')['address_line3']) - assert_equal(response.prefilled_customer.city, - body.get('prefilled_customer')['city']) - assert_equal(response.prefilled_customer.company_name, - body.get('prefilled_customer')['company_name']) - assert_equal(response.prefilled_customer.country_code, - body.get('prefilled_customer')['country_code']) - assert_equal(response.prefilled_customer.danish_identity_number, - body.get('prefilled_customer')['danish_identity_number']) - assert_equal(response.prefilled_customer.email, - body.get('prefilled_customer')['email']) - assert_equal(response.prefilled_customer.family_name, - body.get('prefilled_customer')['family_name']) - assert_equal(response.prefilled_customer.given_name, - body.get('prefilled_customer')['given_name']) - assert_equal(response.prefilled_customer.postal_code, - body.get('prefilled_customer')['postal_code']) - assert_equal(response.prefilled_customer.region, - body.get('prefilled_customer')['region']) - assert_equal(response.prefilled_customer.swedish_identity_number, - body.get('prefilled_customer')['swedish_identity_number']) + assert isinstance(response, resources.BillingRequestFlow) + assert responses.calls[-1].request.headers.get('Idempotency-Key') is not None + assert response.authorisation_url == body.get('authorisation_url') + assert response.auto_fulfil == body.get('auto_fulfil') + assert response.created_at == body.get('created_at') + assert response.exit_uri == body.get('exit_uri') + assert response.expires_at == body.get('expires_at') + assert response.id == body.get('id') + assert response.language == body.get('language') + assert response.lock_bank_account == body.get('lock_bank_account') + assert response.lock_currency == body.get('lock_currency') + assert response.lock_customer_details == body.get('lock_customer_details') + assert response.redirect_uri == body.get('redirect_uri') + assert response.session_token == body.get('session_token') + assert response.show_redirect_buttons == body.get('show_redirect_buttons') + assert response.show_success_redirect_button == body.get('show_success_redirect_button') + assert response.links.billing_request == body.get('links')['billing_request'] + assert response.prefilled_bank_account.account_type == body.get('prefilled_bank_account')['account_type'] + assert response.prefilled_customer.address_line1 == body.get('prefilled_customer')['address_line1'] + assert response.prefilled_customer.address_line2 == body.get('prefilled_customer')['address_line2'] + assert response.prefilled_customer.address_line3 == body.get('prefilled_customer')['address_line3'] + assert response.prefilled_customer.city == body.get('prefilled_customer')['city'] + assert response.prefilled_customer.company_name == body.get('prefilled_customer')['company_name'] + assert response.prefilled_customer.country_code == body.get('prefilled_customer')['country_code'] + assert response.prefilled_customer.danish_identity_number == body.get('prefilled_customer')['danish_identity_number'] + assert response.prefilled_customer.email == body.get('prefilled_customer')['email'] + assert response.prefilled_customer.family_name == body.get('prefilled_customer')['family_name'] + assert response.prefilled_customer.given_name == body.get('prefilled_customer')['given_name'] + assert response.prefilled_customer.postal_code == body.get('prefilled_customer')['postal_code'] + assert response.prefilled_customer.region == body.get('prefilled_customer')['region'] + assert response.prefilled_customer.swedish_identity_number == body.get('prefilled_customer')['swedish_identity_number'] def test_timeout_billing_request_flows_initialise_doesnt_retry(): fixture = helpers.load_fixture('billing_request_flows')['initialise'] with helpers.stub_timeout(fixture) as rsps: - with assert_raises(requests.ConnectTimeout): + with pytest.raises(requests.ConnectTimeout): response = helpers.client.billing_request_flows.initialise(*fixture['url_params']) - assert_equal(1, len(rsps.calls)) + assert len(rsps.calls) == 1 def test_502_billing_request_flows_initialise_doesnt_retry(): fixture = helpers.load_fixture('billing_request_flows')['initialise'] with helpers.stub_502(fixture) as rsps: - with assert_raises(MalformedResponseError): + with pytest.raises(MalformedResponseError): response = helpers.client.billing_request_flows.initialise(*fixture['url_params']) - assert_equal(1, len(rsps.calls)) + assert len(rsps.calls) == 1 diff --git a/tests/integration/billing_request_templates_integration_test.py b/tests/integration/billing_request_templates_integration_test.py index 86952a80..3e808c0a 100644 --- a/tests/integration/billing_request_templates_integration_test.py +++ b/tests/integration/billing_request_templates_integration_test.py @@ -5,16 +5,9 @@ import json +import pytest import requests import responses -from nose.tools import ( - assert_equal, - assert_is_instance, - assert_is_none, - assert_is_not_none, - assert_not_equal, - assert_raises -) from gocardless_pro.errors import MalformedResponseError from gocardless_pro import resources @@ -30,77 +23,58 @@ def test_billing_request_templates_list(): response = helpers.client.billing_request_templates.list(*fixture['url_params']) body = fixture['body']['billing_request_templates'] - assert_is_instance(response, list_response.ListResponse) - assert_is_instance(response.records[0], resources.BillingRequestTemplate) - - assert_equal(response.before, fixture['body']['meta']['cursors']['before']) - assert_equal(response.after, fixture['body']['meta']['cursors']['after']) - assert_is_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal([r.authorisation_url for r in response.records], - [b.get('authorisation_url') for b in body]) - assert_equal([r.created_at for r in response.records], - [b.get('created_at') for b in body]) - assert_equal([r.id for r in response.records], - [b.get('id') for b in body]) - assert_equal([r.mandate_request_currency for r in response.records], - [b.get('mandate_request_currency') for b in body]) - assert_equal([r.mandate_request_description for r in response.records], - [b.get('mandate_request_description') for b in body]) - assert_equal([r.mandate_request_metadata for r in response.records], - [b.get('mandate_request_metadata') for b in body]) - assert_equal([r.mandate_request_scheme for r in response.records], - [b.get('mandate_request_scheme') for b in body]) - assert_equal([r.mandate_request_verify for r in response.records], - [b.get('mandate_request_verify') for b in body]) - assert_equal([r.metadata for r in response.records], - [b.get('metadata') for b in body]) - assert_equal([r.name for r in response.records], - [b.get('name') for b in body]) - assert_equal([r.payment_request_amount for r in response.records], - [b.get('payment_request_amount') for b in body]) - assert_equal([r.payment_request_currency for r in response.records], - [b.get('payment_request_currency') for b in body]) - assert_equal([r.payment_request_description for r in response.records], - [b.get('payment_request_description') for b in body]) - assert_equal([r.payment_request_metadata for r in response.records], - [b.get('payment_request_metadata') for b in body]) - assert_equal([r.payment_request_scheme for r in response.records], - [b.get('payment_request_scheme') for b in body]) - assert_equal([r.redirect_uri for r in response.records], - [b.get('redirect_uri') for b in body]) - assert_equal([r.updated_at for r in response.records], - [b.get('updated_at') for b in body]) + assert isinstance(response, list_response.ListResponse) + assert isinstance(response.records[0], resources.BillingRequestTemplate) + + assert response.before == fixture['body']['meta']['cursors']['before'] + assert response.after == fixture['body']['meta']['cursors']['after'] + assert responses.calls[-1].request.headers.get('Idempotency-Key') is None + assert [r.authorisation_url for r in response.records] == [b.get('authorisation_url') for b in body] + assert [r.created_at for r in response.records] == [b.get('created_at') for b in body] + assert [r.id for r in response.records] == [b.get('id') for b in body] + assert [r.mandate_request_currency for r in response.records] == [b.get('mandate_request_currency') for b in body] + assert [r.mandate_request_description for r in response.records] == [b.get('mandate_request_description') for b in body] + assert [r.mandate_request_metadata for r in response.records] == [b.get('mandate_request_metadata') for b in body] + assert [r.mandate_request_scheme for r in response.records] == [b.get('mandate_request_scheme') for b in body] + assert [r.mandate_request_verify for r in response.records] == [b.get('mandate_request_verify') for b in body] + assert [r.metadata for r in response.records] == [b.get('metadata') for b in body] + assert [r.name for r in response.records] == [b.get('name') for b in body] + assert [r.payment_request_amount for r in response.records] == [b.get('payment_request_amount') for b in body] + assert [r.payment_request_currency for r in response.records] == [b.get('payment_request_currency') for b in body] + assert [r.payment_request_description for r in response.records] == [b.get('payment_request_description') for b in body] + assert [r.payment_request_metadata for r in response.records] == [b.get('payment_request_metadata') for b in body] + assert [r.payment_request_scheme for r in response.records] == [b.get('payment_request_scheme') for b in body] + assert [r.redirect_uri for r in response.records] == [b.get('redirect_uri') for b in body] + assert [r.updated_at for r in response.records] == [b.get('updated_at') for b in body] @responses.activate def test_timeout_billing_request_templates_list_retries(): fixture = helpers.load_fixture('billing_request_templates')['list'] with helpers.stub_timeout_then_response(fixture) as rsps: response = helpers.client.billing_request_templates.list(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['billing_request_templates'] - assert_is_instance(response, list_response.ListResponse) - assert_is_instance(response.records[0], resources.BillingRequestTemplate) + assert isinstance(response, list_response.ListResponse) + assert isinstance(response.records[0], resources.BillingRequestTemplate) - assert_equal(response.before, fixture['body']['meta']['cursors']['before']) - assert_equal(response.after, fixture['body']['meta']['cursors']['after']) + assert response.before == fixture['body']['meta']['cursors']['before'] + assert response.after == fixture['body']['meta']['cursors']['after'] def test_502_billing_request_templates_list_retries(): fixture = helpers.load_fixture('billing_request_templates')['list'] with helpers.stub_502_then_response(fixture) as rsps: response = helpers.client.billing_request_templates.list(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['billing_request_templates'] - assert_is_instance(response, list_response.ListResponse) - assert_is_instance(response.records[0], resources.BillingRequestTemplate) + assert isinstance(response, list_response.ListResponse) + assert isinstance(response.records[0], resources.BillingRequestTemplate) - assert_equal(response.before, fixture['body']['meta']['cursors']['before']) - assert_equal(response.after, fixture['body']['meta']['cursors']['after']) + assert response.before == fixture['body']['meta']['cursors']['before'] + assert response.after == fixture['body']['meta']['cursors']['after'] @responses.activate def test_billing_request_templates_all(): @@ -117,9 +91,9 @@ def callback(request): responses.add_callback(fixture['method'], url, callback) all_records = list(helpers.client.billing_request_templates.all()) - assert_equal(len(all_records), len(fixture['body']['billing_request_templates']) * 2) + assert len(all_records) == len(fixture['body']['billing_request_templates']) * 2 for record in all_records: - assert_is_instance(record, resources.BillingRequestTemplate) + assert isinstance(record, resources.BillingRequestTemplate) @@ -130,48 +104,46 @@ def test_billing_request_templates_get(): response = helpers.client.billing_request_templates.get(*fixture['url_params']) body = fixture['body']['billing_request_templates'] - assert_is_instance(response, resources.BillingRequestTemplate) - assert_is_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal(response.authorisation_url, body.get('authorisation_url')) - assert_equal(response.created_at, body.get('created_at')) - assert_equal(response.id, body.get('id')) - assert_equal(response.mandate_request_currency, body.get('mandate_request_currency')) - assert_equal(response.mandate_request_description, body.get('mandate_request_description')) - assert_equal(response.mandate_request_metadata, body.get('mandate_request_metadata')) - assert_equal(response.mandate_request_scheme, body.get('mandate_request_scheme')) - assert_equal(response.mandate_request_verify, body.get('mandate_request_verify')) - assert_equal(response.metadata, body.get('metadata')) - assert_equal(response.name, body.get('name')) - assert_equal(response.payment_request_amount, body.get('payment_request_amount')) - assert_equal(response.payment_request_currency, body.get('payment_request_currency')) - assert_equal(response.payment_request_description, body.get('payment_request_description')) - assert_equal(response.payment_request_metadata, body.get('payment_request_metadata')) - assert_equal(response.payment_request_scheme, body.get('payment_request_scheme')) - assert_equal(response.redirect_uri, body.get('redirect_uri')) - assert_equal(response.updated_at, body.get('updated_at')) + assert isinstance(response, resources.BillingRequestTemplate) + assert responses.calls[-1].request.headers.get('Idempotency-Key') is None + assert response.authorisation_url == body.get('authorisation_url') + assert response.created_at == body.get('created_at') + assert response.id == body.get('id') + assert response.mandate_request_currency == body.get('mandate_request_currency') + assert response.mandate_request_description == body.get('mandate_request_description') + assert response.mandate_request_metadata == body.get('mandate_request_metadata') + assert response.mandate_request_scheme == body.get('mandate_request_scheme') + assert response.mandate_request_verify == body.get('mandate_request_verify') + assert response.metadata == body.get('metadata') + assert response.name == body.get('name') + assert response.payment_request_amount == body.get('payment_request_amount') + assert response.payment_request_currency == body.get('payment_request_currency') + assert response.payment_request_description == body.get('payment_request_description') + assert response.payment_request_metadata == body.get('payment_request_metadata') + assert response.payment_request_scheme == body.get('payment_request_scheme') + assert response.redirect_uri == body.get('redirect_uri') + assert response.updated_at == body.get('updated_at') @responses.activate def test_timeout_billing_request_templates_get_retries(): fixture = helpers.load_fixture('billing_request_templates')['get'] with helpers.stub_timeout_then_response(fixture) as rsps: response = helpers.client.billing_request_templates.get(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['billing_request_templates'] - assert_is_instance(response, resources.BillingRequestTemplate) + assert isinstance(response, resources.BillingRequestTemplate) def test_502_billing_request_templates_get_retries(): fixture = helpers.load_fixture('billing_request_templates')['get'] with helpers.stub_502_then_response(fixture) as rsps: response = helpers.client.billing_request_templates.get(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['billing_request_templates'] - assert_is_instance(response, resources.BillingRequestTemplate) + assert isinstance(response, resources.BillingRequestTemplate) @responses.activate @@ -181,25 +153,25 @@ def test_billing_request_templates_create(): response = helpers.client.billing_request_templates.create(*fixture['url_params']) body = fixture['body']['billing_request_templates'] - assert_is_instance(response, resources.BillingRequestTemplate) - assert_is_not_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal(response.authorisation_url, body.get('authorisation_url')) - assert_equal(response.created_at, body.get('created_at')) - assert_equal(response.id, body.get('id')) - assert_equal(response.mandate_request_currency, body.get('mandate_request_currency')) - assert_equal(response.mandate_request_description, body.get('mandate_request_description')) - assert_equal(response.mandate_request_metadata, body.get('mandate_request_metadata')) - assert_equal(response.mandate_request_scheme, body.get('mandate_request_scheme')) - assert_equal(response.mandate_request_verify, body.get('mandate_request_verify')) - assert_equal(response.metadata, body.get('metadata')) - assert_equal(response.name, body.get('name')) - assert_equal(response.payment_request_amount, body.get('payment_request_amount')) - assert_equal(response.payment_request_currency, body.get('payment_request_currency')) - assert_equal(response.payment_request_description, body.get('payment_request_description')) - assert_equal(response.payment_request_metadata, body.get('payment_request_metadata')) - assert_equal(response.payment_request_scheme, body.get('payment_request_scheme')) - assert_equal(response.redirect_uri, body.get('redirect_uri')) - assert_equal(response.updated_at, body.get('updated_at')) + assert isinstance(response, resources.BillingRequestTemplate) + assert responses.calls[-1].request.headers.get('Idempotency-Key') is not None + assert response.authorisation_url == body.get('authorisation_url') + assert response.created_at == body.get('created_at') + assert response.id == body.get('id') + assert response.mandate_request_currency == body.get('mandate_request_currency') + assert response.mandate_request_description == body.get('mandate_request_description') + assert response.mandate_request_metadata == body.get('mandate_request_metadata') + assert response.mandate_request_scheme == body.get('mandate_request_scheme') + assert response.mandate_request_verify == body.get('mandate_request_verify') + assert response.metadata == body.get('metadata') + assert response.name == body.get('name') + assert response.payment_request_amount == body.get('payment_request_amount') + assert response.payment_request_currency == body.get('payment_request_currency') + assert response.payment_request_description == body.get('payment_request_description') + assert response.payment_request_metadata == body.get('payment_request_metadata') + assert response.payment_request_scheme == body.get('payment_request_scheme') + assert response.redirect_uri == body.get('redirect_uri') + assert response.updated_at == body.get('updated_at') @responses.activate def test_billing_request_templates_create_new_idempotency_key_for_each_call(): @@ -207,40 +179,37 @@ def test_billing_request_templates_create_new_idempotency_key_for_each_call(): helpers.stub_response(fixture) helpers.client.billing_request_templates.create(*fixture['url_params']) helpers.client.billing_request_templates.create(*fixture['url_params']) - assert_not_equal(responses.calls[0].request.headers.get('Idempotency-Key'), - responses.calls[1].request.headers.get('Idempotency-Key')) + assert responses.calls[0].request.headers.get('Idempotency-Key') != responses.calls[1].request.headers.get('Idempotency-Key') def test_timeout_billing_request_templates_create_idempotency_conflict(): create_fixture = helpers.load_fixture('billing_request_templates')['create'] get_fixture = helpers.load_fixture('billing_request_templates')['get'] with helpers.stub_timeout_then_idempotency_conflict(create_fixture, get_fixture) as rsps: response = helpers.client.billing_request_templates.create(*create_fixture['url_params']) - assert_equal(2, len(rsps.calls)) + assert len(rsps.calls) == 2 - assert_is_instance(response, resources.BillingRequestTemplate) + assert isinstance(response, resources.BillingRequestTemplate) @responses.activate def test_timeout_billing_request_templates_create_retries(): fixture = helpers.load_fixture('billing_request_templates')['create'] with helpers.stub_timeout_then_response(fixture) as rsps: response = helpers.client.billing_request_templates.create(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['billing_request_templates'] - assert_is_instance(response, resources.BillingRequestTemplate) + assert isinstance(response, resources.BillingRequestTemplate) def test_502_billing_request_templates_create_retries(): fixture = helpers.load_fixture('billing_request_templates')['create'] with helpers.stub_502_then_response(fixture) as rsps: response = helpers.client.billing_request_templates.create(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['billing_request_templates'] - assert_is_instance(response, resources.BillingRequestTemplate) + assert isinstance(response, resources.BillingRequestTemplate) @responses.activate @@ -250,46 +219,44 @@ def test_billing_request_templates_update(): response = helpers.client.billing_request_templates.update(*fixture['url_params']) body = fixture['body']['billing_request_templates'] - assert_is_instance(response, resources.BillingRequestTemplate) - assert_is_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal(response.authorisation_url, body.get('authorisation_url')) - assert_equal(response.created_at, body.get('created_at')) - assert_equal(response.id, body.get('id')) - assert_equal(response.mandate_request_currency, body.get('mandate_request_currency')) - assert_equal(response.mandate_request_description, body.get('mandate_request_description')) - assert_equal(response.mandate_request_metadata, body.get('mandate_request_metadata')) - assert_equal(response.mandate_request_scheme, body.get('mandate_request_scheme')) - assert_equal(response.mandate_request_verify, body.get('mandate_request_verify')) - assert_equal(response.metadata, body.get('metadata')) - assert_equal(response.name, body.get('name')) - assert_equal(response.payment_request_amount, body.get('payment_request_amount')) - assert_equal(response.payment_request_currency, body.get('payment_request_currency')) - assert_equal(response.payment_request_description, body.get('payment_request_description')) - assert_equal(response.payment_request_metadata, body.get('payment_request_metadata')) - assert_equal(response.payment_request_scheme, body.get('payment_request_scheme')) - assert_equal(response.redirect_uri, body.get('redirect_uri')) - assert_equal(response.updated_at, body.get('updated_at')) + assert isinstance(response, resources.BillingRequestTemplate) + assert responses.calls[-1].request.headers.get('Idempotency-Key') is None + assert response.authorisation_url == body.get('authorisation_url') + assert response.created_at == body.get('created_at') + assert response.id == body.get('id') + assert response.mandate_request_currency == body.get('mandate_request_currency') + assert response.mandate_request_description == body.get('mandate_request_description') + assert response.mandate_request_metadata == body.get('mandate_request_metadata') + assert response.mandate_request_scheme == body.get('mandate_request_scheme') + assert response.mandate_request_verify == body.get('mandate_request_verify') + assert response.metadata == body.get('metadata') + assert response.name == body.get('name') + assert response.payment_request_amount == body.get('payment_request_amount') + assert response.payment_request_currency == body.get('payment_request_currency') + assert response.payment_request_description == body.get('payment_request_description') + assert response.payment_request_metadata == body.get('payment_request_metadata') + assert response.payment_request_scheme == body.get('payment_request_scheme') + assert response.redirect_uri == body.get('redirect_uri') + assert response.updated_at == body.get('updated_at') @responses.activate def test_timeout_billing_request_templates_update_retries(): fixture = helpers.load_fixture('billing_request_templates')['update'] with helpers.stub_timeout_then_response(fixture) as rsps: response = helpers.client.billing_request_templates.update(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['billing_request_templates'] - assert_is_instance(response, resources.BillingRequestTemplate) + assert isinstance(response, resources.BillingRequestTemplate) def test_502_billing_request_templates_update_retries(): fixture = helpers.load_fixture('billing_request_templates')['update'] with helpers.stub_502_then_response(fixture) as rsps: response = helpers.client.billing_request_templates.update(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['billing_request_templates'] - assert_is_instance(response, resources.BillingRequestTemplate) + assert isinstance(response, resources.BillingRequestTemplate) diff --git a/tests/integration/billing_requests_integration_test.py b/tests/integration/billing_requests_integration_test.py index b3663aea..9e3dac59 100644 --- a/tests/integration/billing_requests_integration_test.py +++ b/tests/integration/billing_requests_integration_test.py @@ -5,16 +5,9 @@ import json +import pytest import requests import responses -from nose.tools import ( - assert_equal, - assert_is_instance, - assert_is_none, - assert_is_not_none, - assert_not_equal, - assert_raises -) from gocardless_pro.errors import MalformedResponseError from gocardless_pro import resources @@ -30,71 +23,43 @@ def test_billing_requests_create(): response = helpers.client.billing_requests.create(*fixture['url_params']) body = fixture['body']['billing_requests'] - assert_is_instance(response, resources.BillingRequest) - assert_is_not_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal(response.actions, body.get('actions')) - assert_equal(response.created_at, body.get('created_at')) - assert_equal(response.fallback_enabled, body.get('fallback_enabled')) - assert_equal(response.id, body.get('id')) - assert_equal(response.metadata, body.get('metadata')) - assert_equal(response.purpose_code, body.get('purpose_code')) - assert_equal(response.status, body.get('status')) - assert_equal(response.links.bank_authorisation, - body.get('links')['bank_authorisation']) - assert_equal(response.links.creditor, - body.get('links')['creditor']) - assert_equal(response.links.customer, - body.get('links')['customer']) - assert_equal(response.links.customer_bank_account, - body.get('links')['customer_bank_account']) - assert_equal(response.links.customer_billing_detail, - body.get('links')['customer_billing_detail']) - assert_equal(response.links.mandate_request, - body.get('links')['mandate_request']) - assert_equal(response.links.mandate_request_mandate, - body.get('links')['mandate_request_mandate']) - assert_equal(response.links.organisation, - body.get('links')['organisation']) - assert_equal(response.links.payment_request, - body.get('links')['payment_request']) - assert_equal(response.links.payment_request_payment, - body.get('links')['payment_request_payment']) - assert_equal(response.mandate_request.authorisation_source, - body.get('mandate_request')['authorisation_source']) - assert_equal(response.mandate_request.constraints, - body.get('mandate_request')['constraints']) - assert_equal(response.mandate_request.currency, - body.get('mandate_request')['currency']) - assert_equal(response.mandate_request.description, - body.get('mandate_request')['description']) - assert_equal(response.mandate_request.links, - body.get('mandate_request')['links']) - assert_equal(response.mandate_request.metadata, - body.get('mandate_request')['metadata']) - assert_equal(response.mandate_request.scheme, - body.get('mandate_request')['scheme']) - assert_equal(response.mandate_request.verify, - body.get('mandate_request')['verify']) - assert_equal(response.payment_request.amount, - body.get('payment_request')['amount']) - assert_equal(response.payment_request.app_fee, - body.get('payment_request')['app_fee']) - assert_equal(response.payment_request.currency, - body.get('payment_request')['currency']) - assert_equal(response.payment_request.description, - body.get('payment_request')['description']) - assert_equal(response.payment_request.links, - body.get('payment_request')['links']) - assert_equal(response.payment_request.metadata, - body.get('payment_request')['metadata']) - assert_equal(response.payment_request.scheme, - body.get('payment_request')['scheme']) - assert_equal(response.resources.customer, - body.get('resources')['customer']) - assert_equal(response.resources.customer_bank_account, - body.get('resources')['customer_bank_account']) - assert_equal(response.resources.customer_billing_detail, - body.get('resources')['customer_billing_detail']) + assert isinstance(response, resources.BillingRequest) + assert responses.calls[-1].request.headers.get('Idempotency-Key') is not None + assert response.actions == body.get('actions') + assert response.created_at == body.get('created_at') + assert response.fallback_enabled == body.get('fallback_enabled') + assert response.id == body.get('id') + assert response.metadata == body.get('metadata') + assert response.purpose_code == body.get('purpose_code') + assert response.status == body.get('status') + assert response.links.bank_authorisation == body.get('links')['bank_authorisation'] + assert response.links.creditor == body.get('links')['creditor'] + assert response.links.customer == body.get('links')['customer'] + assert response.links.customer_bank_account == body.get('links')['customer_bank_account'] + assert response.links.customer_billing_detail == body.get('links')['customer_billing_detail'] + assert response.links.mandate_request == body.get('links')['mandate_request'] + assert response.links.mandate_request_mandate == body.get('links')['mandate_request_mandate'] + assert response.links.organisation == body.get('links')['organisation'] + assert response.links.payment_request == body.get('links')['payment_request'] + assert response.links.payment_request_payment == body.get('links')['payment_request_payment'] + assert response.mandate_request.authorisation_source == body.get('mandate_request')['authorisation_source'] + assert response.mandate_request.constraints == body.get('mandate_request')['constraints'] + assert response.mandate_request.currency == body.get('mandate_request')['currency'] + assert response.mandate_request.description == body.get('mandate_request')['description'] + assert response.mandate_request.links == body.get('mandate_request')['links'] + assert response.mandate_request.metadata == body.get('mandate_request')['metadata'] + assert response.mandate_request.scheme == body.get('mandate_request')['scheme'] + assert response.mandate_request.verify == body.get('mandate_request')['verify'] + assert response.payment_request.amount == body.get('payment_request')['amount'] + assert response.payment_request.app_fee == body.get('payment_request')['app_fee'] + assert response.payment_request.currency == body.get('payment_request')['currency'] + assert response.payment_request.description == body.get('payment_request')['description'] + assert response.payment_request.links == body.get('payment_request')['links'] + assert response.payment_request.metadata == body.get('payment_request')['metadata'] + assert response.payment_request.scheme == body.get('payment_request')['scheme'] + assert response.resources.customer == body.get('resources')['customer'] + assert response.resources.customer_bank_account == body.get('resources')['customer_bank_account'] + assert response.resources.customer_billing_detail == body.get('resources')['customer_billing_detail'] @responses.activate def test_billing_requests_create_new_idempotency_key_for_each_call(): @@ -102,40 +67,37 @@ def test_billing_requests_create_new_idempotency_key_for_each_call(): helpers.stub_response(fixture) helpers.client.billing_requests.create(*fixture['url_params']) helpers.client.billing_requests.create(*fixture['url_params']) - assert_not_equal(responses.calls[0].request.headers.get('Idempotency-Key'), - responses.calls[1].request.headers.get('Idempotency-Key')) + assert responses.calls[0].request.headers.get('Idempotency-Key') != responses.calls[1].request.headers.get('Idempotency-Key') def test_timeout_billing_requests_create_idempotency_conflict(): create_fixture = helpers.load_fixture('billing_requests')['create'] get_fixture = helpers.load_fixture('billing_requests')['get'] with helpers.stub_timeout_then_idempotency_conflict(create_fixture, get_fixture) as rsps: response = helpers.client.billing_requests.create(*create_fixture['url_params']) - assert_equal(2, len(rsps.calls)) + assert len(rsps.calls) == 2 - assert_is_instance(response, resources.BillingRequest) + assert isinstance(response, resources.BillingRequest) @responses.activate def test_timeout_billing_requests_create_retries(): fixture = helpers.load_fixture('billing_requests')['create'] with helpers.stub_timeout_then_response(fixture) as rsps: response = helpers.client.billing_requests.create(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['billing_requests'] - assert_is_instance(response, resources.BillingRequest) + assert isinstance(response, resources.BillingRequest) def test_502_billing_requests_create_retries(): fixture = helpers.load_fixture('billing_requests')['create'] with helpers.stub_502_then_response(fixture) as rsps: response = helpers.client.billing_requests.create(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['billing_requests'] - assert_is_instance(response, resources.BillingRequest) + assert isinstance(response, resources.BillingRequest) @responses.activate @@ -145,85 +107,57 @@ def test_billing_requests_collect_customer_details(): response = helpers.client.billing_requests.collect_customer_details(*fixture['url_params']) body = fixture['body']['billing_requests'] - assert_is_instance(response, resources.BillingRequest) - assert_is_not_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal(response.actions, body.get('actions')) - assert_equal(response.created_at, body.get('created_at')) - assert_equal(response.fallback_enabled, body.get('fallback_enabled')) - assert_equal(response.id, body.get('id')) - assert_equal(response.metadata, body.get('metadata')) - assert_equal(response.purpose_code, body.get('purpose_code')) - assert_equal(response.status, body.get('status')) - assert_equal(response.links.bank_authorisation, - body.get('links')['bank_authorisation']) - assert_equal(response.links.creditor, - body.get('links')['creditor']) - assert_equal(response.links.customer, - body.get('links')['customer']) - assert_equal(response.links.customer_bank_account, - body.get('links')['customer_bank_account']) - assert_equal(response.links.customer_billing_detail, - body.get('links')['customer_billing_detail']) - assert_equal(response.links.mandate_request, - body.get('links')['mandate_request']) - assert_equal(response.links.mandate_request_mandate, - body.get('links')['mandate_request_mandate']) - assert_equal(response.links.organisation, - body.get('links')['organisation']) - assert_equal(response.links.payment_request, - body.get('links')['payment_request']) - assert_equal(response.links.payment_request_payment, - body.get('links')['payment_request_payment']) - assert_equal(response.mandate_request.authorisation_source, - body.get('mandate_request')['authorisation_source']) - assert_equal(response.mandate_request.constraints, - body.get('mandate_request')['constraints']) - assert_equal(response.mandate_request.currency, - body.get('mandate_request')['currency']) - assert_equal(response.mandate_request.description, - body.get('mandate_request')['description']) - assert_equal(response.mandate_request.links, - body.get('mandate_request')['links']) - assert_equal(response.mandate_request.metadata, - body.get('mandate_request')['metadata']) - assert_equal(response.mandate_request.scheme, - body.get('mandate_request')['scheme']) - assert_equal(response.mandate_request.verify, - body.get('mandate_request')['verify']) - assert_equal(response.payment_request.amount, - body.get('payment_request')['amount']) - assert_equal(response.payment_request.app_fee, - body.get('payment_request')['app_fee']) - assert_equal(response.payment_request.currency, - body.get('payment_request')['currency']) - assert_equal(response.payment_request.description, - body.get('payment_request')['description']) - assert_equal(response.payment_request.links, - body.get('payment_request')['links']) - assert_equal(response.payment_request.metadata, - body.get('payment_request')['metadata']) - assert_equal(response.payment_request.scheme, - body.get('payment_request')['scheme']) - assert_equal(response.resources.customer, - body.get('resources')['customer']) - assert_equal(response.resources.customer_bank_account, - body.get('resources')['customer_bank_account']) - assert_equal(response.resources.customer_billing_detail, - body.get('resources')['customer_billing_detail']) + assert isinstance(response, resources.BillingRequest) + assert responses.calls[-1].request.headers.get('Idempotency-Key') is not None + assert response.actions == body.get('actions') + assert response.created_at == body.get('created_at') + assert response.fallback_enabled == body.get('fallback_enabled') + assert response.id == body.get('id') + assert response.metadata == body.get('metadata') + assert response.purpose_code == body.get('purpose_code') + assert response.status == body.get('status') + assert response.links.bank_authorisation == body.get('links')['bank_authorisation'] + assert response.links.creditor == body.get('links')['creditor'] + assert response.links.customer == body.get('links')['customer'] + assert response.links.customer_bank_account == body.get('links')['customer_bank_account'] + assert response.links.customer_billing_detail == body.get('links')['customer_billing_detail'] + assert response.links.mandate_request == body.get('links')['mandate_request'] + assert response.links.mandate_request_mandate == body.get('links')['mandate_request_mandate'] + assert response.links.organisation == body.get('links')['organisation'] + assert response.links.payment_request == body.get('links')['payment_request'] + assert response.links.payment_request_payment == body.get('links')['payment_request_payment'] + assert response.mandate_request.authorisation_source == body.get('mandate_request')['authorisation_source'] + assert response.mandate_request.constraints == body.get('mandate_request')['constraints'] + assert response.mandate_request.currency == body.get('mandate_request')['currency'] + assert response.mandate_request.description == body.get('mandate_request')['description'] + assert response.mandate_request.links == body.get('mandate_request')['links'] + assert response.mandate_request.metadata == body.get('mandate_request')['metadata'] + assert response.mandate_request.scheme == body.get('mandate_request')['scheme'] + assert response.mandate_request.verify == body.get('mandate_request')['verify'] + assert response.payment_request.amount == body.get('payment_request')['amount'] + assert response.payment_request.app_fee == body.get('payment_request')['app_fee'] + assert response.payment_request.currency == body.get('payment_request')['currency'] + assert response.payment_request.description == body.get('payment_request')['description'] + assert response.payment_request.links == body.get('payment_request')['links'] + assert response.payment_request.metadata == body.get('payment_request')['metadata'] + assert response.payment_request.scheme == body.get('payment_request')['scheme'] + assert response.resources.customer == body.get('resources')['customer'] + assert response.resources.customer_bank_account == body.get('resources')['customer_bank_account'] + assert response.resources.customer_billing_detail == body.get('resources')['customer_billing_detail'] def test_timeout_billing_requests_collect_customer_details_doesnt_retry(): fixture = helpers.load_fixture('billing_requests')['collect_customer_details'] with helpers.stub_timeout(fixture) as rsps: - with assert_raises(requests.ConnectTimeout): + with pytest.raises(requests.ConnectTimeout): response = helpers.client.billing_requests.collect_customer_details(*fixture['url_params']) - assert_equal(1, len(rsps.calls)) + assert len(rsps.calls) == 1 def test_502_billing_requests_collect_customer_details_doesnt_retry(): fixture = helpers.load_fixture('billing_requests')['collect_customer_details'] with helpers.stub_502(fixture) as rsps: - with assert_raises(MalformedResponseError): + with pytest.raises(MalformedResponseError): response = helpers.client.billing_requests.collect_customer_details(*fixture['url_params']) - assert_equal(1, len(rsps.calls)) + assert len(rsps.calls) == 1 @responses.activate @@ -233,85 +167,57 @@ def test_billing_requests_collect_bank_account(): response = helpers.client.billing_requests.collect_bank_account(*fixture['url_params']) body = fixture['body']['billing_requests'] - assert_is_instance(response, resources.BillingRequest) - assert_is_not_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal(response.actions, body.get('actions')) - assert_equal(response.created_at, body.get('created_at')) - assert_equal(response.fallback_enabled, body.get('fallback_enabled')) - assert_equal(response.id, body.get('id')) - assert_equal(response.metadata, body.get('metadata')) - assert_equal(response.purpose_code, body.get('purpose_code')) - assert_equal(response.status, body.get('status')) - assert_equal(response.links.bank_authorisation, - body.get('links')['bank_authorisation']) - assert_equal(response.links.creditor, - body.get('links')['creditor']) - assert_equal(response.links.customer, - body.get('links')['customer']) - assert_equal(response.links.customer_bank_account, - body.get('links')['customer_bank_account']) - assert_equal(response.links.customer_billing_detail, - body.get('links')['customer_billing_detail']) - assert_equal(response.links.mandate_request, - body.get('links')['mandate_request']) - assert_equal(response.links.mandate_request_mandate, - body.get('links')['mandate_request_mandate']) - assert_equal(response.links.organisation, - body.get('links')['organisation']) - assert_equal(response.links.payment_request, - body.get('links')['payment_request']) - assert_equal(response.links.payment_request_payment, - body.get('links')['payment_request_payment']) - assert_equal(response.mandate_request.authorisation_source, - body.get('mandate_request')['authorisation_source']) - assert_equal(response.mandate_request.constraints, - body.get('mandate_request')['constraints']) - assert_equal(response.mandate_request.currency, - body.get('mandate_request')['currency']) - assert_equal(response.mandate_request.description, - body.get('mandate_request')['description']) - assert_equal(response.mandate_request.links, - body.get('mandate_request')['links']) - assert_equal(response.mandate_request.metadata, - body.get('mandate_request')['metadata']) - assert_equal(response.mandate_request.scheme, - body.get('mandate_request')['scheme']) - assert_equal(response.mandate_request.verify, - body.get('mandate_request')['verify']) - assert_equal(response.payment_request.amount, - body.get('payment_request')['amount']) - assert_equal(response.payment_request.app_fee, - body.get('payment_request')['app_fee']) - assert_equal(response.payment_request.currency, - body.get('payment_request')['currency']) - assert_equal(response.payment_request.description, - body.get('payment_request')['description']) - assert_equal(response.payment_request.links, - body.get('payment_request')['links']) - assert_equal(response.payment_request.metadata, - body.get('payment_request')['metadata']) - assert_equal(response.payment_request.scheme, - body.get('payment_request')['scheme']) - assert_equal(response.resources.customer, - body.get('resources')['customer']) - assert_equal(response.resources.customer_bank_account, - body.get('resources')['customer_bank_account']) - assert_equal(response.resources.customer_billing_detail, - body.get('resources')['customer_billing_detail']) + assert isinstance(response, resources.BillingRequest) + assert responses.calls[-1].request.headers.get('Idempotency-Key') is not None + assert response.actions == body.get('actions') + assert response.created_at == body.get('created_at') + assert response.fallback_enabled == body.get('fallback_enabled') + assert response.id == body.get('id') + assert response.metadata == body.get('metadata') + assert response.purpose_code == body.get('purpose_code') + assert response.status == body.get('status') + assert response.links.bank_authorisation == body.get('links')['bank_authorisation'] + assert response.links.creditor == body.get('links')['creditor'] + assert response.links.customer == body.get('links')['customer'] + assert response.links.customer_bank_account == body.get('links')['customer_bank_account'] + assert response.links.customer_billing_detail == body.get('links')['customer_billing_detail'] + assert response.links.mandate_request == body.get('links')['mandate_request'] + assert response.links.mandate_request_mandate == body.get('links')['mandate_request_mandate'] + assert response.links.organisation == body.get('links')['organisation'] + assert response.links.payment_request == body.get('links')['payment_request'] + assert response.links.payment_request_payment == body.get('links')['payment_request_payment'] + assert response.mandate_request.authorisation_source == body.get('mandate_request')['authorisation_source'] + assert response.mandate_request.constraints == body.get('mandate_request')['constraints'] + assert response.mandate_request.currency == body.get('mandate_request')['currency'] + assert response.mandate_request.description == body.get('mandate_request')['description'] + assert response.mandate_request.links == body.get('mandate_request')['links'] + assert response.mandate_request.metadata == body.get('mandate_request')['metadata'] + assert response.mandate_request.scheme == body.get('mandate_request')['scheme'] + assert response.mandate_request.verify == body.get('mandate_request')['verify'] + assert response.payment_request.amount == body.get('payment_request')['amount'] + assert response.payment_request.app_fee == body.get('payment_request')['app_fee'] + assert response.payment_request.currency == body.get('payment_request')['currency'] + assert response.payment_request.description == body.get('payment_request')['description'] + assert response.payment_request.links == body.get('payment_request')['links'] + assert response.payment_request.metadata == body.get('payment_request')['metadata'] + assert response.payment_request.scheme == body.get('payment_request')['scheme'] + assert response.resources.customer == body.get('resources')['customer'] + assert response.resources.customer_bank_account == body.get('resources')['customer_bank_account'] + assert response.resources.customer_billing_detail == body.get('resources')['customer_billing_detail'] def test_timeout_billing_requests_collect_bank_account_doesnt_retry(): fixture = helpers.load_fixture('billing_requests')['collect_bank_account'] with helpers.stub_timeout(fixture) as rsps: - with assert_raises(requests.ConnectTimeout): + with pytest.raises(requests.ConnectTimeout): response = helpers.client.billing_requests.collect_bank_account(*fixture['url_params']) - assert_equal(1, len(rsps.calls)) + assert len(rsps.calls) == 1 def test_502_billing_requests_collect_bank_account_doesnt_retry(): fixture = helpers.load_fixture('billing_requests')['collect_bank_account'] with helpers.stub_502(fixture) as rsps: - with assert_raises(MalformedResponseError): + with pytest.raises(MalformedResponseError): response = helpers.client.billing_requests.collect_bank_account(*fixture['url_params']) - assert_equal(1, len(rsps.calls)) + assert len(rsps.calls) == 1 @responses.activate @@ -321,85 +227,57 @@ def test_billing_requests_confirm_payer_details(): response = helpers.client.billing_requests.confirm_payer_details(*fixture['url_params']) body = fixture['body']['billing_requests'] - assert_is_instance(response, resources.BillingRequest) - assert_is_not_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal(response.actions, body.get('actions')) - assert_equal(response.created_at, body.get('created_at')) - assert_equal(response.fallback_enabled, body.get('fallback_enabled')) - assert_equal(response.id, body.get('id')) - assert_equal(response.metadata, body.get('metadata')) - assert_equal(response.purpose_code, body.get('purpose_code')) - assert_equal(response.status, body.get('status')) - assert_equal(response.links.bank_authorisation, - body.get('links')['bank_authorisation']) - assert_equal(response.links.creditor, - body.get('links')['creditor']) - assert_equal(response.links.customer, - body.get('links')['customer']) - assert_equal(response.links.customer_bank_account, - body.get('links')['customer_bank_account']) - assert_equal(response.links.customer_billing_detail, - body.get('links')['customer_billing_detail']) - assert_equal(response.links.mandate_request, - body.get('links')['mandate_request']) - assert_equal(response.links.mandate_request_mandate, - body.get('links')['mandate_request_mandate']) - assert_equal(response.links.organisation, - body.get('links')['organisation']) - assert_equal(response.links.payment_request, - body.get('links')['payment_request']) - assert_equal(response.links.payment_request_payment, - body.get('links')['payment_request_payment']) - assert_equal(response.mandate_request.authorisation_source, - body.get('mandate_request')['authorisation_source']) - assert_equal(response.mandate_request.constraints, - body.get('mandate_request')['constraints']) - assert_equal(response.mandate_request.currency, - body.get('mandate_request')['currency']) - assert_equal(response.mandate_request.description, - body.get('mandate_request')['description']) - assert_equal(response.mandate_request.links, - body.get('mandate_request')['links']) - assert_equal(response.mandate_request.metadata, - body.get('mandate_request')['metadata']) - assert_equal(response.mandate_request.scheme, - body.get('mandate_request')['scheme']) - assert_equal(response.mandate_request.verify, - body.get('mandate_request')['verify']) - assert_equal(response.payment_request.amount, - body.get('payment_request')['amount']) - assert_equal(response.payment_request.app_fee, - body.get('payment_request')['app_fee']) - assert_equal(response.payment_request.currency, - body.get('payment_request')['currency']) - assert_equal(response.payment_request.description, - body.get('payment_request')['description']) - assert_equal(response.payment_request.links, - body.get('payment_request')['links']) - assert_equal(response.payment_request.metadata, - body.get('payment_request')['metadata']) - assert_equal(response.payment_request.scheme, - body.get('payment_request')['scheme']) - assert_equal(response.resources.customer, - body.get('resources')['customer']) - assert_equal(response.resources.customer_bank_account, - body.get('resources')['customer_bank_account']) - assert_equal(response.resources.customer_billing_detail, - body.get('resources')['customer_billing_detail']) + assert isinstance(response, resources.BillingRequest) + assert responses.calls[-1].request.headers.get('Idempotency-Key') is not None + assert response.actions == body.get('actions') + assert response.created_at == body.get('created_at') + assert response.fallback_enabled == body.get('fallback_enabled') + assert response.id == body.get('id') + assert response.metadata == body.get('metadata') + assert response.purpose_code == body.get('purpose_code') + assert response.status == body.get('status') + assert response.links.bank_authorisation == body.get('links')['bank_authorisation'] + assert response.links.creditor == body.get('links')['creditor'] + assert response.links.customer == body.get('links')['customer'] + assert response.links.customer_bank_account == body.get('links')['customer_bank_account'] + assert response.links.customer_billing_detail == body.get('links')['customer_billing_detail'] + assert response.links.mandate_request == body.get('links')['mandate_request'] + assert response.links.mandate_request_mandate == body.get('links')['mandate_request_mandate'] + assert response.links.organisation == body.get('links')['organisation'] + assert response.links.payment_request == body.get('links')['payment_request'] + assert response.links.payment_request_payment == body.get('links')['payment_request_payment'] + assert response.mandate_request.authorisation_source == body.get('mandate_request')['authorisation_source'] + assert response.mandate_request.constraints == body.get('mandate_request')['constraints'] + assert response.mandate_request.currency == body.get('mandate_request')['currency'] + assert response.mandate_request.description == body.get('mandate_request')['description'] + assert response.mandate_request.links == body.get('mandate_request')['links'] + assert response.mandate_request.metadata == body.get('mandate_request')['metadata'] + assert response.mandate_request.scheme == body.get('mandate_request')['scheme'] + assert response.mandate_request.verify == body.get('mandate_request')['verify'] + assert response.payment_request.amount == body.get('payment_request')['amount'] + assert response.payment_request.app_fee == body.get('payment_request')['app_fee'] + assert response.payment_request.currency == body.get('payment_request')['currency'] + assert response.payment_request.description == body.get('payment_request')['description'] + assert response.payment_request.links == body.get('payment_request')['links'] + assert response.payment_request.metadata == body.get('payment_request')['metadata'] + assert response.payment_request.scheme == body.get('payment_request')['scheme'] + assert response.resources.customer == body.get('resources')['customer'] + assert response.resources.customer_bank_account == body.get('resources')['customer_bank_account'] + assert response.resources.customer_billing_detail == body.get('resources')['customer_billing_detail'] def test_timeout_billing_requests_confirm_payer_details_doesnt_retry(): fixture = helpers.load_fixture('billing_requests')['confirm_payer_details'] with helpers.stub_timeout(fixture) as rsps: - with assert_raises(requests.ConnectTimeout): + with pytest.raises(requests.ConnectTimeout): response = helpers.client.billing_requests.confirm_payer_details(*fixture['url_params']) - assert_equal(1, len(rsps.calls)) + assert len(rsps.calls) == 1 def test_502_billing_requests_confirm_payer_details_doesnt_retry(): fixture = helpers.load_fixture('billing_requests')['confirm_payer_details'] with helpers.stub_502(fixture) as rsps: - with assert_raises(MalformedResponseError): + with pytest.raises(MalformedResponseError): response = helpers.client.billing_requests.confirm_payer_details(*fixture['url_params']) - assert_equal(1, len(rsps.calls)) + assert len(rsps.calls) == 1 @responses.activate @@ -409,85 +287,57 @@ def test_billing_requests_fulfil(): response = helpers.client.billing_requests.fulfil(*fixture['url_params']) body = fixture['body']['billing_requests'] - assert_is_instance(response, resources.BillingRequest) - assert_is_not_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal(response.actions, body.get('actions')) - assert_equal(response.created_at, body.get('created_at')) - assert_equal(response.fallback_enabled, body.get('fallback_enabled')) - assert_equal(response.id, body.get('id')) - assert_equal(response.metadata, body.get('metadata')) - assert_equal(response.purpose_code, body.get('purpose_code')) - assert_equal(response.status, body.get('status')) - assert_equal(response.links.bank_authorisation, - body.get('links')['bank_authorisation']) - assert_equal(response.links.creditor, - body.get('links')['creditor']) - assert_equal(response.links.customer, - body.get('links')['customer']) - assert_equal(response.links.customer_bank_account, - body.get('links')['customer_bank_account']) - assert_equal(response.links.customer_billing_detail, - body.get('links')['customer_billing_detail']) - assert_equal(response.links.mandate_request, - body.get('links')['mandate_request']) - assert_equal(response.links.mandate_request_mandate, - body.get('links')['mandate_request_mandate']) - assert_equal(response.links.organisation, - body.get('links')['organisation']) - assert_equal(response.links.payment_request, - body.get('links')['payment_request']) - assert_equal(response.links.payment_request_payment, - body.get('links')['payment_request_payment']) - assert_equal(response.mandate_request.authorisation_source, - body.get('mandate_request')['authorisation_source']) - assert_equal(response.mandate_request.constraints, - body.get('mandate_request')['constraints']) - assert_equal(response.mandate_request.currency, - body.get('mandate_request')['currency']) - assert_equal(response.mandate_request.description, - body.get('mandate_request')['description']) - assert_equal(response.mandate_request.links, - body.get('mandate_request')['links']) - assert_equal(response.mandate_request.metadata, - body.get('mandate_request')['metadata']) - assert_equal(response.mandate_request.scheme, - body.get('mandate_request')['scheme']) - assert_equal(response.mandate_request.verify, - body.get('mandate_request')['verify']) - assert_equal(response.payment_request.amount, - body.get('payment_request')['amount']) - assert_equal(response.payment_request.app_fee, - body.get('payment_request')['app_fee']) - assert_equal(response.payment_request.currency, - body.get('payment_request')['currency']) - assert_equal(response.payment_request.description, - body.get('payment_request')['description']) - assert_equal(response.payment_request.links, - body.get('payment_request')['links']) - assert_equal(response.payment_request.metadata, - body.get('payment_request')['metadata']) - assert_equal(response.payment_request.scheme, - body.get('payment_request')['scheme']) - assert_equal(response.resources.customer, - body.get('resources')['customer']) - assert_equal(response.resources.customer_bank_account, - body.get('resources')['customer_bank_account']) - assert_equal(response.resources.customer_billing_detail, - body.get('resources')['customer_billing_detail']) + assert isinstance(response, resources.BillingRequest) + assert responses.calls[-1].request.headers.get('Idempotency-Key') is not None + assert response.actions == body.get('actions') + assert response.created_at == body.get('created_at') + assert response.fallback_enabled == body.get('fallback_enabled') + assert response.id == body.get('id') + assert response.metadata == body.get('metadata') + assert response.purpose_code == body.get('purpose_code') + assert response.status == body.get('status') + assert response.links.bank_authorisation == body.get('links')['bank_authorisation'] + assert response.links.creditor == body.get('links')['creditor'] + assert response.links.customer == body.get('links')['customer'] + assert response.links.customer_bank_account == body.get('links')['customer_bank_account'] + assert response.links.customer_billing_detail == body.get('links')['customer_billing_detail'] + assert response.links.mandate_request == body.get('links')['mandate_request'] + assert response.links.mandate_request_mandate == body.get('links')['mandate_request_mandate'] + assert response.links.organisation == body.get('links')['organisation'] + assert response.links.payment_request == body.get('links')['payment_request'] + assert response.links.payment_request_payment == body.get('links')['payment_request_payment'] + assert response.mandate_request.authorisation_source == body.get('mandate_request')['authorisation_source'] + assert response.mandate_request.constraints == body.get('mandate_request')['constraints'] + assert response.mandate_request.currency == body.get('mandate_request')['currency'] + assert response.mandate_request.description == body.get('mandate_request')['description'] + assert response.mandate_request.links == body.get('mandate_request')['links'] + assert response.mandate_request.metadata == body.get('mandate_request')['metadata'] + assert response.mandate_request.scheme == body.get('mandate_request')['scheme'] + assert response.mandate_request.verify == body.get('mandate_request')['verify'] + assert response.payment_request.amount == body.get('payment_request')['amount'] + assert response.payment_request.app_fee == body.get('payment_request')['app_fee'] + assert response.payment_request.currency == body.get('payment_request')['currency'] + assert response.payment_request.description == body.get('payment_request')['description'] + assert response.payment_request.links == body.get('payment_request')['links'] + assert response.payment_request.metadata == body.get('payment_request')['metadata'] + assert response.payment_request.scheme == body.get('payment_request')['scheme'] + assert response.resources.customer == body.get('resources')['customer'] + assert response.resources.customer_bank_account == body.get('resources')['customer_bank_account'] + assert response.resources.customer_billing_detail == body.get('resources')['customer_billing_detail'] def test_timeout_billing_requests_fulfil_doesnt_retry(): fixture = helpers.load_fixture('billing_requests')['fulfil'] with helpers.stub_timeout(fixture) as rsps: - with assert_raises(requests.ConnectTimeout): + with pytest.raises(requests.ConnectTimeout): response = helpers.client.billing_requests.fulfil(*fixture['url_params']) - assert_equal(1, len(rsps.calls)) + assert len(rsps.calls) == 1 def test_502_billing_requests_fulfil_doesnt_retry(): fixture = helpers.load_fixture('billing_requests')['fulfil'] with helpers.stub_502(fixture) as rsps: - with assert_raises(MalformedResponseError): + with pytest.raises(MalformedResponseError): response = helpers.client.billing_requests.fulfil(*fixture['url_params']) - assert_equal(1, len(rsps.calls)) + assert len(rsps.calls) == 1 @responses.activate @@ -497,85 +347,57 @@ def test_billing_requests_cancel(): response = helpers.client.billing_requests.cancel(*fixture['url_params']) body = fixture['body']['billing_requests'] - assert_is_instance(response, resources.BillingRequest) - assert_is_not_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal(response.actions, body.get('actions')) - assert_equal(response.created_at, body.get('created_at')) - assert_equal(response.fallback_enabled, body.get('fallback_enabled')) - assert_equal(response.id, body.get('id')) - assert_equal(response.metadata, body.get('metadata')) - assert_equal(response.purpose_code, body.get('purpose_code')) - assert_equal(response.status, body.get('status')) - assert_equal(response.links.bank_authorisation, - body.get('links')['bank_authorisation']) - assert_equal(response.links.creditor, - body.get('links')['creditor']) - assert_equal(response.links.customer, - body.get('links')['customer']) - assert_equal(response.links.customer_bank_account, - body.get('links')['customer_bank_account']) - assert_equal(response.links.customer_billing_detail, - body.get('links')['customer_billing_detail']) - assert_equal(response.links.mandate_request, - body.get('links')['mandate_request']) - assert_equal(response.links.mandate_request_mandate, - body.get('links')['mandate_request_mandate']) - assert_equal(response.links.organisation, - body.get('links')['organisation']) - assert_equal(response.links.payment_request, - body.get('links')['payment_request']) - assert_equal(response.links.payment_request_payment, - body.get('links')['payment_request_payment']) - assert_equal(response.mandate_request.authorisation_source, - body.get('mandate_request')['authorisation_source']) - assert_equal(response.mandate_request.constraints, - body.get('mandate_request')['constraints']) - assert_equal(response.mandate_request.currency, - body.get('mandate_request')['currency']) - assert_equal(response.mandate_request.description, - body.get('mandate_request')['description']) - assert_equal(response.mandate_request.links, - body.get('mandate_request')['links']) - assert_equal(response.mandate_request.metadata, - body.get('mandate_request')['metadata']) - assert_equal(response.mandate_request.scheme, - body.get('mandate_request')['scheme']) - assert_equal(response.mandate_request.verify, - body.get('mandate_request')['verify']) - assert_equal(response.payment_request.amount, - body.get('payment_request')['amount']) - assert_equal(response.payment_request.app_fee, - body.get('payment_request')['app_fee']) - assert_equal(response.payment_request.currency, - body.get('payment_request')['currency']) - assert_equal(response.payment_request.description, - body.get('payment_request')['description']) - assert_equal(response.payment_request.links, - body.get('payment_request')['links']) - assert_equal(response.payment_request.metadata, - body.get('payment_request')['metadata']) - assert_equal(response.payment_request.scheme, - body.get('payment_request')['scheme']) - assert_equal(response.resources.customer, - body.get('resources')['customer']) - assert_equal(response.resources.customer_bank_account, - body.get('resources')['customer_bank_account']) - assert_equal(response.resources.customer_billing_detail, - body.get('resources')['customer_billing_detail']) + assert isinstance(response, resources.BillingRequest) + assert responses.calls[-1].request.headers.get('Idempotency-Key') is not None + assert response.actions == body.get('actions') + assert response.created_at == body.get('created_at') + assert response.fallback_enabled == body.get('fallback_enabled') + assert response.id == body.get('id') + assert response.metadata == body.get('metadata') + assert response.purpose_code == body.get('purpose_code') + assert response.status == body.get('status') + assert response.links.bank_authorisation == body.get('links')['bank_authorisation'] + assert response.links.creditor == body.get('links')['creditor'] + assert response.links.customer == body.get('links')['customer'] + assert response.links.customer_bank_account == body.get('links')['customer_bank_account'] + assert response.links.customer_billing_detail == body.get('links')['customer_billing_detail'] + assert response.links.mandate_request == body.get('links')['mandate_request'] + assert response.links.mandate_request_mandate == body.get('links')['mandate_request_mandate'] + assert response.links.organisation == body.get('links')['organisation'] + assert response.links.payment_request == body.get('links')['payment_request'] + assert response.links.payment_request_payment == body.get('links')['payment_request_payment'] + assert response.mandate_request.authorisation_source == body.get('mandate_request')['authorisation_source'] + assert response.mandate_request.constraints == body.get('mandate_request')['constraints'] + assert response.mandate_request.currency == body.get('mandate_request')['currency'] + assert response.mandate_request.description == body.get('mandate_request')['description'] + assert response.mandate_request.links == body.get('mandate_request')['links'] + assert response.mandate_request.metadata == body.get('mandate_request')['metadata'] + assert response.mandate_request.scheme == body.get('mandate_request')['scheme'] + assert response.mandate_request.verify == body.get('mandate_request')['verify'] + assert response.payment_request.amount == body.get('payment_request')['amount'] + assert response.payment_request.app_fee == body.get('payment_request')['app_fee'] + assert response.payment_request.currency == body.get('payment_request')['currency'] + assert response.payment_request.description == body.get('payment_request')['description'] + assert response.payment_request.links == body.get('payment_request')['links'] + assert response.payment_request.metadata == body.get('payment_request')['metadata'] + assert response.payment_request.scheme == body.get('payment_request')['scheme'] + assert response.resources.customer == body.get('resources')['customer'] + assert response.resources.customer_bank_account == body.get('resources')['customer_bank_account'] + assert response.resources.customer_billing_detail == body.get('resources')['customer_billing_detail'] def test_timeout_billing_requests_cancel_doesnt_retry(): fixture = helpers.load_fixture('billing_requests')['cancel'] with helpers.stub_timeout(fixture) as rsps: - with assert_raises(requests.ConnectTimeout): + with pytest.raises(requests.ConnectTimeout): response = helpers.client.billing_requests.cancel(*fixture['url_params']) - assert_equal(1, len(rsps.calls)) + assert len(rsps.calls) == 1 def test_502_billing_requests_cancel_doesnt_retry(): fixture = helpers.load_fixture('billing_requests')['cancel'] with helpers.stub_502(fixture) as rsps: - with assert_raises(MalformedResponseError): + with pytest.raises(MalformedResponseError): response = helpers.client.billing_requests.cancel(*fixture['url_params']) - assert_equal(1, len(rsps.calls)) + assert len(rsps.calls) == 1 @responses.activate @@ -585,57 +407,48 @@ def test_billing_requests_list(): response = helpers.client.billing_requests.list(*fixture['url_params']) body = fixture['body']['billing_requests'] - assert_is_instance(response, list_response.ListResponse) - assert_is_instance(response.records[0], resources.BillingRequest) - - assert_equal(response.before, fixture['body']['meta']['cursors']['before']) - assert_equal(response.after, fixture['body']['meta']['cursors']['after']) - assert_is_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal([r.actions for r in response.records], - [b.get('actions') for b in body]) - assert_equal([r.created_at for r in response.records], - [b.get('created_at') for b in body]) - assert_equal([r.fallback_enabled for r in response.records], - [b.get('fallback_enabled') for b in body]) - assert_equal([r.id for r in response.records], - [b.get('id') for b in body]) - assert_equal([r.metadata for r in response.records], - [b.get('metadata') for b in body]) - assert_equal([r.purpose_code for r in response.records], - [b.get('purpose_code') for b in body]) - assert_equal([r.status for r in response.records], - [b.get('status') for b in body]) + assert isinstance(response, list_response.ListResponse) + assert isinstance(response.records[0], resources.BillingRequest) + + assert response.before == fixture['body']['meta']['cursors']['before'] + assert response.after == fixture['body']['meta']['cursors']['after'] + assert responses.calls[-1].request.headers.get('Idempotency-Key') is None + assert [r.actions for r in response.records] == [b.get('actions') for b in body] + assert [r.created_at for r in response.records] == [b.get('created_at') for b in body] + assert [r.fallback_enabled for r in response.records] == [b.get('fallback_enabled') for b in body] + assert [r.id for r in response.records] == [b.get('id') for b in body] + assert [r.metadata for r in response.records] == [b.get('metadata') for b in body] + assert [r.purpose_code for r in response.records] == [b.get('purpose_code') for b in body] + assert [r.status for r in response.records] == [b.get('status') for b in body] @responses.activate def test_timeout_billing_requests_list_retries(): fixture = helpers.load_fixture('billing_requests')['list'] with helpers.stub_timeout_then_response(fixture) as rsps: response = helpers.client.billing_requests.list(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['billing_requests'] - assert_is_instance(response, list_response.ListResponse) - assert_is_instance(response.records[0], resources.BillingRequest) + assert isinstance(response, list_response.ListResponse) + assert isinstance(response.records[0], resources.BillingRequest) - assert_equal(response.before, fixture['body']['meta']['cursors']['before']) - assert_equal(response.after, fixture['body']['meta']['cursors']['after']) + assert response.before == fixture['body']['meta']['cursors']['before'] + assert response.after == fixture['body']['meta']['cursors']['after'] def test_502_billing_requests_list_retries(): fixture = helpers.load_fixture('billing_requests')['list'] with helpers.stub_502_then_response(fixture) as rsps: response = helpers.client.billing_requests.list(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['billing_requests'] - assert_is_instance(response, list_response.ListResponse) - assert_is_instance(response.records[0], resources.BillingRequest) + assert isinstance(response, list_response.ListResponse) + assert isinstance(response.records[0], resources.BillingRequest) - assert_equal(response.before, fixture['body']['meta']['cursors']['before']) - assert_equal(response.after, fixture['body']['meta']['cursors']['after']) + assert response.before == fixture['body']['meta']['cursors']['before'] + assert response.after == fixture['body']['meta']['cursors']['after'] @responses.activate def test_billing_requests_all(): @@ -652,9 +465,9 @@ def callback(request): responses.add_callback(fixture['method'], url, callback) all_records = list(helpers.client.billing_requests.all()) - assert_equal(len(all_records), len(fixture['body']['billing_requests']) * 2) + assert len(all_records) == len(fixture['body']['billing_requests']) * 2 for record in all_records: - assert_is_instance(record, resources.BillingRequest) + assert isinstance(record, resources.BillingRequest) @@ -665,94 +478,64 @@ def test_billing_requests_get(): response = helpers.client.billing_requests.get(*fixture['url_params']) body = fixture['body']['billing_requests'] - assert_is_instance(response, resources.BillingRequest) - assert_is_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal(response.actions, body.get('actions')) - assert_equal(response.created_at, body.get('created_at')) - assert_equal(response.fallback_enabled, body.get('fallback_enabled')) - assert_equal(response.id, body.get('id')) - assert_equal(response.metadata, body.get('metadata')) - assert_equal(response.purpose_code, body.get('purpose_code')) - assert_equal(response.status, body.get('status')) - assert_equal(response.links.bank_authorisation, - body.get('links')['bank_authorisation']) - assert_equal(response.links.creditor, - body.get('links')['creditor']) - assert_equal(response.links.customer, - body.get('links')['customer']) - assert_equal(response.links.customer_bank_account, - body.get('links')['customer_bank_account']) - assert_equal(response.links.customer_billing_detail, - body.get('links')['customer_billing_detail']) - assert_equal(response.links.mandate_request, - body.get('links')['mandate_request']) - assert_equal(response.links.mandate_request_mandate, - body.get('links')['mandate_request_mandate']) - assert_equal(response.links.organisation, - body.get('links')['organisation']) - assert_equal(response.links.payment_request, - body.get('links')['payment_request']) - assert_equal(response.links.payment_request_payment, - body.get('links')['payment_request_payment']) - assert_equal(response.mandate_request.authorisation_source, - body.get('mandate_request')['authorisation_source']) - assert_equal(response.mandate_request.constraints, - body.get('mandate_request')['constraints']) - assert_equal(response.mandate_request.currency, - body.get('mandate_request')['currency']) - assert_equal(response.mandate_request.description, - body.get('mandate_request')['description']) - assert_equal(response.mandate_request.links, - body.get('mandate_request')['links']) - assert_equal(response.mandate_request.metadata, - body.get('mandate_request')['metadata']) - assert_equal(response.mandate_request.scheme, - body.get('mandate_request')['scheme']) - assert_equal(response.mandate_request.verify, - body.get('mandate_request')['verify']) - assert_equal(response.payment_request.amount, - body.get('payment_request')['amount']) - assert_equal(response.payment_request.app_fee, - body.get('payment_request')['app_fee']) - assert_equal(response.payment_request.currency, - body.get('payment_request')['currency']) - assert_equal(response.payment_request.description, - body.get('payment_request')['description']) - assert_equal(response.payment_request.links, - body.get('payment_request')['links']) - assert_equal(response.payment_request.metadata, - body.get('payment_request')['metadata']) - assert_equal(response.payment_request.scheme, - body.get('payment_request')['scheme']) - assert_equal(response.resources.customer, - body.get('resources')['customer']) - assert_equal(response.resources.customer_bank_account, - body.get('resources')['customer_bank_account']) - assert_equal(response.resources.customer_billing_detail, - body.get('resources')['customer_billing_detail']) + assert isinstance(response, resources.BillingRequest) + assert responses.calls[-1].request.headers.get('Idempotency-Key') is None + assert response.actions == body.get('actions') + assert response.created_at == body.get('created_at') + assert response.fallback_enabled == body.get('fallback_enabled') + assert response.id == body.get('id') + assert response.metadata == body.get('metadata') + assert response.purpose_code == body.get('purpose_code') + assert response.status == body.get('status') + assert response.links.bank_authorisation == body.get('links')['bank_authorisation'] + assert response.links.creditor == body.get('links')['creditor'] + assert response.links.customer == body.get('links')['customer'] + assert response.links.customer_bank_account == body.get('links')['customer_bank_account'] + assert response.links.customer_billing_detail == body.get('links')['customer_billing_detail'] + assert response.links.mandate_request == body.get('links')['mandate_request'] + assert response.links.mandate_request_mandate == body.get('links')['mandate_request_mandate'] + assert response.links.organisation == body.get('links')['organisation'] + assert response.links.payment_request == body.get('links')['payment_request'] + assert response.links.payment_request_payment == body.get('links')['payment_request_payment'] + assert response.mandate_request.authorisation_source == body.get('mandate_request')['authorisation_source'] + assert response.mandate_request.constraints == body.get('mandate_request')['constraints'] + assert response.mandate_request.currency == body.get('mandate_request')['currency'] + assert response.mandate_request.description == body.get('mandate_request')['description'] + assert response.mandate_request.links == body.get('mandate_request')['links'] + assert response.mandate_request.metadata == body.get('mandate_request')['metadata'] + assert response.mandate_request.scheme == body.get('mandate_request')['scheme'] + assert response.mandate_request.verify == body.get('mandate_request')['verify'] + assert response.payment_request.amount == body.get('payment_request')['amount'] + assert response.payment_request.app_fee == body.get('payment_request')['app_fee'] + assert response.payment_request.currency == body.get('payment_request')['currency'] + assert response.payment_request.description == body.get('payment_request')['description'] + assert response.payment_request.links == body.get('payment_request')['links'] + assert response.payment_request.metadata == body.get('payment_request')['metadata'] + assert response.payment_request.scheme == body.get('payment_request')['scheme'] + assert response.resources.customer == body.get('resources')['customer'] + assert response.resources.customer_bank_account == body.get('resources')['customer_bank_account'] + assert response.resources.customer_billing_detail == body.get('resources')['customer_billing_detail'] @responses.activate def test_timeout_billing_requests_get_retries(): fixture = helpers.load_fixture('billing_requests')['get'] with helpers.stub_timeout_then_response(fixture) as rsps: response = helpers.client.billing_requests.get(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['billing_requests'] - assert_is_instance(response, resources.BillingRequest) + assert isinstance(response, resources.BillingRequest) def test_502_billing_requests_get_retries(): fixture = helpers.load_fixture('billing_requests')['get'] with helpers.stub_502_then_response(fixture) as rsps: response = helpers.client.billing_requests.get(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['billing_requests'] - assert_is_instance(response, resources.BillingRequest) + assert isinstance(response, resources.BillingRequest) @responses.activate @@ -762,85 +545,57 @@ def test_billing_requests_notify(): response = helpers.client.billing_requests.notify(*fixture['url_params']) body = fixture['body']['billing_requests'] - assert_is_instance(response, resources.BillingRequest) - assert_is_not_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal(response.actions, body.get('actions')) - assert_equal(response.created_at, body.get('created_at')) - assert_equal(response.fallback_enabled, body.get('fallback_enabled')) - assert_equal(response.id, body.get('id')) - assert_equal(response.metadata, body.get('metadata')) - assert_equal(response.purpose_code, body.get('purpose_code')) - assert_equal(response.status, body.get('status')) - assert_equal(response.links.bank_authorisation, - body.get('links')['bank_authorisation']) - assert_equal(response.links.creditor, - body.get('links')['creditor']) - assert_equal(response.links.customer, - body.get('links')['customer']) - assert_equal(response.links.customer_bank_account, - body.get('links')['customer_bank_account']) - assert_equal(response.links.customer_billing_detail, - body.get('links')['customer_billing_detail']) - assert_equal(response.links.mandate_request, - body.get('links')['mandate_request']) - assert_equal(response.links.mandate_request_mandate, - body.get('links')['mandate_request_mandate']) - assert_equal(response.links.organisation, - body.get('links')['organisation']) - assert_equal(response.links.payment_request, - body.get('links')['payment_request']) - assert_equal(response.links.payment_request_payment, - body.get('links')['payment_request_payment']) - assert_equal(response.mandate_request.authorisation_source, - body.get('mandate_request')['authorisation_source']) - assert_equal(response.mandate_request.constraints, - body.get('mandate_request')['constraints']) - assert_equal(response.mandate_request.currency, - body.get('mandate_request')['currency']) - assert_equal(response.mandate_request.description, - body.get('mandate_request')['description']) - assert_equal(response.mandate_request.links, - body.get('mandate_request')['links']) - assert_equal(response.mandate_request.metadata, - body.get('mandate_request')['metadata']) - assert_equal(response.mandate_request.scheme, - body.get('mandate_request')['scheme']) - assert_equal(response.mandate_request.verify, - body.get('mandate_request')['verify']) - assert_equal(response.payment_request.amount, - body.get('payment_request')['amount']) - assert_equal(response.payment_request.app_fee, - body.get('payment_request')['app_fee']) - assert_equal(response.payment_request.currency, - body.get('payment_request')['currency']) - assert_equal(response.payment_request.description, - body.get('payment_request')['description']) - assert_equal(response.payment_request.links, - body.get('payment_request')['links']) - assert_equal(response.payment_request.metadata, - body.get('payment_request')['metadata']) - assert_equal(response.payment_request.scheme, - body.get('payment_request')['scheme']) - assert_equal(response.resources.customer, - body.get('resources')['customer']) - assert_equal(response.resources.customer_bank_account, - body.get('resources')['customer_bank_account']) - assert_equal(response.resources.customer_billing_detail, - body.get('resources')['customer_billing_detail']) + assert isinstance(response, resources.BillingRequest) + assert responses.calls[-1].request.headers.get('Idempotency-Key') is not None + assert response.actions == body.get('actions') + assert response.created_at == body.get('created_at') + assert response.fallback_enabled == body.get('fallback_enabled') + assert response.id == body.get('id') + assert response.metadata == body.get('metadata') + assert response.purpose_code == body.get('purpose_code') + assert response.status == body.get('status') + assert response.links.bank_authorisation == body.get('links')['bank_authorisation'] + assert response.links.creditor == body.get('links')['creditor'] + assert response.links.customer == body.get('links')['customer'] + assert response.links.customer_bank_account == body.get('links')['customer_bank_account'] + assert response.links.customer_billing_detail == body.get('links')['customer_billing_detail'] + assert response.links.mandate_request == body.get('links')['mandate_request'] + assert response.links.mandate_request_mandate == body.get('links')['mandate_request_mandate'] + assert response.links.organisation == body.get('links')['organisation'] + assert response.links.payment_request == body.get('links')['payment_request'] + assert response.links.payment_request_payment == body.get('links')['payment_request_payment'] + assert response.mandate_request.authorisation_source == body.get('mandate_request')['authorisation_source'] + assert response.mandate_request.constraints == body.get('mandate_request')['constraints'] + assert response.mandate_request.currency == body.get('mandate_request')['currency'] + assert response.mandate_request.description == body.get('mandate_request')['description'] + assert response.mandate_request.links == body.get('mandate_request')['links'] + assert response.mandate_request.metadata == body.get('mandate_request')['metadata'] + assert response.mandate_request.scheme == body.get('mandate_request')['scheme'] + assert response.mandate_request.verify == body.get('mandate_request')['verify'] + assert response.payment_request.amount == body.get('payment_request')['amount'] + assert response.payment_request.app_fee == body.get('payment_request')['app_fee'] + assert response.payment_request.currency == body.get('payment_request')['currency'] + assert response.payment_request.description == body.get('payment_request')['description'] + assert response.payment_request.links == body.get('payment_request')['links'] + assert response.payment_request.metadata == body.get('payment_request')['metadata'] + assert response.payment_request.scheme == body.get('payment_request')['scheme'] + assert response.resources.customer == body.get('resources')['customer'] + assert response.resources.customer_bank_account == body.get('resources')['customer_bank_account'] + assert response.resources.customer_billing_detail == body.get('resources')['customer_billing_detail'] def test_timeout_billing_requests_notify_doesnt_retry(): fixture = helpers.load_fixture('billing_requests')['notify'] with helpers.stub_timeout(fixture) as rsps: - with assert_raises(requests.ConnectTimeout): + with pytest.raises(requests.ConnectTimeout): response = helpers.client.billing_requests.notify(*fixture['url_params']) - assert_equal(1, len(rsps.calls)) + assert len(rsps.calls) == 1 def test_502_billing_requests_notify_doesnt_retry(): fixture = helpers.load_fixture('billing_requests')['notify'] with helpers.stub_502(fixture) as rsps: - with assert_raises(MalformedResponseError): + with pytest.raises(MalformedResponseError): response = helpers.client.billing_requests.notify(*fixture['url_params']) - assert_equal(1, len(rsps.calls)) + assert len(rsps.calls) == 1 @responses.activate @@ -850,85 +605,57 @@ def test_billing_requests_fallback(): response = helpers.client.billing_requests.fallback(*fixture['url_params']) body = fixture['body']['billing_requests'] - assert_is_instance(response, resources.BillingRequest) - assert_is_not_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal(response.actions, body.get('actions')) - assert_equal(response.created_at, body.get('created_at')) - assert_equal(response.fallback_enabled, body.get('fallback_enabled')) - assert_equal(response.id, body.get('id')) - assert_equal(response.metadata, body.get('metadata')) - assert_equal(response.purpose_code, body.get('purpose_code')) - assert_equal(response.status, body.get('status')) - assert_equal(response.links.bank_authorisation, - body.get('links')['bank_authorisation']) - assert_equal(response.links.creditor, - body.get('links')['creditor']) - assert_equal(response.links.customer, - body.get('links')['customer']) - assert_equal(response.links.customer_bank_account, - body.get('links')['customer_bank_account']) - assert_equal(response.links.customer_billing_detail, - body.get('links')['customer_billing_detail']) - assert_equal(response.links.mandate_request, - body.get('links')['mandate_request']) - assert_equal(response.links.mandate_request_mandate, - body.get('links')['mandate_request_mandate']) - assert_equal(response.links.organisation, - body.get('links')['organisation']) - assert_equal(response.links.payment_request, - body.get('links')['payment_request']) - assert_equal(response.links.payment_request_payment, - body.get('links')['payment_request_payment']) - assert_equal(response.mandate_request.authorisation_source, - body.get('mandate_request')['authorisation_source']) - assert_equal(response.mandate_request.constraints, - body.get('mandate_request')['constraints']) - assert_equal(response.mandate_request.currency, - body.get('mandate_request')['currency']) - assert_equal(response.mandate_request.description, - body.get('mandate_request')['description']) - assert_equal(response.mandate_request.links, - body.get('mandate_request')['links']) - assert_equal(response.mandate_request.metadata, - body.get('mandate_request')['metadata']) - assert_equal(response.mandate_request.scheme, - body.get('mandate_request')['scheme']) - assert_equal(response.mandate_request.verify, - body.get('mandate_request')['verify']) - assert_equal(response.payment_request.amount, - body.get('payment_request')['amount']) - assert_equal(response.payment_request.app_fee, - body.get('payment_request')['app_fee']) - assert_equal(response.payment_request.currency, - body.get('payment_request')['currency']) - assert_equal(response.payment_request.description, - body.get('payment_request')['description']) - assert_equal(response.payment_request.links, - body.get('payment_request')['links']) - assert_equal(response.payment_request.metadata, - body.get('payment_request')['metadata']) - assert_equal(response.payment_request.scheme, - body.get('payment_request')['scheme']) - assert_equal(response.resources.customer, - body.get('resources')['customer']) - assert_equal(response.resources.customer_bank_account, - body.get('resources')['customer_bank_account']) - assert_equal(response.resources.customer_billing_detail, - body.get('resources')['customer_billing_detail']) + assert isinstance(response, resources.BillingRequest) + assert responses.calls[-1].request.headers.get('Idempotency-Key') is not None + assert response.actions == body.get('actions') + assert response.created_at == body.get('created_at') + assert response.fallback_enabled == body.get('fallback_enabled') + assert response.id == body.get('id') + assert response.metadata == body.get('metadata') + assert response.purpose_code == body.get('purpose_code') + assert response.status == body.get('status') + assert response.links.bank_authorisation == body.get('links')['bank_authorisation'] + assert response.links.creditor == body.get('links')['creditor'] + assert response.links.customer == body.get('links')['customer'] + assert response.links.customer_bank_account == body.get('links')['customer_bank_account'] + assert response.links.customer_billing_detail == body.get('links')['customer_billing_detail'] + assert response.links.mandate_request == body.get('links')['mandate_request'] + assert response.links.mandate_request_mandate == body.get('links')['mandate_request_mandate'] + assert response.links.organisation == body.get('links')['organisation'] + assert response.links.payment_request == body.get('links')['payment_request'] + assert response.links.payment_request_payment == body.get('links')['payment_request_payment'] + assert response.mandate_request.authorisation_source == body.get('mandate_request')['authorisation_source'] + assert response.mandate_request.constraints == body.get('mandate_request')['constraints'] + assert response.mandate_request.currency == body.get('mandate_request')['currency'] + assert response.mandate_request.description == body.get('mandate_request')['description'] + assert response.mandate_request.links == body.get('mandate_request')['links'] + assert response.mandate_request.metadata == body.get('mandate_request')['metadata'] + assert response.mandate_request.scheme == body.get('mandate_request')['scheme'] + assert response.mandate_request.verify == body.get('mandate_request')['verify'] + assert response.payment_request.amount == body.get('payment_request')['amount'] + assert response.payment_request.app_fee == body.get('payment_request')['app_fee'] + assert response.payment_request.currency == body.get('payment_request')['currency'] + assert response.payment_request.description == body.get('payment_request')['description'] + assert response.payment_request.links == body.get('payment_request')['links'] + assert response.payment_request.metadata == body.get('payment_request')['metadata'] + assert response.payment_request.scheme == body.get('payment_request')['scheme'] + assert response.resources.customer == body.get('resources')['customer'] + assert response.resources.customer_bank_account == body.get('resources')['customer_bank_account'] + assert response.resources.customer_billing_detail == body.get('resources')['customer_billing_detail'] def test_timeout_billing_requests_fallback_doesnt_retry(): fixture = helpers.load_fixture('billing_requests')['fallback'] with helpers.stub_timeout(fixture) as rsps: - with assert_raises(requests.ConnectTimeout): + with pytest.raises(requests.ConnectTimeout): response = helpers.client.billing_requests.fallback(*fixture['url_params']) - assert_equal(1, len(rsps.calls)) + assert len(rsps.calls) == 1 def test_502_billing_requests_fallback_doesnt_retry(): fixture = helpers.load_fixture('billing_requests')['fallback'] with helpers.stub_502(fixture) as rsps: - with assert_raises(MalformedResponseError): + with pytest.raises(MalformedResponseError): response = helpers.client.billing_requests.fallback(*fixture['url_params']) - assert_equal(1, len(rsps.calls)) + assert len(rsps.calls) == 1 @responses.activate @@ -938,85 +665,57 @@ def test_billing_requests_choose_currency(): response = helpers.client.billing_requests.choose_currency(*fixture['url_params']) body = fixture['body']['billing_requests'] - assert_is_instance(response, resources.BillingRequest) - assert_is_not_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal(response.actions, body.get('actions')) - assert_equal(response.created_at, body.get('created_at')) - assert_equal(response.fallback_enabled, body.get('fallback_enabled')) - assert_equal(response.id, body.get('id')) - assert_equal(response.metadata, body.get('metadata')) - assert_equal(response.purpose_code, body.get('purpose_code')) - assert_equal(response.status, body.get('status')) - assert_equal(response.links.bank_authorisation, - body.get('links')['bank_authorisation']) - assert_equal(response.links.creditor, - body.get('links')['creditor']) - assert_equal(response.links.customer, - body.get('links')['customer']) - assert_equal(response.links.customer_bank_account, - body.get('links')['customer_bank_account']) - assert_equal(response.links.customer_billing_detail, - body.get('links')['customer_billing_detail']) - assert_equal(response.links.mandate_request, - body.get('links')['mandate_request']) - assert_equal(response.links.mandate_request_mandate, - body.get('links')['mandate_request_mandate']) - assert_equal(response.links.organisation, - body.get('links')['organisation']) - assert_equal(response.links.payment_request, - body.get('links')['payment_request']) - assert_equal(response.links.payment_request_payment, - body.get('links')['payment_request_payment']) - assert_equal(response.mandate_request.authorisation_source, - body.get('mandate_request')['authorisation_source']) - assert_equal(response.mandate_request.constraints, - body.get('mandate_request')['constraints']) - assert_equal(response.mandate_request.currency, - body.get('mandate_request')['currency']) - assert_equal(response.mandate_request.description, - body.get('mandate_request')['description']) - assert_equal(response.mandate_request.links, - body.get('mandate_request')['links']) - assert_equal(response.mandate_request.metadata, - body.get('mandate_request')['metadata']) - assert_equal(response.mandate_request.scheme, - body.get('mandate_request')['scheme']) - assert_equal(response.mandate_request.verify, - body.get('mandate_request')['verify']) - assert_equal(response.payment_request.amount, - body.get('payment_request')['amount']) - assert_equal(response.payment_request.app_fee, - body.get('payment_request')['app_fee']) - assert_equal(response.payment_request.currency, - body.get('payment_request')['currency']) - assert_equal(response.payment_request.description, - body.get('payment_request')['description']) - assert_equal(response.payment_request.links, - body.get('payment_request')['links']) - assert_equal(response.payment_request.metadata, - body.get('payment_request')['metadata']) - assert_equal(response.payment_request.scheme, - body.get('payment_request')['scheme']) - assert_equal(response.resources.customer, - body.get('resources')['customer']) - assert_equal(response.resources.customer_bank_account, - body.get('resources')['customer_bank_account']) - assert_equal(response.resources.customer_billing_detail, - body.get('resources')['customer_billing_detail']) + assert isinstance(response, resources.BillingRequest) + assert responses.calls[-1].request.headers.get('Idempotency-Key') is not None + assert response.actions == body.get('actions') + assert response.created_at == body.get('created_at') + assert response.fallback_enabled == body.get('fallback_enabled') + assert response.id == body.get('id') + assert response.metadata == body.get('metadata') + assert response.purpose_code == body.get('purpose_code') + assert response.status == body.get('status') + assert response.links.bank_authorisation == body.get('links')['bank_authorisation'] + assert response.links.creditor == body.get('links')['creditor'] + assert response.links.customer == body.get('links')['customer'] + assert response.links.customer_bank_account == body.get('links')['customer_bank_account'] + assert response.links.customer_billing_detail == body.get('links')['customer_billing_detail'] + assert response.links.mandate_request == body.get('links')['mandate_request'] + assert response.links.mandate_request_mandate == body.get('links')['mandate_request_mandate'] + assert response.links.organisation == body.get('links')['organisation'] + assert response.links.payment_request == body.get('links')['payment_request'] + assert response.links.payment_request_payment == body.get('links')['payment_request_payment'] + assert response.mandate_request.authorisation_source == body.get('mandate_request')['authorisation_source'] + assert response.mandate_request.constraints == body.get('mandate_request')['constraints'] + assert response.mandate_request.currency == body.get('mandate_request')['currency'] + assert response.mandate_request.description == body.get('mandate_request')['description'] + assert response.mandate_request.links == body.get('mandate_request')['links'] + assert response.mandate_request.metadata == body.get('mandate_request')['metadata'] + assert response.mandate_request.scheme == body.get('mandate_request')['scheme'] + assert response.mandate_request.verify == body.get('mandate_request')['verify'] + assert response.payment_request.amount == body.get('payment_request')['amount'] + assert response.payment_request.app_fee == body.get('payment_request')['app_fee'] + assert response.payment_request.currency == body.get('payment_request')['currency'] + assert response.payment_request.description == body.get('payment_request')['description'] + assert response.payment_request.links == body.get('payment_request')['links'] + assert response.payment_request.metadata == body.get('payment_request')['metadata'] + assert response.payment_request.scheme == body.get('payment_request')['scheme'] + assert response.resources.customer == body.get('resources')['customer'] + assert response.resources.customer_bank_account == body.get('resources')['customer_bank_account'] + assert response.resources.customer_billing_detail == body.get('resources')['customer_billing_detail'] def test_timeout_billing_requests_choose_currency_doesnt_retry(): fixture = helpers.load_fixture('billing_requests')['choose_currency'] with helpers.stub_timeout(fixture) as rsps: - with assert_raises(requests.ConnectTimeout): + with pytest.raises(requests.ConnectTimeout): response = helpers.client.billing_requests.choose_currency(*fixture['url_params']) - assert_equal(1, len(rsps.calls)) + assert len(rsps.calls) == 1 def test_502_billing_requests_choose_currency_doesnt_retry(): fixture = helpers.load_fixture('billing_requests')['choose_currency'] with helpers.stub_502(fixture) as rsps: - with assert_raises(MalformedResponseError): + with pytest.raises(MalformedResponseError): response = helpers.client.billing_requests.choose_currency(*fixture['url_params']) - assert_equal(1, len(rsps.calls)) + assert len(rsps.calls) == 1 @responses.activate @@ -1026,83 +725,55 @@ def test_billing_requests_select_institution(): response = helpers.client.billing_requests.select_institution(*fixture['url_params']) body = fixture['body']['billing_requests'] - assert_is_instance(response, resources.BillingRequest) - assert_is_not_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal(response.actions, body.get('actions')) - assert_equal(response.created_at, body.get('created_at')) - assert_equal(response.fallback_enabled, body.get('fallback_enabled')) - assert_equal(response.id, body.get('id')) - assert_equal(response.metadata, body.get('metadata')) - assert_equal(response.purpose_code, body.get('purpose_code')) - assert_equal(response.status, body.get('status')) - assert_equal(response.links.bank_authorisation, - body.get('links')['bank_authorisation']) - assert_equal(response.links.creditor, - body.get('links')['creditor']) - assert_equal(response.links.customer, - body.get('links')['customer']) - assert_equal(response.links.customer_bank_account, - body.get('links')['customer_bank_account']) - assert_equal(response.links.customer_billing_detail, - body.get('links')['customer_billing_detail']) - assert_equal(response.links.mandate_request, - body.get('links')['mandate_request']) - assert_equal(response.links.mandate_request_mandate, - body.get('links')['mandate_request_mandate']) - assert_equal(response.links.organisation, - body.get('links')['organisation']) - assert_equal(response.links.payment_request, - body.get('links')['payment_request']) - assert_equal(response.links.payment_request_payment, - body.get('links')['payment_request_payment']) - assert_equal(response.mandate_request.authorisation_source, - body.get('mandate_request')['authorisation_source']) - assert_equal(response.mandate_request.constraints, - body.get('mandate_request')['constraints']) - assert_equal(response.mandate_request.currency, - body.get('mandate_request')['currency']) - assert_equal(response.mandate_request.description, - body.get('mandate_request')['description']) - assert_equal(response.mandate_request.links, - body.get('mandate_request')['links']) - assert_equal(response.mandate_request.metadata, - body.get('mandate_request')['metadata']) - assert_equal(response.mandate_request.scheme, - body.get('mandate_request')['scheme']) - assert_equal(response.mandate_request.verify, - body.get('mandate_request')['verify']) - assert_equal(response.payment_request.amount, - body.get('payment_request')['amount']) - assert_equal(response.payment_request.app_fee, - body.get('payment_request')['app_fee']) - assert_equal(response.payment_request.currency, - body.get('payment_request')['currency']) - assert_equal(response.payment_request.description, - body.get('payment_request')['description']) - assert_equal(response.payment_request.links, - body.get('payment_request')['links']) - assert_equal(response.payment_request.metadata, - body.get('payment_request')['metadata']) - assert_equal(response.payment_request.scheme, - body.get('payment_request')['scheme']) - assert_equal(response.resources.customer, - body.get('resources')['customer']) - assert_equal(response.resources.customer_bank_account, - body.get('resources')['customer_bank_account']) - assert_equal(response.resources.customer_billing_detail, - body.get('resources')['customer_billing_detail']) + assert isinstance(response, resources.BillingRequest) + assert responses.calls[-1].request.headers.get('Idempotency-Key') is not None + assert response.actions == body.get('actions') + assert response.created_at == body.get('created_at') + assert response.fallback_enabled == body.get('fallback_enabled') + assert response.id == body.get('id') + assert response.metadata == body.get('metadata') + assert response.purpose_code == body.get('purpose_code') + assert response.status == body.get('status') + assert response.links.bank_authorisation == body.get('links')['bank_authorisation'] + assert response.links.creditor == body.get('links')['creditor'] + assert response.links.customer == body.get('links')['customer'] + assert response.links.customer_bank_account == body.get('links')['customer_bank_account'] + assert response.links.customer_billing_detail == body.get('links')['customer_billing_detail'] + assert response.links.mandate_request == body.get('links')['mandate_request'] + assert response.links.mandate_request_mandate == body.get('links')['mandate_request_mandate'] + assert response.links.organisation == body.get('links')['organisation'] + assert response.links.payment_request == body.get('links')['payment_request'] + assert response.links.payment_request_payment == body.get('links')['payment_request_payment'] + assert response.mandate_request.authorisation_source == body.get('mandate_request')['authorisation_source'] + assert response.mandate_request.constraints == body.get('mandate_request')['constraints'] + assert response.mandate_request.currency == body.get('mandate_request')['currency'] + assert response.mandate_request.description == body.get('mandate_request')['description'] + assert response.mandate_request.links == body.get('mandate_request')['links'] + assert response.mandate_request.metadata == body.get('mandate_request')['metadata'] + assert response.mandate_request.scheme == body.get('mandate_request')['scheme'] + assert response.mandate_request.verify == body.get('mandate_request')['verify'] + assert response.payment_request.amount == body.get('payment_request')['amount'] + assert response.payment_request.app_fee == body.get('payment_request')['app_fee'] + assert response.payment_request.currency == body.get('payment_request')['currency'] + assert response.payment_request.description == body.get('payment_request')['description'] + assert response.payment_request.links == body.get('payment_request')['links'] + assert response.payment_request.metadata == body.get('payment_request')['metadata'] + assert response.payment_request.scheme == body.get('payment_request')['scheme'] + assert response.resources.customer == body.get('resources')['customer'] + assert response.resources.customer_bank_account == body.get('resources')['customer_bank_account'] + assert response.resources.customer_billing_detail == body.get('resources')['customer_billing_detail'] def test_timeout_billing_requests_select_institution_doesnt_retry(): fixture = helpers.load_fixture('billing_requests')['select_institution'] with helpers.stub_timeout(fixture) as rsps: - with assert_raises(requests.ConnectTimeout): + with pytest.raises(requests.ConnectTimeout): response = helpers.client.billing_requests.select_institution(*fixture['url_params']) - assert_equal(1, len(rsps.calls)) + assert len(rsps.calls) == 1 def test_502_billing_requests_select_institution_doesnt_retry(): fixture = helpers.load_fixture('billing_requests')['select_institution'] with helpers.stub_502(fixture) as rsps: - with assert_raises(MalformedResponseError): + with pytest.raises(MalformedResponseError): response = helpers.client.billing_requests.select_institution(*fixture['url_params']) - assert_equal(1, len(rsps.calls)) + assert len(rsps.calls) == 1 diff --git a/tests/integration/blocks_integration_test.py b/tests/integration/blocks_integration_test.py index 0d046d15..cf92d7a7 100644 --- a/tests/integration/blocks_integration_test.py +++ b/tests/integration/blocks_integration_test.py @@ -5,16 +5,9 @@ import json +import pytest import requests import responses -from nose.tools import ( - assert_equal, - assert_is_instance, - assert_is_none, - assert_is_not_none, - assert_not_equal, - assert_raises -) from gocardless_pro.errors import MalformedResponseError from gocardless_pro import resources @@ -30,16 +23,16 @@ def test_blocks_create(): response = helpers.client.blocks.create(*fixture['url_params']) body = fixture['body']['blocks'] - assert_is_instance(response, resources.Block) - assert_is_not_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal(response.active, body.get('active')) - assert_equal(response.block_type, body.get('block_type')) - assert_equal(response.created_at, body.get('created_at')) - assert_equal(response.id, body.get('id')) - assert_equal(response.reason_description, body.get('reason_description')) - assert_equal(response.reason_type, body.get('reason_type')) - assert_equal(response.resource_reference, body.get('resource_reference')) - assert_equal(response.updated_at, body.get('updated_at')) + assert isinstance(response, resources.Block) + assert responses.calls[-1].request.headers.get('Idempotency-Key') is not None + assert response.active == body.get('active') + assert response.block_type == body.get('block_type') + assert response.created_at == body.get('created_at') + assert response.id == body.get('id') + assert response.reason_description == body.get('reason_description') + assert response.reason_type == body.get('reason_type') + assert response.resource_reference == body.get('resource_reference') + assert response.updated_at == body.get('updated_at') @responses.activate def test_blocks_create_new_idempotency_key_for_each_call(): @@ -47,40 +40,37 @@ def test_blocks_create_new_idempotency_key_for_each_call(): helpers.stub_response(fixture) helpers.client.blocks.create(*fixture['url_params']) helpers.client.blocks.create(*fixture['url_params']) - assert_not_equal(responses.calls[0].request.headers.get('Idempotency-Key'), - responses.calls[1].request.headers.get('Idempotency-Key')) + assert responses.calls[0].request.headers.get('Idempotency-Key') != responses.calls[1].request.headers.get('Idempotency-Key') def test_timeout_blocks_create_idempotency_conflict(): create_fixture = helpers.load_fixture('blocks')['create'] get_fixture = helpers.load_fixture('blocks')['get'] with helpers.stub_timeout_then_idempotency_conflict(create_fixture, get_fixture) as rsps: response = helpers.client.blocks.create(*create_fixture['url_params']) - assert_equal(2, len(rsps.calls)) + assert len(rsps.calls) == 2 - assert_is_instance(response, resources.Block) + assert isinstance(response, resources.Block) @responses.activate def test_timeout_blocks_create_retries(): fixture = helpers.load_fixture('blocks')['create'] with helpers.stub_timeout_then_response(fixture) as rsps: response = helpers.client.blocks.create(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['blocks'] - assert_is_instance(response, resources.Block) + assert isinstance(response, resources.Block) def test_502_blocks_create_retries(): fixture = helpers.load_fixture('blocks')['create'] with helpers.stub_502_then_response(fixture) as rsps: response = helpers.client.blocks.create(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['blocks'] - assert_is_instance(response, resources.Block) + assert isinstance(response, resources.Block) @responses.activate @@ -90,39 +80,37 @@ def test_blocks_get(): response = helpers.client.blocks.get(*fixture['url_params']) body = fixture['body']['blocks'] - assert_is_instance(response, resources.Block) - assert_is_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal(response.active, body.get('active')) - assert_equal(response.block_type, body.get('block_type')) - assert_equal(response.created_at, body.get('created_at')) - assert_equal(response.id, body.get('id')) - assert_equal(response.reason_description, body.get('reason_description')) - assert_equal(response.reason_type, body.get('reason_type')) - assert_equal(response.resource_reference, body.get('resource_reference')) - assert_equal(response.updated_at, body.get('updated_at')) + assert isinstance(response, resources.Block) + assert responses.calls[-1].request.headers.get('Idempotency-Key') is None + assert response.active == body.get('active') + assert response.block_type == body.get('block_type') + assert response.created_at == body.get('created_at') + assert response.id == body.get('id') + assert response.reason_description == body.get('reason_description') + assert response.reason_type == body.get('reason_type') + assert response.resource_reference == body.get('resource_reference') + assert response.updated_at == body.get('updated_at') @responses.activate def test_timeout_blocks_get_retries(): fixture = helpers.load_fixture('blocks')['get'] with helpers.stub_timeout_then_response(fixture) as rsps: response = helpers.client.blocks.get(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['blocks'] - assert_is_instance(response, resources.Block) + assert isinstance(response, resources.Block) def test_502_blocks_get_retries(): fixture = helpers.load_fixture('blocks')['get'] with helpers.stub_502_then_response(fixture) as rsps: response = helpers.client.blocks.get(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['blocks'] - assert_is_instance(response, resources.Block) + assert isinstance(response, resources.Block) @responses.activate @@ -132,59 +120,49 @@ def test_blocks_list(): response = helpers.client.blocks.list(*fixture['url_params']) body = fixture['body']['blocks'] - assert_is_instance(response, list_response.ListResponse) - assert_is_instance(response.records[0], resources.Block) - - assert_equal(response.before, fixture['body']['meta']['cursors']['before']) - assert_equal(response.after, fixture['body']['meta']['cursors']['after']) - assert_is_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal([r.active for r in response.records], - [b.get('active') for b in body]) - assert_equal([r.block_type for r in response.records], - [b.get('block_type') for b in body]) - assert_equal([r.created_at for r in response.records], - [b.get('created_at') for b in body]) - assert_equal([r.id for r in response.records], - [b.get('id') for b in body]) - assert_equal([r.reason_description for r in response.records], - [b.get('reason_description') for b in body]) - assert_equal([r.reason_type for r in response.records], - [b.get('reason_type') for b in body]) - assert_equal([r.resource_reference for r in response.records], - [b.get('resource_reference') for b in body]) - assert_equal([r.updated_at for r in response.records], - [b.get('updated_at') for b in body]) + assert isinstance(response, list_response.ListResponse) + assert isinstance(response.records[0], resources.Block) + + assert response.before == fixture['body']['meta']['cursors']['before'] + assert response.after == fixture['body']['meta']['cursors']['after'] + assert responses.calls[-1].request.headers.get('Idempotency-Key') is None + assert [r.active for r in response.records] == [b.get('active') for b in body] + assert [r.block_type for r in response.records] == [b.get('block_type') for b in body] + assert [r.created_at for r in response.records] == [b.get('created_at') for b in body] + assert [r.id for r in response.records] == [b.get('id') for b in body] + assert [r.reason_description for r in response.records] == [b.get('reason_description') for b in body] + assert [r.reason_type for r in response.records] == [b.get('reason_type') for b in body] + assert [r.resource_reference for r in response.records] == [b.get('resource_reference') for b in body] + assert [r.updated_at for r in response.records] == [b.get('updated_at') for b in body] @responses.activate def test_timeout_blocks_list_retries(): fixture = helpers.load_fixture('blocks')['list'] with helpers.stub_timeout_then_response(fixture) as rsps: response = helpers.client.blocks.list(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['blocks'] - assert_is_instance(response, list_response.ListResponse) - assert_is_instance(response.records[0], resources.Block) + assert isinstance(response, list_response.ListResponse) + assert isinstance(response.records[0], resources.Block) - assert_equal(response.before, fixture['body']['meta']['cursors']['before']) - assert_equal(response.after, fixture['body']['meta']['cursors']['after']) + assert response.before == fixture['body']['meta']['cursors']['before'] + assert response.after == fixture['body']['meta']['cursors']['after'] def test_502_blocks_list_retries(): fixture = helpers.load_fixture('blocks')['list'] with helpers.stub_502_then_response(fixture) as rsps: response = helpers.client.blocks.list(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['blocks'] - assert_is_instance(response, list_response.ListResponse) - assert_is_instance(response.records[0], resources.Block) + assert isinstance(response, list_response.ListResponse) + assert isinstance(response.records[0], resources.Block) - assert_equal(response.before, fixture['body']['meta']['cursors']['before']) - assert_equal(response.after, fixture['body']['meta']['cursors']['after']) + assert response.before == fixture['body']['meta']['cursors']['before'] + assert response.after == fixture['body']['meta']['cursors']['after'] @responses.activate def test_blocks_all(): @@ -201,9 +179,9 @@ def callback(request): responses.add_callback(fixture['method'], url, callback) all_records = list(helpers.client.blocks.all()) - assert_equal(len(all_records), len(fixture['body']['blocks']) * 2) + assert len(all_records) == len(fixture['body']['blocks']) * 2 for record in all_records: - assert_is_instance(record, resources.Block) + assert isinstance(record, resources.Block) @@ -214,30 +192,30 @@ def test_blocks_disable(): response = helpers.client.blocks.disable(*fixture['url_params']) body = fixture['body']['blocks'] - assert_is_instance(response, resources.Block) - assert_is_not_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal(response.active, body.get('active')) - assert_equal(response.block_type, body.get('block_type')) - assert_equal(response.created_at, body.get('created_at')) - assert_equal(response.id, body.get('id')) - assert_equal(response.reason_description, body.get('reason_description')) - assert_equal(response.reason_type, body.get('reason_type')) - assert_equal(response.resource_reference, body.get('resource_reference')) - assert_equal(response.updated_at, body.get('updated_at')) + assert isinstance(response, resources.Block) + assert responses.calls[-1].request.headers.get('Idempotency-Key') is not None + assert response.active == body.get('active') + assert response.block_type == body.get('block_type') + assert response.created_at == body.get('created_at') + assert response.id == body.get('id') + assert response.reason_description == body.get('reason_description') + assert response.reason_type == body.get('reason_type') + assert response.resource_reference == body.get('resource_reference') + assert response.updated_at == body.get('updated_at') def test_timeout_blocks_disable_doesnt_retry(): fixture = helpers.load_fixture('blocks')['disable'] with helpers.stub_timeout(fixture) as rsps: - with assert_raises(requests.ConnectTimeout): + with pytest.raises(requests.ConnectTimeout): response = helpers.client.blocks.disable(*fixture['url_params']) - assert_equal(1, len(rsps.calls)) + assert len(rsps.calls) == 1 def test_502_blocks_disable_doesnt_retry(): fixture = helpers.load_fixture('blocks')['disable'] with helpers.stub_502(fixture) as rsps: - with assert_raises(MalformedResponseError): + with pytest.raises(MalformedResponseError): response = helpers.client.blocks.disable(*fixture['url_params']) - assert_equal(1, len(rsps.calls)) + assert len(rsps.calls) == 1 @responses.activate @@ -247,30 +225,30 @@ def test_blocks_enable(): response = helpers.client.blocks.enable(*fixture['url_params']) body = fixture['body']['blocks'] - assert_is_instance(response, resources.Block) - assert_is_not_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal(response.active, body.get('active')) - assert_equal(response.block_type, body.get('block_type')) - assert_equal(response.created_at, body.get('created_at')) - assert_equal(response.id, body.get('id')) - assert_equal(response.reason_description, body.get('reason_description')) - assert_equal(response.reason_type, body.get('reason_type')) - assert_equal(response.resource_reference, body.get('resource_reference')) - assert_equal(response.updated_at, body.get('updated_at')) + assert isinstance(response, resources.Block) + assert responses.calls[-1].request.headers.get('Idempotency-Key') is not None + assert response.active == body.get('active') + assert response.block_type == body.get('block_type') + assert response.created_at == body.get('created_at') + assert response.id == body.get('id') + assert response.reason_description == body.get('reason_description') + assert response.reason_type == body.get('reason_type') + assert response.resource_reference == body.get('resource_reference') + assert response.updated_at == body.get('updated_at') def test_timeout_blocks_enable_doesnt_retry(): fixture = helpers.load_fixture('blocks')['enable'] with helpers.stub_timeout(fixture) as rsps: - with assert_raises(requests.ConnectTimeout): + with pytest.raises(requests.ConnectTimeout): response = helpers.client.blocks.enable(*fixture['url_params']) - assert_equal(1, len(rsps.calls)) + assert len(rsps.calls) == 1 def test_502_blocks_enable_doesnt_retry(): fixture = helpers.load_fixture('blocks')['enable'] with helpers.stub_502(fixture) as rsps: - with assert_raises(MalformedResponseError): + with pytest.raises(MalformedResponseError): response = helpers.client.blocks.enable(*fixture['url_params']) - assert_equal(1, len(rsps.calls)) + assert len(rsps.calls) == 1 @responses.activate @@ -280,40 +258,32 @@ def test_blocks_block_by_ref(): response = helpers.client.blocks.block_by_ref(*fixture['url_params']) body = fixture['body']['blocks'] - assert_is_instance(response, list_response.ListResponse) - assert_is_instance(response.records[0], resources.Block) - - assert_equal(response.before, fixture['body']['meta']['cursors']['before']) - assert_equal(response.after, fixture['body']['meta']['cursors']['after']) - assert_is_not_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal([r.active for r in response.records], - [b.get('active') for b in body]) - assert_equal([r.block_type for r in response.records], - [b.get('block_type') for b in body]) - assert_equal([r.created_at for r in response.records], - [b.get('created_at') for b in body]) - assert_equal([r.id for r in response.records], - [b.get('id') for b in body]) - assert_equal([r.reason_description for r in response.records], - [b.get('reason_description') for b in body]) - assert_equal([r.reason_type for r in response.records], - [b.get('reason_type') for b in body]) - assert_equal([r.resource_reference for r in response.records], - [b.get('resource_reference') for b in body]) - assert_equal([r.updated_at for r in response.records], - [b.get('updated_at') for b in body]) + assert isinstance(response, list_response.ListResponse) + assert isinstance(response.records[0], resources.Block) + + assert response.before == fixture['body']['meta']['cursors']['before'] + assert response.after == fixture['body']['meta']['cursors']['after'] + assert responses.calls[-1].request.headers.get('Idempotency-Key') is not None + assert [r.active for r in response.records] == [b.get('active') for b in body] + assert [r.block_type for r in response.records] == [b.get('block_type') for b in body] + assert [r.created_at for r in response.records] == [b.get('created_at') for b in body] + assert [r.id for r in response.records] == [b.get('id') for b in body] + assert [r.reason_description for r in response.records] == [b.get('reason_description') for b in body] + assert [r.reason_type for r in response.records] == [b.get('reason_type') for b in body] + assert [r.resource_reference for r in response.records] == [b.get('resource_reference') for b in body] + assert [r.updated_at for r in response.records] == [b.get('updated_at') for b in body] def test_timeout_blocks_block_by_ref_doesnt_retry(): fixture = helpers.load_fixture('blocks')['block_by_ref'] with helpers.stub_timeout(fixture) as rsps: - with assert_raises(requests.ConnectTimeout): + with pytest.raises(requests.ConnectTimeout): response = helpers.client.blocks.block_by_ref(*fixture['url_params']) - assert_equal(1, len(rsps.calls)) + assert len(rsps.calls) == 1 def test_502_blocks_block_by_ref_doesnt_retry(): fixture = helpers.load_fixture('blocks')['block_by_ref'] with helpers.stub_502(fixture) as rsps: - with assert_raises(MalformedResponseError): + with pytest.raises(MalformedResponseError): response = helpers.client.blocks.block_by_ref(*fixture['url_params']) - assert_equal(1, len(rsps.calls)) + assert len(rsps.calls) == 1 diff --git a/tests/integration/creditor_bank_accounts_integration_test.py b/tests/integration/creditor_bank_accounts_integration_test.py index 39022fc5..47f640d3 100644 --- a/tests/integration/creditor_bank_accounts_integration_test.py +++ b/tests/integration/creditor_bank_accounts_integration_test.py @@ -5,16 +5,9 @@ import json +import pytest import requests import responses -from nose.tools import ( - assert_equal, - assert_is_instance, - assert_is_none, - assert_is_not_none, - assert_not_equal, - assert_raises -) from gocardless_pro.errors import MalformedResponseError from gocardless_pro import resources @@ -30,20 +23,19 @@ def test_creditor_bank_accounts_create(): response = helpers.client.creditor_bank_accounts.create(*fixture['url_params']) body = fixture['body']['creditor_bank_accounts'] - assert_is_instance(response, resources.CreditorBankAccount) - assert_is_not_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal(response.account_holder_name, body.get('account_holder_name')) - assert_equal(response.account_number_ending, body.get('account_number_ending')) - assert_equal(response.account_type, body.get('account_type')) - assert_equal(response.bank_name, body.get('bank_name')) - assert_equal(response.country_code, body.get('country_code')) - assert_equal(response.created_at, body.get('created_at')) - assert_equal(response.currency, body.get('currency')) - assert_equal(response.enabled, body.get('enabled')) - assert_equal(response.id, body.get('id')) - assert_equal(response.metadata, body.get('metadata')) - assert_equal(response.links.creditor, - body.get('links')['creditor']) + assert isinstance(response, resources.CreditorBankAccount) + assert responses.calls[-1].request.headers.get('Idempotency-Key') is not None + assert response.account_holder_name == body.get('account_holder_name') + assert response.account_number_ending == body.get('account_number_ending') + assert response.account_type == body.get('account_type') + assert response.bank_name == body.get('bank_name') + assert response.country_code == body.get('country_code') + assert response.created_at == body.get('created_at') + assert response.currency == body.get('currency') + assert response.enabled == body.get('enabled') + assert response.id == body.get('id') + assert response.metadata == body.get('metadata') + assert response.links.creditor == body.get('links')['creditor'] @responses.activate def test_creditor_bank_accounts_create_new_idempotency_key_for_each_call(): @@ -51,40 +43,37 @@ def test_creditor_bank_accounts_create_new_idempotency_key_for_each_call(): helpers.stub_response(fixture) helpers.client.creditor_bank_accounts.create(*fixture['url_params']) helpers.client.creditor_bank_accounts.create(*fixture['url_params']) - assert_not_equal(responses.calls[0].request.headers.get('Idempotency-Key'), - responses.calls[1].request.headers.get('Idempotency-Key')) + assert responses.calls[0].request.headers.get('Idempotency-Key') != responses.calls[1].request.headers.get('Idempotency-Key') def test_timeout_creditor_bank_accounts_create_idempotency_conflict(): create_fixture = helpers.load_fixture('creditor_bank_accounts')['create'] get_fixture = helpers.load_fixture('creditor_bank_accounts')['get'] with helpers.stub_timeout_then_idempotency_conflict(create_fixture, get_fixture) as rsps: response = helpers.client.creditor_bank_accounts.create(*create_fixture['url_params']) - assert_equal(2, len(rsps.calls)) + assert len(rsps.calls) == 2 - assert_is_instance(response, resources.CreditorBankAccount) + assert isinstance(response, resources.CreditorBankAccount) @responses.activate def test_timeout_creditor_bank_accounts_create_retries(): fixture = helpers.load_fixture('creditor_bank_accounts')['create'] with helpers.stub_timeout_then_response(fixture) as rsps: response = helpers.client.creditor_bank_accounts.create(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['creditor_bank_accounts'] - assert_is_instance(response, resources.CreditorBankAccount) + assert isinstance(response, resources.CreditorBankAccount) def test_502_creditor_bank_accounts_create_retries(): fixture = helpers.load_fixture('creditor_bank_accounts')['create'] with helpers.stub_502_then_response(fixture) as rsps: response = helpers.client.creditor_bank_accounts.create(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['creditor_bank_accounts'] - assert_is_instance(response, resources.CreditorBankAccount) + assert isinstance(response, resources.CreditorBankAccount) @responses.activate @@ -94,63 +83,51 @@ def test_creditor_bank_accounts_list(): response = helpers.client.creditor_bank_accounts.list(*fixture['url_params']) body = fixture['body']['creditor_bank_accounts'] - assert_is_instance(response, list_response.ListResponse) - assert_is_instance(response.records[0], resources.CreditorBankAccount) - - assert_equal(response.before, fixture['body']['meta']['cursors']['before']) - assert_equal(response.after, fixture['body']['meta']['cursors']['after']) - assert_is_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal([r.account_holder_name for r in response.records], - [b.get('account_holder_name') for b in body]) - assert_equal([r.account_number_ending for r in response.records], - [b.get('account_number_ending') for b in body]) - assert_equal([r.account_type for r in response.records], - [b.get('account_type') for b in body]) - assert_equal([r.bank_name for r in response.records], - [b.get('bank_name') for b in body]) - assert_equal([r.country_code for r in response.records], - [b.get('country_code') for b in body]) - assert_equal([r.created_at for r in response.records], - [b.get('created_at') for b in body]) - assert_equal([r.currency for r in response.records], - [b.get('currency') for b in body]) - assert_equal([r.enabled for r in response.records], - [b.get('enabled') for b in body]) - assert_equal([r.id for r in response.records], - [b.get('id') for b in body]) - assert_equal([r.metadata for r in response.records], - [b.get('metadata') for b in body]) + assert isinstance(response, list_response.ListResponse) + assert isinstance(response.records[0], resources.CreditorBankAccount) + + assert response.before == fixture['body']['meta']['cursors']['before'] + assert response.after == fixture['body']['meta']['cursors']['after'] + assert responses.calls[-1].request.headers.get('Idempotency-Key') is None + assert [r.account_holder_name for r in response.records] == [b.get('account_holder_name') for b in body] + assert [r.account_number_ending for r in response.records] == [b.get('account_number_ending') for b in body] + assert [r.account_type for r in response.records] == [b.get('account_type') for b in body] + assert [r.bank_name for r in response.records] == [b.get('bank_name') for b in body] + assert [r.country_code for r in response.records] == [b.get('country_code') for b in body] + assert [r.created_at for r in response.records] == [b.get('created_at') for b in body] + assert [r.currency for r in response.records] == [b.get('currency') for b in body] + assert [r.enabled for r in response.records] == [b.get('enabled') for b in body] + assert [r.id for r in response.records] == [b.get('id') for b in body] + assert [r.metadata for r in response.records] == [b.get('metadata') for b in body] @responses.activate def test_timeout_creditor_bank_accounts_list_retries(): fixture = helpers.load_fixture('creditor_bank_accounts')['list'] with helpers.stub_timeout_then_response(fixture) as rsps: response = helpers.client.creditor_bank_accounts.list(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['creditor_bank_accounts'] - assert_is_instance(response, list_response.ListResponse) - assert_is_instance(response.records[0], resources.CreditorBankAccount) + assert isinstance(response, list_response.ListResponse) + assert isinstance(response.records[0], resources.CreditorBankAccount) - assert_equal(response.before, fixture['body']['meta']['cursors']['before']) - assert_equal(response.after, fixture['body']['meta']['cursors']['after']) + assert response.before == fixture['body']['meta']['cursors']['before'] + assert response.after == fixture['body']['meta']['cursors']['after'] def test_502_creditor_bank_accounts_list_retries(): fixture = helpers.load_fixture('creditor_bank_accounts')['list'] with helpers.stub_502_then_response(fixture) as rsps: response = helpers.client.creditor_bank_accounts.list(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['creditor_bank_accounts'] - assert_is_instance(response, list_response.ListResponse) - assert_is_instance(response.records[0], resources.CreditorBankAccount) + assert isinstance(response, list_response.ListResponse) + assert isinstance(response.records[0], resources.CreditorBankAccount) - assert_equal(response.before, fixture['body']['meta']['cursors']['before']) - assert_equal(response.after, fixture['body']['meta']['cursors']['after']) + assert response.before == fixture['body']['meta']['cursors']['before'] + assert response.after == fixture['body']['meta']['cursors']['after'] @responses.activate def test_creditor_bank_accounts_all(): @@ -167,9 +144,9 @@ def callback(request): responses.add_callback(fixture['method'], url, callback) all_records = list(helpers.client.creditor_bank_accounts.all()) - assert_equal(len(all_records), len(fixture['body']['creditor_bank_accounts']) * 2) + assert len(all_records) == len(fixture['body']['creditor_bank_accounts']) * 2 for record in all_records: - assert_is_instance(record, resources.CreditorBankAccount) + assert isinstance(record, resources.CreditorBankAccount) @@ -180,43 +157,40 @@ def test_creditor_bank_accounts_get(): response = helpers.client.creditor_bank_accounts.get(*fixture['url_params']) body = fixture['body']['creditor_bank_accounts'] - assert_is_instance(response, resources.CreditorBankAccount) - assert_is_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal(response.account_holder_name, body.get('account_holder_name')) - assert_equal(response.account_number_ending, body.get('account_number_ending')) - assert_equal(response.account_type, body.get('account_type')) - assert_equal(response.bank_name, body.get('bank_name')) - assert_equal(response.country_code, body.get('country_code')) - assert_equal(response.created_at, body.get('created_at')) - assert_equal(response.currency, body.get('currency')) - assert_equal(response.enabled, body.get('enabled')) - assert_equal(response.id, body.get('id')) - assert_equal(response.metadata, body.get('metadata')) - assert_equal(response.links.creditor, - body.get('links')['creditor']) + assert isinstance(response, resources.CreditorBankAccount) + assert responses.calls[-1].request.headers.get('Idempotency-Key') is None + assert response.account_holder_name == body.get('account_holder_name') + assert response.account_number_ending == body.get('account_number_ending') + assert response.account_type == body.get('account_type') + assert response.bank_name == body.get('bank_name') + assert response.country_code == body.get('country_code') + assert response.created_at == body.get('created_at') + assert response.currency == body.get('currency') + assert response.enabled == body.get('enabled') + assert response.id == body.get('id') + assert response.metadata == body.get('metadata') + assert response.links.creditor == body.get('links')['creditor'] @responses.activate def test_timeout_creditor_bank_accounts_get_retries(): fixture = helpers.load_fixture('creditor_bank_accounts')['get'] with helpers.stub_timeout_then_response(fixture) as rsps: response = helpers.client.creditor_bank_accounts.get(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['creditor_bank_accounts'] - assert_is_instance(response, resources.CreditorBankAccount) + assert isinstance(response, resources.CreditorBankAccount) def test_502_creditor_bank_accounts_get_retries(): fixture = helpers.load_fixture('creditor_bank_accounts')['get'] with helpers.stub_502_then_response(fixture) as rsps: response = helpers.client.creditor_bank_accounts.get(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['creditor_bank_accounts'] - assert_is_instance(response, resources.CreditorBankAccount) + assert isinstance(response, resources.CreditorBankAccount) @responses.activate @@ -226,32 +200,31 @@ def test_creditor_bank_accounts_disable(): response = helpers.client.creditor_bank_accounts.disable(*fixture['url_params']) body = fixture['body']['creditor_bank_accounts'] - assert_is_instance(response, resources.CreditorBankAccount) - assert_is_not_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal(response.account_holder_name, body.get('account_holder_name')) - assert_equal(response.account_number_ending, body.get('account_number_ending')) - assert_equal(response.account_type, body.get('account_type')) - assert_equal(response.bank_name, body.get('bank_name')) - assert_equal(response.country_code, body.get('country_code')) - assert_equal(response.created_at, body.get('created_at')) - assert_equal(response.currency, body.get('currency')) - assert_equal(response.enabled, body.get('enabled')) - assert_equal(response.id, body.get('id')) - assert_equal(response.metadata, body.get('metadata')) - assert_equal(response.links.creditor, - body.get('links')['creditor']) + assert isinstance(response, resources.CreditorBankAccount) + assert responses.calls[-1].request.headers.get('Idempotency-Key') is not None + assert response.account_holder_name == body.get('account_holder_name') + assert response.account_number_ending == body.get('account_number_ending') + assert response.account_type == body.get('account_type') + assert response.bank_name == body.get('bank_name') + assert response.country_code == body.get('country_code') + assert response.created_at == body.get('created_at') + assert response.currency == body.get('currency') + assert response.enabled == body.get('enabled') + assert response.id == body.get('id') + assert response.metadata == body.get('metadata') + assert response.links.creditor == body.get('links')['creditor'] def test_timeout_creditor_bank_accounts_disable_doesnt_retry(): fixture = helpers.load_fixture('creditor_bank_accounts')['disable'] with helpers.stub_timeout(fixture) as rsps: - with assert_raises(requests.ConnectTimeout): + with pytest.raises(requests.ConnectTimeout): response = helpers.client.creditor_bank_accounts.disable(*fixture['url_params']) - assert_equal(1, len(rsps.calls)) + assert len(rsps.calls) == 1 def test_502_creditor_bank_accounts_disable_doesnt_retry(): fixture = helpers.load_fixture('creditor_bank_accounts')['disable'] with helpers.stub_502(fixture) as rsps: - with assert_raises(MalformedResponseError): + with pytest.raises(MalformedResponseError): response = helpers.client.creditor_bank_accounts.disable(*fixture['url_params']) - assert_equal(1, len(rsps.calls)) + assert len(rsps.calls) == 1 diff --git a/tests/integration/creditors_integration_test.py b/tests/integration/creditors_integration_test.py index d825fd42..8db879a3 100644 --- a/tests/integration/creditors_integration_test.py +++ b/tests/integration/creditors_integration_test.py @@ -5,16 +5,9 @@ import json +import pytest import requests import responses -from nose.tools import ( - assert_equal, - assert_is_instance, - assert_is_none, - assert_is_not_none, - assert_not_equal, - assert_raises -) from gocardless_pro.errors import MalformedResponseError from gocardless_pro import resources @@ -30,44 +23,36 @@ def test_creditors_create(): response = helpers.client.creditors.create(*fixture['url_params']) body = fixture['body']['creditors'] - assert_is_instance(response, resources.Creditor) - assert_is_not_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal(response.address_line1, body.get('address_line1')) - assert_equal(response.address_line2, body.get('address_line2')) - assert_equal(response.address_line3, body.get('address_line3')) - assert_equal(response.bank_reference_prefix, body.get('bank_reference_prefix')) - assert_equal(response.can_create_refunds, body.get('can_create_refunds')) - assert_equal(response.city, body.get('city')) - assert_equal(response.country_code, body.get('country_code')) - assert_equal(response.created_at, body.get('created_at')) - assert_equal(response.creditor_type, body.get('creditor_type')) - assert_equal(response.custom_payment_pages_enabled, body.get('custom_payment_pages_enabled')) - assert_equal(response.fx_payout_currency, body.get('fx_payout_currency')) - assert_equal(response.id, body.get('id')) - assert_equal(response.logo_url, body.get('logo_url')) - assert_equal(response.mandate_imports_enabled, body.get('mandate_imports_enabled')) - assert_equal(response.merchant_responsible_for_notifications, body.get('merchant_responsible_for_notifications')) - assert_equal(response.name, body.get('name')) - assert_equal(response.postal_code, body.get('postal_code')) - assert_equal(response.region, body.get('region')) - assert_equal(response.scheme_identifiers, body.get('scheme_identifiers')) - assert_equal(response.verification_status, body.get('verification_status')) - assert_equal(response.links.default_aud_payout_account, - body.get('links')['default_aud_payout_account']) - assert_equal(response.links.default_cad_payout_account, - body.get('links')['default_cad_payout_account']) - assert_equal(response.links.default_dkk_payout_account, - body.get('links')['default_dkk_payout_account']) - assert_equal(response.links.default_eur_payout_account, - body.get('links')['default_eur_payout_account']) - assert_equal(response.links.default_gbp_payout_account, - body.get('links')['default_gbp_payout_account']) - assert_equal(response.links.default_nzd_payout_account, - body.get('links')['default_nzd_payout_account']) - assert_equal(response.links.default_sek_payout_account, - body.get('links')['default_sek_payout_account']) - assert_equal(response.links.default_usd_payout_account, - body.get('links')['default_usd_payout_account']) + assert isinstance(response, resources.Creditor) + assert responses.calls[-1].request.headers.get('Idempotency-Key') is not None + assert response.address_line1 == body.get('address_line1') + assert response.address_line2 == body.get('address_line2') + assert response.address_line3 == body.get('address_line3') + assert response.bank_reference_prefix == body.get('bank_reference_prefix') + assert response.can_create_refunds == body.get('can_create_refunds') + assert response.city == body.get('city') + assert response.country_code == body.get('country_code') + assert response.created_at == body.get('created_at') + assert response.creditor_type == body.get('creditor_type') + assert response.custom_payment_pages_enabled == body.get('custom_payment_pages_enabled') + assert response.fx_payout_currency == body.get('fx_payout_currency') + assert response.id == body.get('id') + assert response.logo_url == body.get('logo_url') + assert response.mandate_imports_enabled == body.get('mandate_imports_enabled') + assert response.merchant_responsible_for_notifications == body.get('merchant_responsible_for_notifications') + assert response.name == body.get('name') + assert response.postal_code == body.get('postal_code') + assert response.region == body.get('region') + assert response.scheme_identifiers == body.get('scheme_identifiers') + assert response.verification_status == body.get('verification_status') + assert response.links.default_aud_payout_account == body.get('links')['default_aud_payout_account'] + assert response.links.default_cad_payout_account == body.get('links')['default_cad_payout_account'] + assert response.links.default_dkk_payout_account == body.get('links')['default_dkk_payout_account'] + assert response.links.default_eur_payout_account == body.get('links')['default_eur_payout_account'] + assert response.links.default_gbp_payout_account == body.get('links')['default_gbp_payout_account'] + assert response.links.default_nzd_payout_account == body.get('links')['default_nzd_payout_account'] + assert response.links.default_sek_payout_account == body.get('links')['default_sek_payout_account'] + assert response.links.default_usd_payout_account == body.get('links')['default_usd_payout_account'] @responses.activate def test_creditors_create_new_idempotency_key_for_each_call(): @@ -75,40 +60,37 @@ def test_creditors_create_new_idempotency_key_for_each_call(): helpers.stub_response(fixture) helpers.client.creditors.create(*fixture['url_params']) helpers.client.creditors.create(*fixture['url_params']) - assert_not_equal(responses.calls[0].request.headers.get('Idempotency-Key'), - responses.calls[1].request.headers.get('Idempotency-Key')) + assert responses.calls[0].request.headers.get('Idempotency-Key') != responses.calls[1].request.headers.get('Idempotency-Key') def test_timeout_creditors_create_idempotency_conflict(): create_fixture = helpers.load_fixture('creditors')['create'] get_fixture = helpers.load_fixture('creditors')['get'] with helpers.stub_timeout_then_idempotency_conflict(create_fixture, get_fixture) as rsps: response = helpers.client.creditors.create(*create_fixture['url_params']) - assert_equal(2, len(rsps.calls)) + assert len(rsps.calls) == 2 - assert_is_instance(response, resources.Creditor) + assert isinstance(response, resources.Creditor) @responses.activate def test_timeout_creditors_create_retries(): fixture = helpers.load_fixture('creditors')['create'] with helpers.stub_timeout_then_response(fixture) as rsps: response = helpers.client.creditors.create(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['creditors'] - assert_is_instance(response, resources.Creditor) + assert isinstance(response, resources.Creditor) def test_502_creditors_create_retries(): fixture = helpers.load_fixture('creditors')['create'] with helpers.stub_502_then_response(fixture) as rsps: response = helpers.client.creditors.create(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['creditors'] - assert_is_instance(response, resources.Creditor) + assert isinstance(response, resources.Creditor) @responses.activate @@ -118,83 +100,61 @@ def test_creditors_list(): response = helpers.client.creditors.list(*fixture['url_params']) body = fixture['body']['creditors'] - assert_is_instance(response, list_response.ListResponse) - assert_is_instance(response.records[0], resources.Creditor) - - assert_equal(response.before, fixture['body']['meta']['cursors']['before']) - assert_equal(response.after, fixture['body']['meta']['cursors']['after']) - assert_is_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal([r.address_line1 for r in response.records], - [b.get('address_line1') for b in body]) - assert_equal([r.address_line2 for r in response.records], - [b.get('address_line2') for b in body]) - assert_equal([r.address_line3 for r in response.records], - [b.get('address_line3') for b in body]) - assert_equal([r.bank_reference_prefix for r in response.records], - [b.get('bank_reference_prefix') for b in body]) - assert_equal([r.can_create_refunds for r in response.records], - [b.get('can_create_refunds') for b in body]) - assert_equal([r.city for r in response.records], - [b.get('city') for b in body]) - assert_equal([r.country_code for r in response.records], - [b.get('country_code') for b in body]) - assert_equal([r.created_at for r in response.records], - [b.get('created_at') for b in body]) - assert_equal([r.creditor_type for r in response.records], - [b.get('creditor_type') for b in body]) - assert_equal([r.custom_payment_pages_enabled for r in response.records], - [b.get('custom_payment_pages_enabled') for b in body]) - assert_equal([r.fx_payout_currency for r in response.records], - [b.get('fx_payout_currency') for b in body]) - assert_equal([r.id for r in response.records], - [b.get('id') for b in body]) - assert_equal([r.logo_url for r in response.records], - [b.get('logo_url') for b in body]) - assert_equal([r.mandate_imports_enabled for r in response.records], - [b.get('mandate_imports_enabled') for b in body]) - assert_equal([r.merchant_responsible_for_notifications for r in response.records], - [b.get('merchant_responsible_for_notifications') for b in body]) - assert_equal([r.name for r in response.records], - [b.get('name') for b in body]) - assert_equal([r.postal_code for r in response.records], - [b.get('postal_code') for b in body]) - assert_equal([r.region for r in response.records], - [b.get('region') for b in body]) - assert_equal([r.scheme_identifiers for r in response.records], - [b.get('scheme_identifiers') for b in body]) - assert_equal([r.verification_status for r in response.records], - [b.get('verification_status') for b in body]) + assert isinstance(response, list_response.ListResponse) + assert isinstance(response.records[0], resources.Creditor) + + assert response.before == fixture['body']['meta']['cursors']['before'] + assert response.after == fixture['body']['meta']['cursors']['after'] + assert responses.calls[-1].request.headers.get('Idempotency-Key') is None + assert [r.address_line1 for r in response.records] == [b.get('address_line1') for b in body] + assert [r.address_line2 for r in response.records] == [b.get('address_line2') for b in body] + assert [r.address_line3 for r in response.records] == [b.get('address_line3') for b in body] + assert [r.bank_reference_prefix for r in response.records] == [b.get('bank_reference_prefix') for b in body] + assert [r.can_create_refunds for r in response.records] == [b.get('can_create_refunds') for b in body] + assert [r.city for r in response.records] == [b.get('city') for b in body] + assert [r.country_code for r in response.records] == [b.get('country_code') for b in body] + assert [r.created_at for r in response.records] == [b.get('created_at') for b in body] + assert [r.creditor_type for r in response.records] == [b.get('creditor_type') for b in body] + assert [r.custom_payment_pages_enabled for r in response.records] == [b.get('custom_payment_pages_enabled') for b in body] + assert [r.fx_payout_currency for r in response.records] == [b.get('fx_payout_currency') for b in body] + assert [r.id for r in response.records] == [b.get('id') for b in body] + assert [r.logo_url for r in response.records] == [b.get('logo_url') for b in body] + assert [r.mandate_imports_enabled for r in response.records] == [b.get('mandate_imports_enabled') for b in body] + assert [r.merchant_responsible_for_notifications for r in response.records] == [b.get('merchant_responsible_for_notifications') for b in body] + assert [r.name for r in response.records] == [b.get('name') for b in body] + assert [r.postal_code for r in response.records] == [b.get('postal_code') for b in body] + assert [r.region for r in response.records] == [b.get('region') for b in body] + assert [r.scheme_identifiers for r in response.records] == [b.get('scheme_identifiers') for b in body] + assert [r.verification_status for r in response.records] == [b.get('verification_status') for b in body] @responses.activate def test_timeout_creditors_list_retries(): fixture = helpers.load_fixture('creditors')['list'] with helpers.stub_timeout_then_response(fixture) as rsps: response = helpers.client.creditors.list(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['creditors'] - assert_is_instance(response, list_response.ListResponse) - assert_is_instance(response.records[0], resources.Creditor) + assert isinstance(response, list_response.ListResponse) + assert isinstance(response.records[0], resources.Creditor) - assert_equal(response.before, fixture['body']['meta']['cursors']['before']) - assert_equal(response.after, fixture['body']['meta']['cursors']['after']) + assert response.before == fixture['body']['meta']['cursors']['before'] + assert response.after == fixture['body']['meta']['cursors']['after'] def test_502_creditors_list_retries(): fixture = helpers.load_fixture('creditors')['list'] with helpers.stub_502_then_response(fixture) as rsps: response = helpers.client.creditors.list(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['creditors'] - assert_is_instance(response, list_response.ListResponse) - assert_is_instance(response.records[0], resources.Creditor) + assert isinstance(response, list_response.ListResponse) + assert isinstance(response.records[0], resources.Creditor) - assert_equal(response.before, fixture['body']['meta']['cursors']['before']) - assert_equal(response.after, fixture['body']['meta']['cursors']['after']) + assert response.before == fixture['body']['meta']['cursors']['before'] + assert response.after == fixture['body']['meta']['cursors']['after'] @responses.activate def test_creditors_all(): @@ -211,9 +171,9 @@ def callback(request): responses.add_callback(fixture['method'], url, callback) all_records = list(helpers.client.creditors.all()) - assert_equal(len(all_records), len(fixture['body']['creditors']) * 2) + assert len(all_records) == len(fixture['body']['creditors']) * 2 for record in all_records: - assert_is_instance(record, resources.Creditor) + assert isinstance(record, resources.Creditor) @@ -224,67 +184,57 @@ def test_creditors_get(): response = helpers.client.creditors.get(*fixture['url_params']) body = fixture['body']['creditors'] - assert_is_instance(response, resources.Creditor) - assert_is_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal(response.address_line1, body.get('address_line1')) - assert_equal(response.address_line2, body.get('address_line2')) - assert_equal(response.address_line3, body.get('address_line3')) - assert_equal(response.bank_reference_prefix, body.get('bank_reference_prefix')) - assert_equal(response.can_create_refunds, body.get('can_create_refunds')) - assert_equal(response.city, body.get('city')) - assert_equal(response.country_code, body.get('country_code')) - assert_equal(response.created_at, body.get('created_at')) - assert_equal(response.creditor_type, body.get('creditor_type')) - assert_equal(response.custom_payment_pages_enabled, body.get('custom_payment_pages_enabled')) - assert_equal(response.fx_payout_currency, body.get('fx_payout_currency')) - assert_equal(response.id, body.get('id')) - assert_equal(response.logo_url, body.get('logo_url')) - assert_equal(response.mandate_imports_enabled, body.get('mandate_imports_enabled')) - assert_equal(response.merchant_responsible_for_notifications, body.get('merchant_responsible_for_notifications')) - assert_equal(response.name, body.get('name')) - assert_equal(response.postal_code, body.get('postal_code')) - assert_equal(response.region, body.get('region')) - assert_equal(response.scheme_identifiers, body.get('scheme_identifiers')) - assert_equal(response.verification_status, body.get('verification_status')) - assert_equal(response.links.default_aud_payout_account, - body.get('links')['default_aud_payout_account']) - assert_equal(response.links.default_cad_payout_account, - body.get('links')['default_cad_payout_account']) - assert_equal(response.links.default_dkk_payout_account, - body.get('links')['default_dkk_payout_account']) - assert_equal(response.links.default_eur_payout_account, - body.get('links')['default_eur_payout_account']) - assert_equal(response.links.default_gbp_payout_account, - body.get('links')['default_gbp_payout_account']) - assert_equal(response.links.default_nzd_payout_account, - body.get('links')['default_nzd_payout_account']) - assert_equal(response.links.default_sek_payout_account, - body.get('links')['default_sek_payout_account']) - assert_equal(response.links.default_usd_payout_account, - body.get('links')['default_usd_payout_account']) + assert isinstance(response, resources.Creditor) + assert responses.calls[-1].request.headers.get('Idempotency-Key') is None + assert response.address_line1 == body.get('address_line1') + assert response.address_line2 == body.get('address_line2') + assert response.address_line3 == body.get('address_line3') + assert response.bank_reference_prefix == body.get('bank_reference_prefix') + assert response.can_create_refunds == body.get('can_create_refunds') + assert response.city == body.get('city') + assert response.country_code == body.get('country_code') + assert response.created_at == body.get('created_at') + assert response.creditor_type == body.get('creditor_type') + assert response.custom_payment_pages_enabled == body.get('custom_payment_pages_enabled') + assert response.fx_payout_currency == body.get('fx_payout_currency') + assert response.id == body.get('id') + assert response.logo_url == body.get('logo_url') + assert response.mandate_imports_enabled == body.get('mandate_imports_enabled') + assert response.merchant_responsible_for_notifications == body.get('merchant_responsible_for_notifications') + assert response.name == body.get('name') + assert response.postal_code == body.get('postal_code') + assert response.region == body.get('region') + assert response.scheme_identifiers == body.get('scheme_identifiers') + assert response.verification_status == body.get('verification_status') + assert response.links.default_aud_payout_account == body.get('links')['default_aud_payout_account'] + assert response.links.default_cad_payout_account == body.get('links')['default_cad_payout_account'] + assert response.links.default_dkk_payout_account == body.get('links')['default_dkk_payout_account'] + assert response.links.default_eur_payout_account == body.get('links')['default_eur_payout_account'] + assert response.links.default_gbp_payout_account == body.get('links')['default_gbp_payout_account'] + assert response.links.default_nzd_payout_account == body.get('links')['default_nzd_payout_account'] + assert response.links.default_sek_payout_account == body.get('links')['default_sek_payout_account'] + assert response.links.default_usd_payout_account == body.get('links')['default_usd_payout_account'] @responses.activate def test_timeout_creditors_get_retries(): fixture = helpers.load_fixture('creditors')['get'] with helpers.stub_timeout_then_response(fixture) as rsps: response = helpers.client.creditors.get(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['creditors'] - assert_is_instance(response, resources.Creditor) + assert isinstance(response, resources.Creditor) def test_502_creditors_get_retries(): fixture = helpers.load_fixture('creditors')['get'] with helpers.stub_502_then_response(fixture) as rsps: response = helpers.client.creditors.get(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['creditors'] - assert_is_instance(response, resources.Creditor) + assert isinstance(response, resources.Creditor) @responses.activate @@ -294,65 +244,55 @@ def test_creditors_update(): response = helpers.client.creditors.update(*fixture['url_params']) body = fixture['body']['creditors'] - assert_is_instance(response, resources.Creditor) - assert_is_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal(response.address_line1, body.get('address_line1')) - assert_equal(response.address_line2, body.get('address_line2')) - assert_equal(response.address_line3, body.get('address_line3')) - assert_equal(response.bank_reference_prefix, body.get('bank_reference_prefix')) - assert_equal(response.can_create_refunds, body.get('can_create_refunds')) - assert_equal(response.city, body.get('city')) - assert_equal(response.country_code, body.get('country_code')) - assert_equal(response.created_at, body.get('created_at')) - assert_equal(response.creditor_type, body.get('creditor_type')) - assert_equal(response.custom_payment_pages_enabled, body.get('custom_payment_pages_enabled')) - assert_equal(response.fx_payout_currency, body.get('fx_payout_currency')) - assert_equal(response.id, body.get('id')) - assert_equal(response.logo_url, body.get('logo_url')) - assert_equal(response.mandate_imports_enabled, body.get('mandate_imports_enabled')) - assert_equal(response.merchant_responsible_for_notifications, body.get('merchant_responsible_for_notifications')) - assert_equal(response.name, body.get('name')) - assert_equal(response.postal_code, body.get('postal_code')) - assert_equal(response.region, body.get('region')) - assert_equal(response.scheme_identifiers, body.get('scheme_identifiers')) - assert_equal(response.verification_status, body.get('verification_status')) - assert_equal(response.links.default_aud_payout_account, - body.get('links')['default_aud_payout_account']) - assert_equal(response.links.default_cad_payout_account, - body.get('links')['default_cad_payout_account']) - assert_equal(response.links.default_dkk_payout_account, - body.get('links')['default_dkk_payout_account']) - assert_equal(response.links.default_eur_payout_account, - body.get('links')['default_eur_payout_account']) - assert_equal(response.links.default_gbp_payout_account, - body.get('links')['default_gbp_payout_account']) - assert_equal(response.links.default_nzd_payout_account, - body.get('links')['default_nzd_payout_account']) - assert_equal(response.links.default_sek_payout_account, - body.get('links')['default_sek_payout_account']) - assert_equal(response.links.default_usd_payout_account, - body.get('links')['default_usd_payout_account']) + assert isinstance(response, resources.Creditor) + assert responses.calls[-1].request.headers.get('Idempotency-Key') is None + assert response.address_line1 == body.get('address_line1') + assert response.address_line2 == body.get('address_line2') + assert response.address_line3 == body.get('address_line3') + assert response.bank_reference_prefix == body.get('bank_reference_prefix') + assert response.can_create_refunds == body.get('can_create_refunds') + assert response.city == body.get('city') + assert response.country_code == body.get('country_code') + assert response.created_at == body.get('created_at') + assert response.creditor_type == body.get('creditor_type') + assert response.custom_payment_pages_enabled == body.get('custom_payment_pages_enabled') + assert response.fx_payout_currency == body.get('fx_payout_currency') + assert response.id == body.get('id') + assert response.logo_url == body.get('logo_url') + assert response.mandate_imports_enabled == body.get('mandate_imports_enabled') + assert response.merchant_responsible_for_notifications == body.get('merchant_responsible_for_notifications') + assert response.name == body.get('name') + assert response.postal_code == body.get('postal_code') + assert response.region == body.get('region') + assert response.scheme_identifiers == body.get('scheme_identifiers') + assert response.verification_status == body.get('verification_status') + assert response.links.default_aud_payout_account == body.get('links')['default_aud_payout_account'] + assert response.links.default_cad_payout_account == body.get('links')['default_cad_payout_account'] + assert response.links.default_dkk_payout_account == body.get('links')['default_dkk_payout_account'] + assert response.links.default_eur_payout_account == body.get('links')['default_eur_payout_account'] + assert response.links.default_gbp_payout_account == body.get('links')['default_gbp_payout_account'] + assert response.links.default_nzd_payout_account == body.get('links')['default_nzd_payout_account'] + assert response.links.default_sek_payout_account == body.get('links')['default_sek_payout_account'] + assert response.links.default_usd_payout_account == body.get('links')['default_usd_payout_account'] @responses.activate def test_timeout_creditors_update_retries(): fixture = helpers.load_fixture('creditors')['update'] with helpers.stub_timeout_then_response(fixture) as rsps: response = helpers.client.creditors.update(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['creditors'] - assert_is_instance(response, resources.Creditor) + assert isinstance(response, resources.Creditor) def test_502_creditors_update_retries(): fixture = helpers.load_fixture('creditors')['update'] with helpers.stub_502_then_response(fixture) as rsps: response = helpers.client.creditors.update(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['creditors'] - assert_is_instance(response, resources.Creditor) + assert isinstance(response, resources.Creditor) diff --git a/tests/integration/currency_exchange_rates_integration_test.py b/tests/integration/currency_exchange_rates_integration_test.py index b0744586..22df66d6 100644 --- a/tests/integration/currency_exchange_rates_integration_test.py +++ b/tests/integration/currency_exchange_rates_integration_test.py @@ -5,16 +5,9 @@ import json +import pytest import requests import responses -from nose.tools import ( - assert_equal, - assert_is_instance, - assert_is_none, - assert_is_not_none, - assert_not_equal, - assert_raises -) from gocardless_pro.errors import MalformedResponseError from gocardless_pro import resources @@ -30,51 +23,45 @@ def test_currency_exchange_rates_list(): response = helpers.client.currency_exchange_rates.list(*fixture['url_params']) body = fixture['body']['currency_exchange_rates'] - assert_is_instance(response, list_response.ListResponse) - assert_is_instance(response.records[0], resources.CurrencyExchangeRate) - - assert_equal(response.before, fixture['body']['meta']['cursors']['before']) - assert_equal(response.after, fixture['body']['meta']['cursors']['after']) - assert_is_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal([r.rate for r in response.records], - [b.get('rate') for b in body]) - assert_equal([r.source for r in response.records], - [b.get('source') for b in body]) - assert_equal([r.target for r in response.records], - [b.get('target') for b in body]) - assert_equal([r.time for r in response.records], - [b.get('time') for b in body]) + assert isinstance(response, list_response.ListResponse) + assert isinstance(response.records[0], resources.CurrencyExchangeRate) + + assert response.before == fixture['body']['meta']['cursors']['before'] + assert response.after == fixture['body']['meta']['cursors']['after'] + assert responses.calls[-1].request.headers.get('Idempotency-Key') is None + assert [r.rate for r in response.records] == [b.get('rate') for b in body] + assert [r.source for r in response.records] == [b.get('source') for b in body] + assert [r.target for r in response.records] == [b.get('target') for b in body] + assert [r.time for r in response.records] == [b.get('time') for b in body] @responses.activate def test_timeout_currency_exchange_rates_list_retries(): fixture = helpers.load_fixture('currency_exchange_rates')['list'] with helpers.stub_timeout_then_response(fixture) as rsps: response = helpers.client.currency_exchange_rates.list(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['currency_exchange_rates'] - assert_is_instance(response, list_response.ListResponse) - assert_is_instance(response.records[0], resources.CurrencyExchangeRate) + assert isinstance(response, list_response.ListResponse) + assert isinstance(response.records[0], resources.CurrencyExchangeRate) - assert_equal(response.before, fixture['body']['meta']['cursors']['before']) - assert_equal(response.after, fixture['body']['meta']['cursors']['after']) + assert response.before == fixture['body']['meta']['cursors']['before'] + assert response.after == fixture['body']['meta']['cursors']['after'] def test_502_currency_exchange_rates_list_retries(): fixture = helpers.load_fixture('currency_exchange_rates')['list'] with helpers.stub_502_then_response(fixture) as rsps: response = helpers.client.currency_exchange_rates.list(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['currency_exchange_rates'] - assert_is_instance(response, list_response.ListResponse) - assert_is_instance(response.records[0], resources.CurrencyExchangeRate) + assert isinstance(response, list_response.ListResponse) + assert isinstance(response.records[0], resources.CurrencyExchangeRate) - assert_equal(response.before, fixture['body']['meta']['cursors']['before']) - assert_equal(response.after, fixture['body']['meta']['cursors']['after']) + assert response.before == fixture['body']['meta']['cursors']['before'] + assert response.after == fixture['body']['meta']['cursors']['after'] @responses.activate def test_currency_exchange_rates_all(): @@ -91,8 +78,8 @@ def callback(request): responses.add_callback(fixture['method'], url, callback) all_records = list(helpers.client.currency_exchange_rates.all()) - assert_equal(len(all_records), len(fixture['body']['currency_exchange_rates']) * 2) + assert len(all_records) == len(fixture['body']['currency_exchange_rates']) * 2 for record in all_records: - assert_is_instance(record, resources.CurrencyExchangeRate) + assert isinstance(record, resources.CurrencyExchangeRate) diff --git a/tests/integration/customer_bank_accounts_integration_test.py b/tests/integration/customer_bank_accounts_integration_test.py index 8a6b139d..52470414 100644 --- a/tests/integration/customer_bank_accounts_integration_test.py +++ b/tests/integration/customer_bank_accounts_integration_test.py @@ -5,16 +5,9 @@ import json +import pytest import requests import responses -from nose.tools import ( - assert_equal, - assert_is_instance, - assert_is_none, - assert_is_not_none, - assert_not_equal, - assert_raises -) from gocardless_pro.errors import MalformedResponseError from gocardless_pro import resources @@ -30,20 +23,19 @@ def test_customer_bank_accounts_create(): response = helpers.client.customer_bank_accounts.create(*fixture['url_params']) body = fixture['body']['customer_bank_accounts'] - assert_is_instance(response, resources.CustomerBankAccount) - assert_is_not_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal(response.account_holder_name, body.get('account_holder_name')) - assert_equal(response.account_number_ending, body.get('account_number_ending')) - assert_equal(response.account_type, body.get('account_type')) - assert_equal(response.bank_name, body.get('bank_name')) - assert_equal(response.country_code, body.get('country_code')) - assert_equal(response.created_at, body.get('created_at')) - assert_equal(response.currency, body.get('currency')) - assert_equal(response.enabled, body.get('enabled')) - assert_equal(response.id, body.get('id')) - assert_equal(response.metadata, body.get('metadata')) - assert_equal(response.links.customer, - body.get('links')['customer']) + assert isinstance(response, resources.CustomerBankAccount) + assert responses.calls[-1].request.headers.get('Idempotency-Key') is not None + assert response.account_holder_name == body.get('account_holder_name') + assert response.account_number_ending == body.get('account_number_ending') + assert response.account_type == body.get('account_type') + assert response.bank_name == body.get('bank_name') + assert response.country_code == body.get('country_code') + assert response.created_at == body.get('created_at') + assert response.currency == body.get('currency') + assert response.enabled == body.get('enabled') + assert response.id == body.get('id') + assert response.metadata == body.get('metadata') + assert response.links.customer == body.get('links')['customer'] @responses.activate def test_customer_bank_accounts_create_new_idempotency_key_for_each_call(): @@ -51,40 +43,37 @@ def test_customer_bank_accounts_create_new_idempotency_key_for_each_call(): helpers.stub_response(fixture) helpers.client.customer_bank_accounts.create(*fixture['url_params']) helpers.client.customer_bank_accounts.create(*fixture['url_params']) - assert_not_equal(responses.calls[0].request.headers.get('Idempotency-Key'), - responses.calls[1].request.headers.get('Idempotency-Key')) + assert responses.calls[0].request.headers.get('Idempotency-Key') != responses.calls[1].request.headers.get('Idempotency-Key') def test_timeout_customer_bank_accounts_create_idempotency_conflict(): create_fixture = helpers.load_fixture('customer_bank_accounts')['create'] get_fixture = helpers.load_fixture('customer_bank_accounts')['get'] with helpers.stub_timeout_then_idempotency_conflict(create_fixture, get_fixture) as rsps: response = helpers.client.customer_bank_accounts.create(*create_fixture['url_params']) - assert_equal(2, len(rsps.calls)) + assert len(rsps.calls) == 2 - assert_is_instance(response, resources.CustomerBankAccount) + assert isinstance(response, resources.CustomerBankAccount) @responses.activate def test_timeout_customer_bank_accounts_create_retries(): fixture = helpers.load_fixture('customer_bank_accounts')['create'] with helpers.stub_timeout_then_response(fixture) as rsps: response = helpers.client.customer_bank_accounts.create(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['customer_bank_accounts'] - assert_is_instance(response, resources.CustomerBankAccount) + assert isinstance(response, resources.CustomerBankAccount) def test_502_customer_bank_accounts_create_retries(): fixture = helpers.load_fixture('customer_bank_accounts')['create'] with helpers.stub_502_then_response(fixture) as rsps: response = helpers.client.customer_bank_accounts.create(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['customer_bank_accounts'] - assert_is_instance(response, resources.CustomerBankAccount) + assert isinstance(response, resources.CustomerBankAccount) @responses.activate @@ -94,63 +83,51 @@ def test_customer_bank_accounts_list(): response = helpers.client.customer_bank_accounts.list(*fixture['url_params']) body = fixture['body']['customer_bank_accounts'] - assert_is_instance(response, list_response.ListResponse) - assert_is_instance(response.records[0], resources.CustomerBankAccount) - - assert_equal(response.before, fixture['body']['meta']['cursors']['before']) - assert_equal(response.after, fixture['body']['meta']['cursors']['after']) - assert_is_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal([r.account_holder_name for r in response.records], - [b.get('account_holder_name') for b in body]) - assert_equal([r.account_number_ending for r in response.records], - [b.get('account_number_ending') for b in body]) - assert_equal([r.account_type for r in response.records], - [b.get('account_type') for b in body]) - assert_equal([r.bank_name for r in response.records], - [b.get('bank_name') for b in body]) - assert_equal([r.country_code for r in response.records], - [b.get('country_code') for b in body]) - assert_equal([r.created_at for r in response.records], - [b.get('created_at') for b in body]) - assert_equal([r.currency for r in response.records], - [b.get('currency') for b in body]) - assert_equal([r.enabled for r in response.records], - [b.get('enabled') for b in body]) - assert_equal([r.id for r in response.records], - [b.get('id') for b in body]) - assert_equal([r.metadata for r in response.records], - [b.get('metadata') for b in body]) + assert isinstance(response, list_response.ListResponse) + assert isinstance(response.records[0], resources.CustomerBankAccount) + + assert response.before == fixture['body']['meta']['cursors']['before'] + assert response.after == fixture['body']['meta']['cursors']['after'] + assert responses.calls[-1].request.headers.get('Idempotency-Key') is None + assert [r.account_holder_name for r in response.records] == [b.get('account_holder_name') for b in body] + assert [r.account_number_ending for r in response.records] == [b.get('account_number_ending') for b in body] + assert [r.account_type for r in response.records] == [b.get('account_type') for b in body] + assert [r.bank_name for r in response.records] == [b.get('bank_name') for b in body] + assert [r.country_code for r in response.records] == [b.get('country_code') for b in body] + assert [r.created_at for r in response.records] == [b.get('created_at') for b in body] + assert [r.currency for r in response.records] == [b.get('currency') for b in body] + assert [r.enabled for r in response.records] == [b.get('enabled') for b in body] + assert [r.id for r in response.records] == [b.get('id') for b in body] + assert [r.metadata for r in response.records] == [b.get('metadata') for b in body] @responses.activate def test_timeout_customer_bank_accounts_list_retries(): fixture = helpers.load_fixture('customer_bank_accounts')['list'] with helpers.stub_timeout_then_response(fixture) as rsps: response = helpers.client.customer_bank_accounts.list(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['customer_bank_accounts'] - assert_is_instance(response, list_response.ListResponse) - assert_is_instance(response.records[0], resources.CustomerBankAccount) + assert isinstance(response, list_response.ListResponse) + assert isinstance(response.records[0], resources.CustomerBankAccount) - assert_equal(response.before, fixture['body']['meta']['cursors']['before']) - assert_equal(response.after, fixture['body']['meta']['cursors']['after']) + assert response.before == fixture['body']['meta']['cursors']['before'] + assert response.after == fixture['body']['meta']['cursors']['after'] def test_502_customer_bank_accounts_list_retries(): fixture = helpers.load_fixture('customer_bank_accounts')['list'] with helpers.stub_502_then_response(fixture) as rsps: response = helpers.client.customer_bank_accounts.list(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['customer_bank_accounts'] - assert_is_instance(response, list_response.ListResponse) - assert_is_instance(response.records[0], resources.CustomerBankAccount) + assert isinstance(response, list_response.ListResponse) + assert isinstance(response.records[0], resources.CustomerBankAccount) - assert_equal(response.before, fixture['body']['meta']['cursors']['before']) - assert_equal(response.after, fixture['body']['meta']['cursors']['after']) + assert response.before == fixture['body']['meta']['cursors']['before'] + assert response.after == fixture['body']['meta']['cursors']['after'] @responses.activate def test_customer_bank_accounts_all(): @@ -167,9 +144,9 @@ def callback(request): responses.add_callback(fixture['method'], url, callback) all_records = list(helpers.client.customer_bank_accounts.all()) - assert_equal(len(all_records), len(fixture['body']['customer_bank_accounts']) * 2) + assert len(all_records) == len(fixture['body']['customer_bank_accounts']) * 2 for record in all_records: - assert_is_instance(record, resources.CustomerBankAccount) + assert isinstance(record, resources.CustomerBankAccount) @@ -180,43 +157,40 @@ def test_customer_bank_accounts_get(): response = helpers.client.customer_bank_accounts.get(*fixture['url_params']) body = fixture['body']['customer_bank_accounts'] - assert_is_instance(response, resources.CustomerBankAccount) - assert_is_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal(response.account_holder_name, body.get('account_holder_name')) - assert_equal(response.account_number_ending, body.get('account_number_ending')) - assert_equal(response.account_type, body.get('account_type')) - assert_equal(response.bank_name, body.get('bank_name')) - assert_equal(response.country_code, body.get('country_code')) - assert_equal(response.created_at, body.get('created_at')) - assert_equal(response.currency, body.get('currency')) - assert_equal(response.enabled, body.get('enabled')) - assert_equal(response.id, body.get('id')) - assert_equal(response.metadata, body.get('metadata')) - assert_equal(response.links.customer, - body.get('links')['customer']) + assert isinstance(response, resources.CustomerBankAccount) + assert responses.calls[-1].request.headers.get('Idempotency-Key') is None + assert response.account_holder_name == body.get('account_holder_name') + assert response.account_number_ending == body.get('account_number_ending') + assert response.account_type == body.get('account_type') + assert response.bank_name == body.get('bank_name') + assert response.country_code == body.get('country_code') + assert response.created_at == body.get('created_at') + assert response.currency == body.get('currency') + assert response.enabled == body.get('enabled') + assert response.id == body.get('id') + assert response.metadata == body.get('metadata') + assert response.links.customer == body.get('links')['customer'] @responses.activate def test_timeout_customer_bank_accounts_get_retries(): fixture = helpers.load_fixture('customer_bank_accounts')['get'] with helpers.stub_timeout_then_response(fixture) as rsps: response = helpers.client.customer_bank_accounts.get(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['customer_bank_accounts'] - assert_is_instance(response, resources.CustomerBankAccount) + assert isinstance(response, resources.CustomerBankAccount) def test_502_customer_bank_accounts_get_retries(): fixture = helpers.load_fixture('customer_bank_accounts')['get'] with helpers.stub_502_then_response(fixture) as rsps: response = helpers.client.customer_bank_accounts.get(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['customer_bank_accounts'] - assert_is_instance(response, resources.CustomerBankAccount) + assert isinstance(response, resources.CustomerBankAccount) @responses.activate @@ -226,43 +200,40 @@ def test_customer_bank_accounts_update(): response = helpers.client.customer_bank_accounts.update(*fixture['url_params']) body = fixture['body']['customer_bank_accounts'] - assert_is_instance(response, resources.CustomerBankAccount) - assert_is_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal(response.account_holder_name, body.get('account_holder_name')) - assert_equal(response.account_number_ending, body.get('account_number_ending')) - assert_equal(response.account_type, body.get('account_type')) - assert_equal(response.bank_name, body.get('bank_name')) - assert_equal(response.country_code, body.get('country_code')) - assert_equal(response.created_at, body.get('created_at')) - assert_equal(response.currency, body.get('currency')) - assert_equal(response.enabled, body.get('enabled')) - assert_equal(response.id, body.get('id')) - assert_equal(response.metadata, body.get('metadata')) - assert_equal(response.links.customer, - body.get('links')['customer']) + assert isinstance(response, resources.CustomerBankAccount) + assert responses.calls[-1].request.headers.get('Idempotency-Key') is None + assert response.account_holder_name == body.get('account_holder_name') + assert response.account_number_ending == body.get('account_number_ending') + assert response.account_type == body.get('account_type') + assert response.bank_name == body.get('bank_name') + assert response.country_code == body.get('country_code') + assert response.created_at == body.get('created_at') + assert response.currency == body.get('currency') + assert response.enabled == body.get('enabled') + assert response.id == body.get('id') + assert response.metadata == body.get('metadata') + assert response.links.customer == body.get('links')['customer'] @responses.activate def test_timeout_customer_bank_accounts_update_retries(): fixture = helpers.load_fixture('customer_bank_accounts')['update'] with helpers.stub_timeout_then_response(fixture) as rsps: response = helpers.client.customer_bank_accounts.update(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['customer_bank_accounts'] - assert_is_instance(response, resources.CustomerBankAccount) + assert isinstance(response, resources.CustomerBankAccount) def test_502_customer_bank_accounts_update_retries(): fixture = helpers.load_fixture('customer_bank_accounts')['update'] with helpers.stub_502_then_response(fixture) as rsps: response = helpers.client.customer_bank_accounts.update(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['customer_bank_accounts'] - assert_is_instance(response, resources.CustomerBankAccount) + assert isinstance(response, resources.CustomerBankAccount) @responses.activate @@ -272,32 +243,31 @@ def test_customer_bank_accounts_disable(): response = helpers.client.customer_bank_accounts.disable(*fixture['url_params']) body = fixture['body']['customer_bank_accounts'] - assert_is_instance(response, resources.CustomerBankAccount) - assert_is_not_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal(response.account_holder_name, body.get('account_holder_name')) - assert_equal(response.account_number_ending, body.get('account_number_ending')) - assert_equal(response.account_type, body.get('account_type')) - assert_equal(response.bank_name, body.get('bank_name')) - assert_equal(response.country_code, body.get('country_code')) - assert_equal(response.created_at, body.get('created_at')) - assert_equal(response.currency, body.get('currency')) - assert_equal(response.enabled, body.get('enabled')) - assert_equal(response.id, body.get('id')) - assert_equal(response.metadata, body.get('metadata')) - assert_equal(response.links.customer, - body.get('links')['customer']) + assert isinstance(response, resources.CustomerBankAccount) + assert responses.calls[-1].request.headers.get('Idempotency-Key') is not None + assert response.account_holder_name == body.get('account_holder_name') + assert response.account_number_ending == body.get('account_number_ending') + assert response.account_type == body.get('account_type') + assert response.bank_name == body.get('bank_name') + assert response.country_code == body.get('country_code') + assert response.created_at == body.get('created_at') + assert response.currency == body.get('currency') + assert response.enabled == body.get('enabled') + assert response.id == body.get('id') + assert response.metadata == body.get('metadata') + assert response.links.customer == body.get('links')['customer'] def test_timeout_customer_bank_accounts_disable_doesnt_retry(): fixture = helpers.load_fixture('customer_bank_accounts')['disable'] with helpers.stub_timeout(fixture) as rsps: - with assert_raises(requests.ConnectTimeout): + with pytest.raises(requests.ConnectTimeout): response = helpers.client.customer_bank_accounts.disable(*fixture['url_params']) - assert_equal(1, len(rsps.calls)) + assert len(rsps.calls) == 1 def test_502_customer_bank_accounts_disable_doesnt_retry(): fixture = helpers.load_fixture('customer_bank_accounts')['disable'] with helpers.stub_502(fixture) as rsps: - with assert_raises(MalformedResponseError): + with pytest.raises(MalformedResponseError): response = helpers.client.customer_bank_accounts.disable(*fixture['url_params']) - assert_equal(1, len(rsps.calls)) + assert len(rsps.calls) == 1 diff --git a/tests/integration/customer_notifications_integration_test.py b/tests/integration/customer_notifications_integration_test.py index ae740396..66a3b422 100644 --- a/tests/integration/customer_notifications_integration_test.py +++ b/tests/integration/customer_notifications_integration_test.py @@ -5,16 +5,9 @@ import json +import pytest import requests import responses -from nose.tools import ( - assert_equal, - assert_is_instance, - assert_is_none, - assert_is_not_none, - assert_not_equal, - assert_raises -) from gocardless_pro.errors import MalformedResponseError from gocardless_pro import resources @@ -30,37 +23,31 @@ def test_customer_notifications_handle(): response = helpers.client.customer_notifications.handle(*fixture['url_params']) body = fixture['body']['customer_notifications'] - assert_is_instance(response, resources.CustomerNotification) - assert_is_not_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal(response.action_taken, body.get('action_taken')) - assert_equal(response.action_taken_at, body.get('action_taken_at')) - assert_equal(response.action_taken_by, body.get('action_taken_by')) - assert_equal(response.id, body.get('id')) - assert_equal(response.type, body.get('type')) - assert_equal(response.links.customer, - body.get('links')['customer']) - assert_equal(response.links.event, - body.get('links')['event']) - assert_equal(response.links.mandate, - body.get('links')['mandate']) - assert_equal(response.links.payment, - body.get('links')['payment']) - assert_equal(response.links.refund, - body.get('links')['refund']) - assert_equal(response.links.subscription, - body.get('links')['subscription']) + assert isinstance(response, resources.CustomerNotification) + assert responses.calls[-1].request.headers.get('Idempotency-Key') is not None + assert response.action_taken == body.get('action_taken') + assert response.action_taken_at == body.get('action_taken_at') + assert response.action_taken_by == body.get('action_taken_by') + assert response.id == body.get('id') + assert response.type == body.get('type') + assert response.links.customer == body.get('links')['customer'] + assert response.links.event == body.get('links')['event'] + assert response.links.mandate == body.get('links')['mandate'] + assert response.links.payment == body.get('links')['payment'] + assert response.links.refund == body.get('links')['refund'] + assert response.links.subscription == body.get('links')['subscription'] def test_timeout_customer_notifications_handle_doesnt_retry(): fixture = helpers.load_fixture('customer_notifications')['handle'] with helpers.stub_timeout(fixture) as rsps: - with assert_raises(requests.ConnectTimeout): + with pytest.raises(requests.ConnectTimeout): response = helpers.client.customer_notifications.handle(*fixture['url_params']) - assert_equal(1, len(rsps.calls)) + assert len(rsps.calls) == 1 def test_502_customer_notifications_handle_doesnt_retry(): fixture = helpers.load_fixture('customer_notifications')['handle'] with helpers.stub_502(fixture) as rsps: - with assert_raises(MalformedResponseError): + with pytest.raises(MalformedResponseError): response = helpers.client.customer_notifications.handle(*fixture['url_params']) - assert_equal(1, len(rsps.calls)) + assert len(rsps.calls) == 1 diff --git a/tests/integration/customers_integration_test.py b/tests/integration/customers_integration_test.py index b82278d1..f7ed9209 100644 --- a/tests/integration/customers_integration_test.py +++ b/tests/integration/customers_integration_test.py @@ -5,16 +5,9 @@ import json +import pytest import requests import responses -from nose.tools import ( - assert_equal, - assert_is_instance, - assert_is_none, - assert_is_not_none, - assert_not_equal, - assert_raises -) from gocardless_pro.errors import MalformedResponseError from gocardless_pro import resources @@ -30,26 +23,26 @@ def test_customers_create(): response = helpers.client.customers.create(*fixture['url_params']) body = fixture['body']['customers'] - assert_is_instance(response, resources.Customer) - assert_is_not_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal(response.address_line1, body.get('address_line1')) - assert_equal(response.address_line2, body.get('address_line2')) - assert_equal(response.address_line3, body.get('address_line3')) - assert_equal(response.city, body.get('city')) - assert_equal(response.company_name, body.get('company_name')) - assert_equal(response.country_code, body.get('country_code')) - assert_equal(response.created_at, body.get('created_at')) - assert_equal(response.danish_identity_number, body.get('danish_identity_number')) - assert_equal(response.email, body.get('email')) - assert_equal(response.family_name, body.get('family_name')) - assert_equal(response.given_name, body.get('given_name')) - assert_equal(response.id, body.get('id')) - assert_equal(response.language, body.get('language')) - assert_equal(response.metadata, body.get('metadata')) - assert_equal(response.phone_number, body.get('phone_number')) - assert_equal(response.postal_code, body.get('postal_code')) - assert_equal(response.region, body.get('region')) - assert_equal(response.swedish_identity_number, body.get('swedish_identity_number')) + assert isinstance(response, resources.Customer) + assert responses.calls[-1].request.headers.get('Idempotency-Key') is not None + assert response.address_line1 == body.get('address_line1') + assert response.address_line2 == body.get('address_line2') + assert response.address_line3 == body.get('address_line3') + assert response.city == body.get('city') + assert response.company_name == body.get('company_name') + assert response.country_code == body.get('country_code') + assert response.created_at == body.get('created_at') + assert response.danish_identity_number == body.get('danish_identity_number') + assert response.email == body.get('email') + assert response.family_name == body.get('family_name') + assert response.given_name == body.get('given_name') + assert response.id == body.get('id') + assert response.language == body.get('language') + assert response.metadata == body.get('metadata') + assert response.phone_number == body.get('phone_number') + assert response.postal_code == body.get('postal_code') + assert response.region == body.get('region') + assert response.swedish_identity_number == body.get('swedish_identity_number') @responses.activate def test_customers_create_new_idempotency_key_for_each_call(): @@ -57,40 +50,37 @@ def test_customers_create_new_idempotency_key_for_each_call(): helpers.stub_response(fixture) helpers.client.customers.create(*fixture['url_params']) helpers.client.customers.create(*fixture['url_params']) - assert_not_equal(responses.calls[0].request.headers.get('Idempotency-Key'), - responses.calls[1].request.headers.get('Idempotency-Key')) + assert responses.calls[0].request.headers.get('Idempotency-Key') != responses.calls[1].request.headers.get('Idempotency-Key') def test_timeout_customers_create_idempotency_conflict(): create_fixture = helpers.load_fixture('customers')['create'] get_fixture = helpers.load_fixture('customers')['get'] with helpers.stub_timeout_then_idempotency_conflict(create_fixture, get_fixture) as rsps: response = helpers.client.customers.create(*create_fixture['url_params']) - assert_equal(2, len(rsps.calls)) + assert len(rsps.calls) == 2 - assert_is_instance(response, resources.Customer) + assert isinstance(response, resources.Customer) @responses.activate def test_timeout_customers_create_retries(): fixture = helpers.load_fixture('customers')['create'] with helpers.stub_timeout_then_response(fixture) as rsps: response = helpers.client.customers.create(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['customers'] - assert_is_instance(response, resources.Customer) + assert isinstance(response, resources.Customer) def test_502_customers_create_retries(): fixture = helpers.load_fixture('customers')['create'] with helpers.stub_502_then_response(fixture) as rsps: response = helpers.client.customers.create(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['customers'] - assert_is_instance(response, resources.Customer) + assert isinstance(response, resources.Customer) @responses.activate @@ -100,79 +90,59 @@ def test_customers_list(): response = helpers.client.customers.list(*fixture['url_params']) body = fixture['body']['customers'] - assert_is_instance(response, list_response.ListResponse) - assert_is_instance(response.records[0], resources.Customer) - - assert_equal(response.before, fixture['body']['meta']['cursors']['before']) - assert_equal(response.after, fixture['body']['meta']['cursors']['after']) - assert_is_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal([r.address_line1 for r in response.records], - [b.get('address_line1') for b in body]) - assert_equal([r.address_line2 for r in response.records], - [b.get('address_line2') for b in body]) - assert_equal([r.address_line3 for r in response.records], - [b.get('address_line3') for b in body]) - assert_equal([r.city for r in response.records], - [b.get('city') for b in body]) - assert_equal([r.company_name for r in response.records], - [b.get('company_name') for b in body]) - assert_equal([r.country_code for r in response.records], - [b.get('country_code') for b in body]) - assert_equal([r.created_at for r in response.records], - [b.get('created_at') for b in body]) - assert_equal([r.danish_identity_number for r in response.records], - [b.get('danish_identity_number') for b in body]) - assert_equal([r.email for r in response.records], - [b.get('email') for b in body]) - assert_equal([r.family_name for r in response.records], - [b.get('family_name') for b in body]) - assert_equal([r.given_name for r in response.records], - [b.get('given_name') for b in body]) - assert_equal([r.id for r in response.records], - [b.get('id') for b in body]) - assert_equal([r.language for r in response.records], - [b.get('language') for b in body]) - assert_equal([r.metadata for r in response.records], - [b.get('metadata') for b in body]) - assert_equal([r.phone_number for r in response.records], - [b.get('phone_number') for b in body]) - assert_equal([r.postal_code for r in response.records], - [b.get('postal_code') for b in body]) - assert_equal([r.region for r in response.records], - [b.get('region') for b in body]) - assert_equal([r.swedish_identity_number for r in response.records], - [b.get('swedish_identity_number') for b in body]) + assert isinstance(response, list_response.ListResponse) + assert isinstance(response.records[0], resources.Customer) + + assert response.before == fixture['body']['meta']['cursors']['before'] + assert response.after == fixture['body']['meta']['cursors']['after'] + assert responses.calls[-1].request.headers.get('Idempotency-Key') is None + assert [r.address_line1 for r in response.records] == [b.get('address_line1') for b in body] + assert [r.address_line2 for r in response.records] == [b.get('address_line2') for b in body] + assert [r.address_line3 for r in response.records] == [b.get('address_line3') for b in body] + assert [r.city for r in response.records] == [b.get('city') for b in body] + assert [r.company_name for r in response.records] == [b.get('company_name') for b in body] + assert [r.country_code for r in response.records] == [b.get('country_code') for b in body] + assert [r.created_at for r in response.records] == [b.get('created_at') for b in body] + assert [r.danish_identity_number for r in response.records] == [b.get('danish_identity_number') for b in body] + assert [r.email for r in response.records] == [b.get('email') for b in body] + assert [r.family_name for r in response.records] == [b.get('family_name') for b in body] + assert [r.given_name for r in response.records] == [b.get('given_name') for b in body] + assert [r.id for r in response.records] == [b.get('id') for b in body] + assert [r.language for r in response.records] == [b.get('language') for b in body] + assert [r.metadata for r in response.records] == [b.get('metadata') for b in body] + assert [r.phone_number for r in response.records] == [b.get('phone_number') for b in body] + assert [r.postal_code for r in response.records] == [b.get('postal_code') for b in body] + assert [r.region for r in response.records] == [b.get('region') for b in body] + assert [r.swedish_identity_number for r in response.records] == [b.get('swedish_identity_number') for b in body] @responses.activate def test_timeout_customers_list_retries(): fixture = helpers.load_fixture('customers')['list'] with helpers.stub_timeout_then_response(fixture) as rsps: response = helpers.client.customers.list(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['customers'] - assert_is_instance(response, list_response.ListResponse) - assert_is_instance(response.records[0], resources.Customer) + assert isinstance(response, list_response.ListResponse) + assert isinstance(response.records[0], resources.Customer) - assert_equal(response.before, fixture['body']['meta']['cursors']['before']) - assert_equal(response.after, fixture['body']['meta']['cursors']['after']) + assert response.before == fixture['body']['meta']['cursors']['before'] + assert response.after == fixture['body']['meta']['cursors']['after'] def test_502_customers_list_retries(): fixture = helpers.load_fixture('customers')['list'] with helpers.stub_502_then_response(fixture) as rsps: response = helpers.client.customers.list(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['customers'] - assert_is_instance(response, list_response.ListResponse) - assert_is_instance(response.records[0], resources.Customer) + assert isinstance(response, list_response.ListResponse) + assert isinstance(response.records[0], resources.Customer) - assert_equal(response.before, fixture['body']['meta']['cursors']['before']) - assert_equal(response.after, fixture['body']['meta']['cursors']['after']) + assert response.before == fixture['body']['meta']['cursors']['before'] + assert response.after == fixture['body']['meta']['cursors']['after'] @responses.activate def test_customers_all(): @@ -189,9 +159,9 @@ def callback(request): responses.add_callback(fixture['method'], url, callback) all_records = list(helpers.client.customers.all()) - assert_equal(len(all_records), len(fixture['body']['customers']) * 2) + assert len(all_records) == len(fixture['body']['customers']) * 2 for record in all_records: - assert_is_instance(record, resources.Customer) + assert isinstance(record, resources.Customer) @@ -202,49 +172,47 @@ def test_customers_get(): response = helpers.client.customers.get(*fixture['url_params']) body = fixture['body']['customers'] - assert_is_instance(response, resources.Customer) - assert_is_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal(response.address_line1, body.get('address_line1')) - assert_equal(response.address_line2, body.get('address_line2')) - assert_equal(response.address_line3, body.get('address_line3')) - assert_equal(response.city, body.get('city')) - assert_equal(response.company_name, body.get('company_name')) - assert_equal(response.country_code, body.get('country_code')) - assert_equal(response.created_at, body.get('created_at')) - assert_equal(response.danish_identity_number, body.get('danish_identity_number')) - assert_equal(response.email, body.get('email')) - assert_equal(response.family_name, body.get('family_name')) - assert_equal(response.given_name, body.get('given_name')) - assert_equal(response.id, body.get('id')) - assert_equal(response.language, body.get('language')) - assert_equal(response.metadata, body.get('metadata')) - assert_equal(response.phone_number, body.get('phone_number')) - assert_equal(response.postal_code, body.get('postal_code')) - assert_equal(response.region, body.get('region')) - assert_equal(response.swedish_identity_number, body.get('swedish_identity_number')) + assert isinstance(response, resources.Customer) + assert responses.calls[-1].request.headers.get('Idempotency-Key') is None + assert response.address_line1 == body.get('address_line1') + assert response.address_line2 == body.get('address_line2') + assert response.address_line3 == body.get('address_line3') + assert response.city == body.get('city') + assert response.company_name == body.get('company_name') + assert response.country_code == body.get('country_code') + assert response.created_at == body.get('created_at') + assert response.danish_identity_number == body.get('danish_identity_number') + assert response.email == body.get('email') + assert response.family_name == body.get('family_name') + assert response.given_name == body.get('given_name') + assert response.id == body.get('id') + assert response.language == body.get('language') + assert response.metadata == body.get('metadata') + assert response.phone_number == body.get('phone_number') + assert response.postal_code == body.get('postal_code') + assert response.region == body.get('region') + assert response.swedish_identity_number == body.get('swedish_identity_number') @responses.activate def test_timeout_customers_get_retries(): fixture = helpers.load_fixture('customers')['get'] with helpers.stub_timeout_then_response(fixture) as rsps: response = helpers.client.customers.get(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['customers'] - assert_is_instance(response, resources.Customer) + assert isinstance(response, resources.Customer) def test_502_customers_get_retries(): fixture = helpers.load_fixture('customers')['get'] with helpers.stub_502_then_response(fixture) as rsps: response = helpers.client.customers.get(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['customers'] - assert_is_instance(response, resources.Customer) + assert isinstance(response, resources.Customer) @responses.activate @@ -254,49 +222,47 @@ def test_customers_update(): response = helpers.client.customers.update(*fixture['url_params']) body = fixture['body']['customers'] - assert_is_instance(response, resources.Customer) - assert_is_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal(response.address_line1, body.get('address_line1')) - assert_equal(response.address_line2, body.get('address_line2')) - assert_equal(response.address_line3, body.get('address_line3')) - assert_equal(response.city, body.get('city')) - assert_equal(response.company_name, body.get('company_name')) - assert_equal(response.country_code, body.get('country_code')) - assert_equal(response.created_at, body.get('created_at')) - assert_equal(response.danish_identity_number, body.get('danish_identity_number')) - assert_equal(response.email, body.get('email')) - assert_equal(response.family_name, body.get('family_name')) - assert_equal(response.given_name, body.get('given_name')) - assert_equal(response.id, body.get('id')) - assert_equal(response.language, body.get('language')) - assert_equal(response.metadata, body.get('metadata')) - assert_equal(response.phone_number, body.get('phone_number')) - assert_equal(response.postal_code, body.get('postal_code')) - assert_equal(response.region, body.get('region')) - assert_equal(response.swedish_identity_number, body.get('swedish_identity_number')) + assert isinstance(response, resources.Customer) + assert responses.calls[-1].request.headers.get('Idempotency-Key') is None + assert response.address_line1 == body.get('address_line1') + assert response.address_line2 == body.get('address_line2') + assert response.address_line3 == body.get('address_line3') + assert response.city == body.get('city') + assert response.company_name == body.get('company_name') + assert response.country_code == body.get('country_code') + assert response.created_at == body.get('created_at') + assert response.danish_identity_number == body.get('danish_identity_number') + assert response.email == body.get('email') + assert response.family_name == body.get('family_name') + assert response.given_name == body.get('given_name') + assert response.id == body.get('id') + assert response.language == body.get('language') + assert response.metadata == body.get('metadata') + assert response.phone_number == body.get('phone_number') + assert response.postal_code == body.get('postal_code') + assert response.region == body.get('region') + assert response.swedish_identity_number == body.get('swedish_identity_number') @responses.activate def test_timeout_customers_update_retries(): fixture = helpers.load_fixture('customers')['update'] with helpers.stub_timeout_then_response(fixture) as rsps: response = helpers.client.customers.update(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['customers'] - assert_is_instance(response, resources.Customer) + assert isinstance(response, resources.Customer) def test_502_customers_update_retries(): fixture = helpers.load_fixture('customers')['update'] with helpers.stub_502_then_response(fixture) as rsps: response = helpers.client.customers.update(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['customers'] - assert_is_instance(response, resources.Customer) + assert isinstance(response, resources.Customer) @responses.activate @@ -306,38 +272,38 @@ def test_customers_remove(): response = helpers.client.customers.remove(*fixture['url_params']) body = fixture['body']['customers'] - assert_is_instance(response, resources.Customer) - assert_is_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal(response.address_line1, body.get('address_line1')) - assert_equal(response.address_line2, body.get('address_line2')) - assert_equal(response.address_line3, body.get('address_line3')) - assert_equal(response.city, body.get('city')) - assert_equal(response.company_name, body.get('company_name')) - assert_equal(response.country_code, body.get('country_code')) - assert_equal(response.created_at, body.get('created_at')) - assert_equal(response.danish_identity_number, body.get('danish_identity_number')) - assert_equal(response.email, body.get('email')) - assert_equal(response.family_name, body.get('family_name')) - assert_equal(response.given_name, body.get('given_name')) - assert_equal(response.id, body.get('id')) - assert_equal(response.language, body.get('language')) - assert_equal(response.metadata, body.get('metadata')) - assert_equal(response.phone_number, body.get('phone_number')) - assert_equal(response.postal_code, body.get('postal_code')) - assert_equal(response.region, body.get('region')) - assert_equal(response.swedish_identity_number, body.get('swedish_identity_number')) + assert isinstance(response, resources.Customer) + assert responses.calls[-1].request.headers.get('Idempotency-Key') is None + assert response.address_line1 == body.get('address_line1') + assert response.address_line2 == body.get('address_line2') + assert response.address_line3 == body.get('address_line3') + assert response.city == body.get('city') + assert response.company_name == body.get('company_name') + assert response.country_code == body.get('country_code') + assert response.created_at == body.get('created_at') + assert response.danish_identity_number == body.get('danish_identity_number') + assert response.email == body.get('email') + assert response.family_name == body.get('family_name') + assert response.given_name == body.get('given_name') + assert response.id == body.get('id') + assert response.language == body.get('language') + assert response.metadata == body.get('metadata') + assert response.phone_number == body.get('phone_number') + assert response.postal_code == body.get('postal_code') + assert response.region == body.get('region') + assert response.swedish_identity_number == body.get('swedish_identity_number') def test_timeout_customers_remove_doesnt_retry(): fixture = helpers.load_fixture('customers')['remove'] with helpers.stub_timeout(fixture) as rsps: - with assert_raises(requests.ConnectTimeout): + with pytest.raises(requests.ConnectTimeout): response = helpers.client.customers.remove(*fixture['url_params']) - assert_equal(1, len(rsps.calls)) + assert len(rsps.calls) == 1 def test_502_customers_remove_doesnt_retry(): fixture = helpers.load_fixture('customers')['remove'] with helpers.stub_502(fixture) as rsps: - with assert_raises(MalformedResponseError): + with pytest.raises(MalformedResponseError): response = helpers.client.customers.remove(*fixture['url_params']) - assert_equal(1, len(rsps.calls)) + assert len(rsps.calls) == 1 diff --git a/tests/integration/events_integration_test.py b/tests/integration/events_integration_test.py index 95f8fd54..3e12659d 100644 --- a/tests/integration/events_integration_test.py +++ b/tests/integration/events_integration_test.py @@ -5,16 +5,9 @@ import json +import pytest import requests import responses -from nose.tools import ( - assert_equal, - assert_is_instance, - assert_is_none, - assert_is_not_none, - assert_not_equal, - assert_raises -) from gocardless_pro.errors import MalformedResponseError from gocardless_pro import resources @@ -30,57 +23,48 @@ def test_events_list(): response = helpers.client.events.list(*fixture['url_params']) body = fixture['body']['events'] - assert_is_instance(response, list_response.ListResponse) - assert_is_instance(response.records[0], resources.Event) - - assert_equal(response.before, fixture['body']['meta']['cursors']['before']) - assert_equal(response.after, fixture['body']['meta']['cursors']['after']) - assert_is_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal([r.action for r in response.records], - [b.get('action') for b in body]) - assert_equal([r.created_at for r in response.records], - [b.get('created_at') for b in body]) - assert_equal([r.customer_notifications for r in response.records], - [b.get('customer_notifications') for b in body]) - assert_equal([r.id for r in response.records], - [b.get('id') for b in body]) - assert_equal([r.metadata for r in response.records], - [b.get('metadata') for b in body]) - assert_equal([r.resource_metadata for r in response.records], - [b.get('resource_metadata') for b in body]) - assert_equal([r.resource_type for r in response.records], - [b.get('resource_type') for b in body]) + assert isinstance(response, list_response.ListResponse) + assert isinstance(response.records[0], resources.Event) + + assert response.before == fixture['body']['meta']['cursors']['before'] + assert response.after == fixture['body']['meta']['cursors']['after'] + assert responses.calls[-1].request.headers.get('Idempotency-Key') is None + assert [r.action for r in response.records] == [b.get('action') for b in body] + assert [r.created_at for r in response.records] == [b.get('created_at') for b in body] + assert [r.customer_notifications for r in response.records] == [b.get('customer_notifications') for b in body] + assert [r.id for r in response.records] == [b.get('id') for b in body] + assert [r.metadata for r in response.records] == [b.get('metadata') for b in body] + assert [r.resource_metadata for r in response.records] == [b.get('resource_metadata') for b in body] + assert [r.resource_type for r in response.records] == [b.get('resource_type') for b in body] @responses.activate def test_timeout_events_list_retries(): fixture = helpers.load_fixture('events')['list'] with helpers.stub_timeout_then_response(fixture) as rsps: response = helpers.client.events.list(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['events'] - assert_is_instance(response, list_response.ListResponse) - assert_is_instance(response.records[0], resources.Event) + assert isinstance(response, list_response.ListResponse) + assert isinstance(response.records[0], resources.Event) - assert_equal(response.before, fixture['body']['meta']['cursors']['before']) - assert_equal(response.after, fixture['body']['meta']['cursors']['after']) + assert response.before == fixture['body']['meta']['cursors']['before'] + assert response.after == fixture['body']['meta']['cursors']['after'] def test_502_events_list_retries(): fixture = helpers.load_fixture('events')['list'] with helpers.stub_502_then_response(fixture) as rsps: response = helpers.client.events.list(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['events'] - assert_is_instance(response, list_response.ListResponse) - assert_is_instance(response.records[0], resources.Event) + assert isinstance(response, list_response.ListResponse) + assert isinstance(response.records[0], resources.Event) - assert_equal(response.before, fixture['body']['meta']['cursors']['before']) - assert_equal(response.after, fixture['body']['meta']['cursors']['after']) + assert response.before == fixture['body']['meta']['cursors']['before'] + assert response.after == fixture['body']['meta']['cursors']['after'] @responses.activate def test_events_all(): @@ -97,9 +81,9 @@ def callback(request): responses.add_callback(fixture['method'], url, callback) all_records = list(helpers.client.events.all()) - assert_equal(len(all_records), len(fixture['body']['events']) * 2) + assert len(all_records) == len(fixture['body']['events']) * 2 for record in all_records: - assert_is_instance(record, resources.Event) + assert isinstance(record, resources.Event) @@ -110,98 +94,65 @@ def test_events_get(): response = helpers.client.events.get(*fixture['url_params']) body = fixture['body']['events'] - assert_is_instance(response, resources.Event) - assert_is_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal(response.action, body.get('action')) - assert_equal(response.created_at, body.get('created_at')) - assert_equal(response.customer_notifications, body.get('customer_notifications')) - assert_equal(response.id, body.get('id')) - assert_equal(response.metadata, body.get('metadata')) - assert_equal(response.resource_metadata, body.get('resource_metadata')) - assert_equal(response.resource_type, body.get('resource_type')) - assert_equal(response.details.bank_account_id, - body.get('details')['bank_account_id']) - assert_equal(response.details.cause, - body.get('details')['cause']) - assert_equal(response.details.currency, - body.get('details')['currency']) - assert_equal(response.details.description, - body.get('details')['description']) - assert_equal(response.details.not_retried_reason, - body.get('details')['not_retried_reason']) - assert_equal(response.details.origin, - body.get('details')['origin']) - assert_equal(response.details._property, - body.get('details')['property']) - assert_equal(response.details.reason_code, - body.get('details')['reason_code']) - assert_equal(response.details.scheme, - body.get('details')['scheme']) - assert_equal(response.details.will_attempt_retry, - body.get('details')['will_attempt_retry']) - assert_equal(response.links.bank_authorisation, - body.get('links')['bank_authorisation']) - assert_equal(response.links.billing_request, - body.get('links')['billing_request']) - assert_equal(response.links.billing_request_flow, - body.get('links')['billing_request_flow']) - assert_equal(response.links.creditor, - body.get('links')['creditor']) - assert_equal(response.links.customer, - body.get('links')['customer']) - assert_equal(response.links.customer_bank_account, - body.get('links')['customer_bank_account']) - assert_equal(response.links.instalment_schedule, - body.get('links')['instalment_schedule']) - assert_equal(response.links.mandate, - body.get('links')['mandate']) - assert_equal(response.links.mandate_request_mandate, - body.get('links')['mandate_request_mandate']) - assert_equal(response.links.new_customer_bank_account, - body.get('links')['new_customer_bank_account']) - assert_equal(response.links.new_mandate, - body.get('links')['new_mandate']) - assert_equal(response.links.organisation, - body.get('links')['organisation']) - assert_equal(response.links.parent_event, - body.get('links')['parent_event']) - assert_equal(response.links.payer_authorisation, - body.get('links')['payer_authorisation']) - assert_equal(response.links.payment, - body.get('links')['payment']) - assert_equal(response.links.payment_request_payment, - body.get('links')['payment_request_payment']) - assert_equal(response.links.payout, - body.get('links')['payout']) - assert_equal(response.links.previous_customer_bank_account, - body.get('links')['previous_customer_bank_account']) - assert_equal(response.links.refund, - body.get('links')['refund']) - assert_equal(response.links.scheme_identifier, - body.get('links')['scheme_identifier']) - assert_equal(response.links.subscription, - body.get('links')['subscription']) + assert isinstance(response, resources.Event) + assert responses.calls[-1].request.headers.get('Idempotency-Key') is None + assert response.action == body.get('action') + assert response.created_at == body.get('created_at') + assert response.customer_notifications == body.get('customer_notifications') + assert response.id == body.get('id') + assert response.metadata == body.get('metadata') + assert response.resource_metadata == body.get('resource_metadata') + assert response.resource_type == body.get('resource_type') + assert response.details.bank_account_id == body.get('details')['bank_account_id'] + assert response.details.cause == body.get('details')['cause'] + assert response.details.currency == body.get('details')['currency'] + assert response.details.description == body.get('details')['description'] + assert response.details.not_retried_reason == body.get('details')['not_retried_reason'] + assert response.details.origin == body.get('details')['origin'] + assert response.details._property == body.get('details')['property'] + assert response.details.reason_code == body.get('details')['reason_code'] + assert response.details.scheme == body.get('details')['scheme'] + assert response.details.will_attempt_retry == body.get('details')['will_attempt_retry'] + assert response.links.bank_authorisation == body.get('links')['bank_authorisation'] + assert response.links.billing_request == body.get('links')['billing_request'] + assert response.links.billing_request_flow == body.get('links')['billing_request_flow'] + assert response.links.creditor == body.get('links')['creditor'] + assert response.links.customer == body.get('links')['customer'] + assert response.links.customer_bank_account == body.get('links')['customer_bank_account'] + assert response.links.instalment_schedule == body.get('links')['instalment_schedule'] + assert response.links.mandate == body.get('links')['mandate'] + assert response.links.mandate_request_mandate == body.get('links')['mandate_request_mandate'] + assert response.links.new_customer_bank_account == body.get('links')['new_customer_bank_account'] + assert response.links.new_mandate == body.get('links')['new_mandate'] + assert response.links.organisation == body.get('links')['organisation'] + assert response.links.parent_event == body.get('links')['parent_event'] + assert response.links.payer_authorisation == body.get('links')['payer_authorisation'] + assert response.links.payment == body.get('links')['payment'] + assert response.links.payment_request_payment == body.get('links')['payment_request_payment'] + assert response.links.payout == body.get('links')['payout'] + assert response.links.previous_customer_bank_account == body.get('links')['previous_customer_bank_account'] + assert response.links.refund == body.get('links')['refund'] + assert response.links.scheme_identifier == body.get('links')['scheme_identifier'] + assert response.links.subscription == body.get('links')['subscription'] @responses.activate def test_timeout_events_get_retries(): fixture = helpers.load_fixture('events')['get'] with helpers.stub_timeout_then_response(fixture) as rsps: response = helpers.client.events.get(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['events'] - assert_is_instance(response, resources.Event) + assert isinstance(response, resources.Event) def test_502_events_get_retries(): fixture = helpers.load_fixture('events')['get'] with helpers.stub_502_then_response(fixture) as rsps: response = helpers.client.events.get(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['events'] - assert_is_instance(response, resources.Event) + assert isinstance(response, resources.Event) diff --git a/tests/integration/instalment_schedules_integration_test.py b/tests/integration/instalment_schedules_integration_test.py index b854ac5b..485c786a 100644 --- a/tests/integration/instalment_schedules_integration_test.py +++ b/tests/integration/instalment_schedules_integration_test.py @@ -5,16 +5,9 @@ import json +import pytest import requests import responses -from nose.tools import ( - assert_equal, - assert_is_instance, - assert_is_none, - assert_is_not_none, - assert_not_equal, - assert_raises -) from gocardless_pro.errors import MalformedResponseError from gocardless_pro import resources @@ -30,22 +23,19 @@ def test_instalment_schedules_create_with_dates(): response = helpers.client.instalment_schedules.create_with_dates(*fixture['url_params']) body = fixture['body']['instalment_schedules'] - assert_is_instance(response, resources.InstalmentSchedule) - assert_is_not_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal(response.created_at, body.get('created_at')) - assert_equal(response.currency, body.get('currency')) - assert_equal(response.id, body.get('id')) - assert_equal(response.metadata, body.get('metadata')) - assert_equal(response.name, body.get('name')) - assert_equal(response.payment_errors, body.get('payment_errors')) - assert_equal(response.status, body.get('status')) - assert_equal(response.total_amount, body.get('total_amount')) - assert_equal(response.links.customer, - body.get('links')['customer']) - assert_equal(response.links.mandate, - body.get('links')['mandate']) - assert_equal(response.links.payments, - body.get('links')['payments']) + assert isinstance(response, resources.InstalmentSchedule) + assert responses.calls[-1].request.headers.get('Idempotency-Key') is not None + assert response.created_at == body.get('created_at') + assert response.currency == body.get('currency') + assert response.id == body.get('id') + assert response.metadata == body.get('metadata') + assert response.name == body.get('name') + assert response.payment_errors == body.get('payment_errors') + assert response.status == body.get('status') + assert response.total_amount == body.get('total_amount') + assert response.links.customer == body.get('links')['customer'] + assert response.links.mandate == body.get('links')['mandate'] + assert response.links.payments == body.get('links')['payments'] @responses.activate def test_instalment_schedules_create_with_dates_new_idempotency_key_for_each_call(): @@ -53,40 +43,37 @@ def test_instalment_schedules_create_with_dates_new_idempotency_key_for_each_cal helpers.stub_response(fixture) helpers.client.instalment_schedules.create_with_dates(*fixture['url_params']) helpers.client.instalment_schedules.create_with_dates(*fixture['url_params']) - assert_not_equal(responses.calls[0].request.headers.get('Idempotency-Key'), - responses.calls[1].request.headers.get('Idempotency-Key')) + assert responses.calls[0].request.headers.get('Idempotency-Key') != responses.calls[1].request.headers.get('Idempotency-Key') def test_timeout_instalment_schedules_create_with_dates_idempotency_conflict(): create_fixture = helpers.load_fixture('instalment_schedules')['create_with_dates'] get_fixture = helpers.load_fixture('instalment_schedules')['get'] with helpers.stub_timeout_then_idempotency_conflict(create_fixture, get_fixture) as rsps: response = helpers.client.instalment_schedules.create_with_dates(*create_fixture['url_params']) - assert_equal(2, len(rsps.calls)) + assert len(rsps.calls) == 2 - assert_is_instance(response, resources.InstalmentSchedule) + assert isinstance(response, resources.InstalmentSchedule) @responses.activate def test_timeout_instalment_schedules_create_with_dates_retries(): fixture = helpers.load_fixture('instalment_schedules')['create_with_dates'] with helpers.stub_timeout_then_response(fixture) as rsps: response = helpers.client.instalment_schedules.create_with_dates(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['instalment_schedules'] - assert_is_instance(response, resources.InstalmentSchedule) + assert isinstance(response, resources.InstalmentSchedule) def test_502_instalment_schedules_create_with_dates_retries(): fixture = helpers.load_fixture('instalment_schedules')['create_with_dates'] with helpers.stub_502_then_response(fixture) as rsps: response = helpers.client.instalment_schedules.create_with_dates(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['instalment_schedules'] - assert_is_instance(response, resources.InstalmentSchedule) + assert isinstance(response, resources.InstalmentSchedule) @responses.activate @@ -96,22 +83,19 @@ def test_instalment_schedules_create_with_schedule(): response = helpers.client.instalment_schedules.create_with_schedule(*fixture['url_params']) body = fixture['body']['instalment_schedules'] - assert_is_instance(response, resources.InstalmentSchedule) - assert_is_not_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal(response.created_at, body.get('created_at')) - assert_equal(response.currency, body.get('currency')) - assert_equal(response.id, body.get('id')) - assert_equal(response.metadata, body.get('metadata')) - assert_equal(response.name, body.get('name')) - assert_equal(response.payment_errors, body.get('payment_errors')) - assert_equal(response.status, body.get('status')) - assert_equal(response.total_amount, body.get('total_amount')) - assert_equal(response.links.customer, - body.get('links')['customer']) - assert_equal(response.links.mandate, - body.get('links')['mandate']) - assert_equal(response.links.payments, - body.get('links')['payments']) + assert isinstance(response, resources.InstalmentSchedule) + assert responses.calls[-1].request.headers.get('Idempotency-Key') is not None + assert response.created_at == body.get('created_at') + assert response.currency == body.get('currency') + assert response.id == body.get('id') + assert response.metadata == body.get('metadata') + assert response.name == body.get('name') + assert response.payment_errors == body.get('payment_errors') + assert response.status == body.get('status') + assert response.total_amount == body.get('total_amount') + assert response.links.customer == body.get('links')['customer'] + assert response.links.mandate == body.get('links')['mandate'] + assert response.links.payments == body.get('links')['payments'] @responses.activate def test_instalment_schedules_create_with_schedule_new_idempotency_key_for_each_call(): @@ -119,40 +103,37 @@ def test_instalment_schedules_create_with_schedule_new_idempotency_key_for_each_ helpers.stub_response(fixture) helpers.client.instalment_schedules.create_with_schedule(*fixture['url_params']) helpers.client.instalment_schedules.create_with_schedule(*fixture['url_params']) - assert_not_equal(responses.calls[0].request.headers.get('Idempotency-Key'), - responses.calls[1].request.headers.get('Idempotency-Key')) + assert responses.calls[0].request.headers.get('Idempotency-Key') != responses.calls[1].request.headers.get('Idempotency-Key') def test_timeout_instalment_schedules_create_with_schedule_idempotency_conflict(): create_fixture = helpers.load_fixture('instalment_schedules')['create_with_schedule'] get_fixture = helpers.load_fixture('instalment_schedules')['get'] with helpers.stub_timeout_then_idempotency_conflict(create_fixture, get_fixture) as rsps: response = helpers.client.instalment_schedules.create_with_schedule(*create_fixture['url_params']) - assert_equal(2, len(rsps.calls)) + assert len(rsps.calls) == 2 - assert_is_instance(response, resources.InstalmentSchedule) + assert isinstance(response, resources.InstalmentSchedule) @responses.activate def test_timeout_instalment_schedules_create_with_schedule_retries(): fixture = helpers.load_fixture('instalment_schedules')['create_with_schedule'] with helpers.stub_timeout_then_response(fixture) as rsps: response = helpers.client.instalment_schedules.create_with_schedule(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['instalment_schedules'] - assert_is_instance(response, resources.InstalmentSchedule) + assert isinstance(response, resources.InstalmentSchedule) def test_502_instalment_schedules_create_with_schedule_retries(): fixture = helpers.load_fixture('instalment_schedules')['create_with_schedule'] with helpers.stub_502_then_response(fixture) as rsps: response = helpers.client.instalment_schedules.create_with_schedule(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['instalment_schedules'] - assert_is_instance(response, resources.InstalmentSchedule) + assert isinstance(response, resources.InstalmentSchedule) @responses.activate @@ -162,59 +143,49 @@ def test_instalment_schedules_list(): response = helpers.client.instalment_schedules.list(*fixture['url_params']) body = fixture['body']['instalment_schedules'] - assert_is_instance(response, list_response.ListResponse) - assert_is_instance(response.records[0], resources.InstalmentSchedule) - - assert_equal(response.before, fixture['body']['meta']['cursors']['before']) - assert_equal(response.after, fixture['body']['meta']['cursors']['after']) - assert_is_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal([r.created_at for r in response.records], - [b.get('created_at') for b in body]) - assert_equal([r.currency for r in response.records], - [b.get('currency') for b in body]) - assert_equal([r.id for r in response.records], - [b.get('id') for b in body]) - assert_equal([r.metadata for r in response.records], - [b.get('metadata') for b in body]) - assert_equal([r.name for r in response.records], - [b.get('name') for b in body]) - assert_equal([r.payment_errors for r in response.records], - [b.get('payment_errors') for b in body]) - assert_equal([r.status for r in response.records], - [b.get('status') for b in body]) - assert_equal([r.total_amount for r in response.records], - [b.get('total_amount') for b in body]) + assert isinstance(response, list_response.ListResponse) + assert isinstance(response.records[0], resources.InstalmentSchedule) + + assert response.before == fixture['body']['meta']['cursors']['before'] + assert response.after == fixture['body']['meta']['cursors']['after'] + assert responses.calls[-1].request.headers.get('Idempotency-Key') is None + assert [r.created_at for r in response.records] == [b.get('created_at') for b in body] + assert [r.currency for r in response.records] == [b.get('currency') for b in body] + assert [r.id for r in response.records] == [b.get('id') for b in body] + assert [r.metadata for r in response.records] == [b.get('metadata') for b in body] + assert [r.name for r in response.records] == [b.get('name') for b in body] + assert [r.payment_errors for r in response.records] == [b.get('payment_errors') for b in body] + assert [r.status for r in response.records] == [b.get('status') for b in body] + assert [r.total_amount for r in response.records] == [b.get('total_amount') for b in body] @responses.activate def test_timeout_instalment_schedules_list_retries(): fixture = helpers.load_fixture('instalment_schedules')['list'] with helpers.stub_timeout_then_response(fixture) as rsps: response = helpers.client.instalment_schedules.list(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['instalment_schedules'] - assert_is_instance(response, list_response.ListResponse) - assert_is_instance(response.records[0], resources.InstalmentSchedule) + assert isinstance(response, list_response.ListResponse) + assert isinstance(response.records[0], resources.InstalmentSchedule) - assert_equal(response.before, fixture['body']['meta']['cursors']['before']) - assert_equal(response.after, fixture['body']['meta']['cursors']['after']) + assert response.before == fixture['body']['meta']['cursors']['before'] + assert response.after == fixture['body']['meta']['cursors']['after'] def test_502_instalment_schedules_list_retries(): fixture = helpers.load_fixture('instalment_schedules')['list'] with helpers.stub_502_then_response(fixture) as rsps: response = helpers.client.instalment_schedules.list(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['instalment_schedules'] - assert_is_instance(response, list_response.ListResponse) - assert_is_instance(response.records[0], resources.InstalmentSchedule) + assert isinstance(response, list_response.ListResponse) + assert isinstance(response.records[0], resources.InstalmentSchedule) - assert_equal(response.before, fixture['body']['meta']['cursors']['before']) - assert_equal(response.after, fixture['body']['meta']['cursors']['after']) + assert response.before == fixture['body']['meta']['cursors']['before'] + assert response.after == fixture['body']['meta']['cursors']['after'] @responses.activate def test_instalment_schedules_all(): @@ -231,9 +202,9 @@ def callback(request): responses.add_callback(fixture['method'], url, callback) all_records = list(helpers.client.instalment_schedules.all()) - assert_equal(len(all_records), len(fixture['body']['instalment_schedules']) * 2) + assert len(all_records) == len(fixture['body']['instalment_schedules']) * 2 for record in all_records: - assert_is_instance(record, resources.InstalmentSchedule) + assert isinstance(record, resources.InstalmentSchedule) @@ -244,45 +215,40 @@ def test_instalment_schedules_get(): response = helpers.client.instalment_schedules.get(*fixture['url_params']) body = fixture['body']['instalment_schedules'] - assert_is_instance(response, resources.InstalmentSchedule) - assert_is_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal(response.created_at, body.get('created_at')) - assert_equal(response.currency, body.get('currency')) - assert_equal(response.id, body.get('id')) - assert_equal(response.metadata, body.get('metadata')) - assert_equal(response.name, body.get('name')) - assert_equal(response.payment_errors, body.get('payment_errors')) - assert_equal(response.status, body.get('status')) - assert_equal(response.total_amount, body.get('total_amount')) - assert_equal(response.links.customer, - body.get('links')['customer']) - assert_equal(response.links.mandate, - body.get('links')['mandate']) - assert_equal(response.links.payments, - body.get('links')['payments']) + assert isinstance(response, resources.InstalmentSchedule) + assert responses.calls[-1].request.headers.get('Idempotency-Key') is None + assert response.created_at == body.get('created_at') + assert response.currency == body.get('currency') + assert response.id == body.get('id') + assert response.metadata == body.get('metadata') + assert response.name == body.get('name') + assert response.payment_errors == body.get('payment_errors') + assert response.status == body.get('status') + assert response.total_amount == body.get('total_amount') + assert response.links.customer == body.get('links')['customer'] + assert response.links.mandate == body.get('links')['mandate'] + assert response.links.payments == body.get('links')['payments'] @responses.activate def test_timeout_instalment_schedules_get_retries(): fixture = helpers.load_fixture('instalment_schedules')['get'] with helpers.stub_timeout_then_response(fixture) as rsps: response = helpers.client.instalment_schedules.get(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['instalment_schedules'] - assert_is_instance(response, resources.InstalmentSchedule) + assert isinstance(response, resources.InstalmentSchedule) def test_502_instalment_schedules_get_retries(): fixture = helpers.load_fixture('instalment_schedules')['get'] with helpers.stub_502_then_response(fixture) as rsps: response = helpers.client.instalment_schedules.get(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['instalment_schedules'] - assert_is_instance(response, resources.InstalmentSchedule) + assert isinstance(response, resources.InstalmentSchedule) @responses.activate @@ -292,45 +258,40 @@ def test_instalment_schedules_update(): response = helpers.client.instalment_schedules.update(*fixture['url_params']) body = fixture['body']['instalment_schedules'] - assert_is_instance(response, resources.InstalmentSchedule) - assert_is_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal(response.created_at, body.get('created_at')) - assert_equal(response.currency, body.get('currency')) - assert_equal(response.id, body.get('id')) - assert_equal(response.metadata, body.get('metadata')) - assert_equal(response.name, body.get('name')) - assert_equal(response.payment_errors, body.get('payment_errors')) - assert_equal(response.status, body.get('status')) - assert_equal(response.total_amount, body.get('total_amount')) - assert_equal(response.links.customer, - body.get('links')['customer']) - assert_equal(response.links.mandate, - body.get('links')['mandate']) - assert_equal(response.links.payments, - body.get('links')['payments']) + assert isinstance(response, resources.InstalmentSchedule) + assert responses.calls[-1].request.headers.get('Idempotency-Key') is None + assert response.created_at == body.get('created_at') + assert response.currency == body.get('currency') + assert response.id == body.get('id') + assert response.metadata == body.get('metadata') + assert response.name == body.get('name') + assert response.payment_errors == body.get('payment_errors') + assert response.status == body.get('status') + assert response.total_amount == body.get('total_amount') + assert response.links.customer == body.get('links')['customer'] + assert response.links.mandate == body.get('links')['mandate'] + assert response.links.payments == body.get('links')['payments'] @responses.activate def test_timeout_instalment_schedules_update_retries(): fixture = helpers.load_fixture('instalment_schedules')['update'] with helpers.stub_timeout_then_response(fixture) as rsps: response = helpers.client.instalment_schedules.update(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['instalment_schedules'] - assert_is_instance(response, resources.InstalmentSchedule) + assert isinstance(response, resources.InstalmentSchedule) def test_502_instalment_schedules_update_retries(): fixture = helpers.load_fixture('instalment_schedules')['update'] with helpers.stub_502_then_response(fixture) as rsps: response = helpers.client.instalment_schedules.update(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['instalment_schedules'] - assert_is_instance(response, resources.InstalmentSchedule) + assert isinstance(response, resources.InstalmentSchedule) @responses.activate @@ -340,34 +301,31 @@ def test_instalment_schedules_cancel(): response = helpers.client.instalment_schedules.cancel(*fixture['url_params']) body = fixture['body']['instalment_schedules'] - assert_is_instance(response, resources.InstalmentSchedule) - assert_is_not_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal(response.created_at, body.get('created_at')) - assert_equal(response.currency, body.get('currency')) - assert_equal(response.id, body.get('id')) - assert_equal(response.metadata, body.get('metadata')) - assert_equal(response.name, body.get('name')) - assert_equal(response.payment_errors, body.get('payment_errors')) - assert_equal(response.status, body.get('status')) - assert_equal(response.total_amount, body.get('total_amount')) - assert_equal(response.links.customer, - body.get('links')['customer']) - assert_equal(response.links.mandate, - body.get('links')['mandate']) - assert_equal(response.links.payments, - body.get('links')['payments']) + assert isinstance(response, resources.InstalmentSchedule) + assert responses.calls[-1].request.headers.get('Idempotency-Key') is not None + assert response.created_at == body.get('created_at') + assert response.currency == body.get('currency') + assert response.id == body.get('id') + assert response.metadata == body.get('metadata') + assert response.name == body.get('name') + assert response.payment_errors == body.get('payment_errors') + assert response.status == body.get('status') + assert response.total_amount == body.get('total_amount') + assert response.links.customer == body.get('links')['customer'] + assert response.links.mandate == body.get('links')['mandate'] + assert response.links.payments == body.get('links')['payments'] def test_timeout_instalment_schedules_cancel_doesnt_retry(): fixture = helpers.load_fixture('instalment_schedules')['cancel'] with helpers.stub_timeout(fixture) as rsps: - with assert_raises(requests.ConnectTimeout): + with pytest.raises(requests.ConnectTimeout): response = helpers.client.instalment_schedules.cancel(*fixture['url_params']) - assert_equal(1, len(rsps.calls)) + assert len(rsps.calls) == 1 def test_502_instalment_schedules_cancel_doesnt_retry(): fixture = helpers.load_fixture('instalment_schedules')['cancel'] with helpers.stub_502(fixture) as rsps: - with assert_raises(MalformedResponseError): + with pytest.raises(MalformedResponseError): response = helpers.client.instalment_schedules.cancel(*fixture['url_params']) - assert_equal(1, len(rsps.calls)) + assert len(rsps.calls) == 1 diff --git a/tests/integration/institutions_integration_test.py b/tests/integration/institutions_integration_test.py index d435214a..162857ef 100644 --- a/tests/integration/institutions_integration_test.py +++ b/tests/integration/institutions_integration_test.py @@ -5,16 +5,9 @@ import json +import pytest import requests import responses -from nose.tools import ( - assert_equal, - assert_is_instance, - assert_is_none, - assert_is_not_none, - assert_not_equal, - assert_raises -) from gocardless_pro.errors import MalformedResponseError from gocardless_pro import resources @@ -30,55 +23,47 @@ def test_institutions_list(): response = helpers.client.institutions.list(*fixture['url_params']) body = fixture['body']['institutions'] - assert_is_instance(response, list_response.ListResponse) - assert_is_instance(response.records[0], resources.Institution) - - assert_equal(response.before, fixture['body']['meta']['cursors']['before']) - assert_equal(response.after, fixture['body']['meta']['cursors']['after']) - assert_is_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal([r.autocompletes_collect_bank_account for r in response.records], - [b.get('autocompletes_collect_bank_account') for b in body]) - assert_equal([r.country_code for r in response.records], - [b.get('country_code') for b in body]) - assert_equal([r.icon_url for r in response.records], - [b.get('icon_url') for b in body]) - assert_equal([r.id for r in response.records], - [b.get('id') for b in body]) - assert_equal([r.logo_url for r in response.records], - [b.get('logo_url') for b in body]) - assert_equal([r.name for r in response.records], - [b.get('name') for b in body]) + assert isinstance(response, list_response.ListResponse) + assert isinstance(response.records[0], resources.Institution) + + assert response.before == fixture['body']['meta']['cursors']['before'] + assert response.after == fixture['body']['meta']['cursors']['after'] + assert responses.calls[-1].request.headers.get('Idempotency-Key') is None + assert [r.autocompletes_collect_bank_account for r in response.records] == [b.get('autocompletes_collect_bank_account') for b in body] + assert [r.country_code for r in response.records] == [b.get('country_code') for b in body] + assert [r.icon_url for r in response.records] == [b.get('icon_url') for b in body] + assert [r.id for r in response.records] == [b.get('id') for b in body] + assert [r.logo_url for r in response.records] == [b.get('logo_url') for b in body] + assert [r.name for r in response.records] == [b.get('name') for b in body] @responses.activate def test_timeout_institutions_list_retries(): fixture = helpers.load_fixture('institutions')['list'] with helpers.stub_timeout_then_response(fixture) as rsps: response = helpers.client.institutions.list(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['institutions'] - assert_is_instance(response, list_response.ListResponse) - assert_is_instance(response.records[0], resources.Institution) + assert isinstance(response, list_response.ListResponse) + assert isinstance(response.records[0], resources.Institution) - assert_equal(response.before, fixture['body']['meta']['cursors']['before']) - assert_equal(response.after, fixture['body']['meta']['cursors']['after']) + assert response.before == fixture['body']['meta']['cursors']['before'] + assert response.after == fixture['body']['meta']['cursors']['after'] def test_502_institutions_list_retries(): fixture = helpers.load_fixture('institutions')['list'] with helpers.stub_502_then_response(fixture) as rsps: response = helpers.client.institutions.list(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['institutions'] - assert_is_instance(response, list_response.ListResponse) - assert_is_instance(response.records[0], resources.Institution) + assert isinstance(response, list_response.ListResponse) + assert isinstance(response.records[0], resources.Institution) - assert_equal(response.before, fixture['body']['meta']['cursors']['before']) - assert_equal(response.after, fixture['body']['meta']['cursors']['after']) + assert response.before == fixture['body']['meta']['cursors']['before'] + assert response.after == fixture['body']['meta']['cursors']['after'] @responses.activate def test_institutions_all(): @@ -95,9 +80,9 @@ def callback(request): responses.add_callback(fixture['method'], url, callback) all_records = list(helpers.client.institutions.all()) - assert_equal(len(all_records), len(fixture['body']['institutions']) * 2) + assert len(all_records) == len(fixture['body']['institutions']) * 2 for record in all_records: - assert_is_instance(record, resources.Institution) + assert isinstance(record, resources.Institution) @@ -108,36 +93,30 @@ def test_institutions_list_for_billing_request(): response = helpers.client.institutions.list_for_billing_request(*fixture['url_params']) body = fixture['body']['institutions'] - assert_is_instance(response, list_response.ListResponse) - assert_is_instance(response.records[0], resources.Institution) - - assert_equal(response.before, fixture['body']['meta']['cursors']['before']) - assert_equal(response.after, fixture['body']['meta']['cursors']['after']) - assert_is_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal([r.autocompletes_collect_bank_account for r in response.records], - [b.get('autocompletes_collect_bank_account') for b in body]) - assert_equal([r.country_code for r in response.records], - [b.get('country_code') for b in body]) - assert_equal([r.icon_url for r in response.records], - [b.get('icon_url') for b in body]) - assert_equal([r.id for r in response.records], - [b.get('id') for b in body]) - assert_equal([r.logo_url for r in response.records], - [b.get('logo_url') for b in body]) - assert_equal([r.name for r in response.records], - [b.get('name') for b in body]) + assert isinstance(response, list_response.ListResponse) + assert isinstance(response.records[0], resources.Institution) + + assert response.before == fixture['body']['meta']['cursors']['before'] + assert response.after == fixture['body']['meta']['cursors']['after'] + assert responses.calls[-1].request.headers.get('Idempotency-Key') is None + assert [r.autocompletes_collect_bank_account for r in response.records] == [b.get('autocompletes_collect_bank_account') for b in body] + assert [r.country_code for r in response.records] == [b.get('country_code') for b in body] + assert [r.icon_url for r in response.records] == [b.get('icon_url') for b in body] + assert [r.id for r in response.records] == [b.get('id') for b in body] + assert [r.logo_url for r in response.records] == [b.get('logo_url') for b in body] + assert [r.name for r in response.records] == [b.get('name') for b in body] def test_timeout_institutions_list_for_billing_request_doesnt_retry(): fixture = helpers.load_fixture('institutions')['list_for_billing_request'] with helpers.stub_timeout(fixture) as rsps: - with assert_raises(requests.ConnectTimeout): + with pytest.raises(requests.ConnectTimeout): response = helpers.client.institutions.list_for_billing_request(*fixture['url_params']) - assert_equal(1, len(rsps.calls)) + assert len(rsps.calls) == 1 def test_502_institutions_list_for_billing_request_doesnt_retry(): fixture = helpers.load_fixture('institutions')['list_for_billing_request'] with helpers.stub_502(fixture) as rsps: - with assert_raises(MalformedResponseError): + with pytest.raises(MalformedResponseError): response = helpers.client.institutions.list_for_billing_request(*fixture['url_params']) - assert_equal(1, len(rsps.calls)) + assert len(rsps.calls) == 1 diff --git a/tests/integration/mandate_import_entries_integration_test.py b/tests/integration/mandate_import_entries_integration_test.py index 376bd90c..c9fed4b3 100644 --- a/tests/integration/mandate_import_entries_integration_test.py +++ b/tests/integration/mandate_import_entries_integration_test.py @@ -5,16 +5,9 @@ import json +import pytest import requests import responses -from nose.tools import ( - assert_equal, - assert_is_instance, - assert_is_none, - assert_is_not_none, - assert_not_equal, - assert_raises -) from gocardless_pro.errors import MalformedResponseError from gocardless_pro import resources @@ -30,41 +23,35 @@ def test_mandate_import_entries_create(): response = helpers.client.mandate_import_entries.create(*fixture['url_params']) body = fixture['body']['mandate_import_entries'] - assert_is_instance(response, resources.MandateImportEntry) - assert_is_not_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal(response.created_at, body.get('created_at')) - assert_equal(response.record_identifier, body.get('record_identifier')) - assert_equal(response.links.customer, - body.get('links')['customer']) - assert_equal(response.links.customer_bank_account, - body.get('links')['customer_bank_account']) - assert_equal(response.links.mandate, - body.get('links')['mandate']) - assert_equal(response.links.mandate_import, - body.get('links')['mandate_import']) + assert isinstance(response, resources.MandateImportEntry) + assert responses.calls[-1].request.headers.get('Idempotency-Key') is not None + assert response.created_at == body.get('created_at') + assert response.record_identifier == body.get('record_identifier') + assert response.links.customer == body.get('links')['customer'] + assert response.links.customer_bank_account == body.get('links')['customer_bank_account'] + assert response.links.mandate == body.get('links')['mandate'] + assert response.links.mandate_import == body.get('links')['mandate_import'] @responses.activate def test_timeout_mandate_import_entries_create_retries(): fixture = helpers.load_fixture('mandate_import_entries')['create'] with helpers.stub_timeout_then_response(fixture) as rsps: response = helpers.client.mandate_import_entries.create(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['mandate_import_entries'] - assert_is_instance(response, resources.MandateImportEntry) + assert isinstance(response, resources.MandateImportEntry) def test_502_mandate_import_entries_create_retries(): fixture = helpers.load_fixture('mandate_import_entries')['create'] with helpers.stub_502_then_response(fixture) as rsps: response = helpers.client.mandate_import_entries.create(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['mandate_import_entries'] - assert_is_instance(response, resources.MandateImportEntry) + assert isinstance(response, resources.MandateImportEntry) @responses.activate @@ -74,47 +61,43 @@ def test_mandate_import_entries_list(): response = helpers.client.mandate_import_entries.list(*fixture['url_params']) body = fixture['body']['mandate_import_entries'] - assert_is_instance(response, list_response.ListResponse) - assert_is_instance(response.records[0], resources.MandateImportEntry) + assert isinstance(response, list_response.ListResponse) + assert isinstance(response.records[0], resources.MandateImportEntry) - assert_equal(response.before, fixture['body']['meta']['cursors']['before']) - assert_equal(response.after, fixture['body']['meta']['cursors']['after']) - assert_is_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal([r.created_at for r in response.records], - [b.get('created_at') for b in body]) - assert_equal([r.record_identifier for r in response.records], - [b.get('record_identifier') for b in body]) + assert response.before == fixture['body']['meta']['cursors']['before'] + assert response.after == fixture['body']['meta']['cursors']['after'] + assert responses.calls[-1].request.headers.get('Idempotency-Key') is None + assert [r.created_at for r in response.records] == [b.get('created_at') for b in body] + assert [r.record_identifier for r in response.records] == [b.get('record_identifier') for b in body] @responses.activate def test_timeout_mandate_import_entries_list_retries(): fixture = helpers.load_fixture('mandate_import_entries')['list'] with helpers.stub_timeout_then_response(fixture) as rsps: response = helpers.client.mandate_import_entries.list(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['mandate_import_entries'] - assert_is_instance(response, list_response.ListResponse) - assert_is_instance(response.records[0], resources.MandateImportEntry) + assert isinstance(response, list_response.ListResponse) + assert isinstance(response.records[0], resources.MandateImportEntry) - assert_equal(response.before, fixture['body']['meta']['cursors']['before']) - assert_equal(response.after, fixture['body']['meta']['cursors']['after']) + assert response.before == fixture['body']['meta']['cursors']['before'] + assert response.after == fixture['body']['meta']['cursors']['after'] def test_502_mandate_import_entries_list_retries(): fixture = helpers.load_fixture('mandate_import_entries')['list'] with helpers.stub_502_then_response(fixture) as rsps: response = helpers.client.mandate_import_entries.list(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['mandate_import_entries'] - assert_is_instance(response, list_response.ListResponse) - assert_is_instance(response.records[0], resources.MandateImportEntry) + assert isinstance(response, list_response.ListResponse) + assert isinstance(response.records[0], resources.MandateImportEntry) - assert_equal(response.before, fixture['body']['meta']['cursors']['before']) - assert_equal(response.after, fixture['body']['meta']['cursors']['after']) + assert response.before == fixture['body']['meta']['cursors']['before'] + assert response.after == fixture['body']['meta']['cursors']['after'] @responses.activate def test_mandate_import_entries_all(): @@ -131,8 +114,8 @@ def callback(request): responses.add_callback(fixture['method'], url, callback) all_records = list(helpers.client.mandate_import_entries.all()) - assert_equal(len(all_records), len(fixture['body']['mandate_import_entries']) * 2) + assert len(all_records) == len(fixture['body']['mandate_import_entries']) * 2 for record in all_records: - assert_is_instance(record, resources.MandateImportEntry) + assert isinstance(record, resources.MandateImportEntry) diff --git a/tests/integration/mandate_imports_integration_test.py b/tests/integration/mandate_imports_integration_test.py index 64f01717..d88608cb 100644 --- a/tests/integration/mandate_imports_integration_test.py +++ b/tests/integration/mandate_imports_integration_test.py @@ -5,16 +5,9 @@ import json +import pytest import requests import responses -from nose.tools import ( - assert_equal, - assert_is_instance, - assert_is_none, - assert_is_not_none, - assert_not_equal, - assert_raises -) from gocardless_pro.errors import MalformedResponseError from gocardless_pro import resources @@ -30,14 +23,13 @@ def test_mandate_imports_create(): response = helpers.client.mandate_imports.create(*fixture['url_params']) body = fixture['body']['mandate_imports'] - assert_is_instance(response, resources.MandateImport) - assert_is_not_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal(response.created_at, body.get('created_at')) - assert_equal(response.id, body.get('id')) - assert_equal(response.scheme, body.get('scheme')) - assert_equal(response.status, body.get('status')) - assert_equal(response.links.creditor, - body.get('links')['creditor']) + assert isinstance(response, resources.MandateImport) + assert responses.calls[-1].request.headers.get('Idempotency-Key') is not None + assert response.created_at == body.get('created_at') + assert response.id == body.get('id') + assert response.scheme == body.get('scheme') + assert response.status == body.get('status') + assert response.links.creditor == body.get('links')['creditor'] @responses.activate def test_mandate_imports_create_new_idempotency_key_for_each_call(): @@ -45,40 +37,37 @@ def test_mandate_imports_create_new_idempotency_key_for_each_call(): helpers.stub_response(fixture) helpers.client.mandate_imports.create(*fixture['url_params']) helpers.client.mandate_imports.create(*fixture['url_params']) - assert_not_equal(responses.calls[0].request.headers.get('Idempotency-Key'), - responses.calls[1].request.headers.get('Idempotency-Key')) + assert responses.calls[0].request.headers.get('Idempotency-Key') != responses.calls[1].request.headers.get('Idempotency-Key') def test_timeout_mandate_imports_create_idempotency_conflict(): create_fixture = helpers.load_fixture('mandate_imports')['create'] get_fixture = helpers.load_fixture('mandate_imports')['get'] with helpers.stub_timeout_then_idempotency_conflict(create_fixture, get_fixture) as rsps: response = helpers.client.mandate_imports.create(*create_fixture['url_params']) - assert_equal(2, len(rsps.calls)) + assert len(rsps.calls) == 2 - assert_is_instance(response, resources.MandateImport) + assert isinstance(response, resources.MandateImport) @responses.activate def test_timeout_mandate_imports_create_retries(): fixture = helpers.load_fixture('mandate_imports')['create'] with helpers.stub_timeout_then_response(fixture) as rsps: response = helpers.client.mandate_imports.create(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['mandate_imports'] - assert_is_instance(response, resources.MandateImport) + assert isinstance(response, resources.MandateImport) def test_502_mandate_imports_create_retries(): fixture = helpers.load_fixture('mandate_imports')['create'] with helpers.stub_502_then_response(fixture) as rsps: response = helpers.client.mandate_imports.create(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['mandate_imports'] - assert_is_instance(response, resources.MandateImport) + assert isinstance(response, resources.MandateImport) @responses.activate @@ -88,37 +77,34 @@ def test_mandate_imports_get(): response = helpers.client.mandate_imports.get(*fixture['url_params']) body = fixture['body']['mandate_imports'] - assert_is_instance(response, resources.MandateImport) - assert_is_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal(response.created_at, body.get('created_at')) - assert_equal(response.id, body.get('id')) - assert_equal(response.scheme, body.get('scheme')) - assert_equal(response.status, body.get('status')) - assert_equal(response.links.creditor, - body.get('links')['creditor']) + assert isinstance(response, resources.MandateImport) + assert responses.calls[-1].request.headers.get('Idempotency-Key') is None + assert response.created_at == body.get('created_at') + assert response.id == body.get('id') + assert response.scheme == body.get('scheme') + assert response.status == body.get('status') + assert response.links.creditor == body.get('links')['creditor'] @responses.activate def test_timeout_mandate_imports_get_retries(): fixture = helpers.load_fixture('mandate_imports')['get'] with helpers.stub_timeout_then_response(fixture) as rsps: response = helpers.client.mandate_imports.get(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['mandate_imports'] - assert_is_instance(response, resources.MandateImport) + assert isinstance(response, resources.MandateImport) def test_502_mandate_imports_get_retries(): fixture = helpers.load_fixture('mandate_imports')['get'] with helpers.stub_502_then_response(fixture) as rsps: response = helpers.client.mandate_imports.get(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['mandate_imports'] - assert_is_instance(response, resources.MandateImport) + assert isinstance(response, resources.MandateImport) @responses.activate @@ -128,28 +114,27 @@ def test_mandate_imports_submit(): response = helpers.client.mandate_imports.submit(*fixture['url_params']) body = fixture['body']['mandate_imports'] - assert_is_instance(response, resources.MandateImport) - assert_is_not_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal(response.created_at, body.get('created_at')) - assert_equal(response.id, body.get('id')) - assert_equal(response.scheme, body.get('scheme')) - assert_equal(response.status, body.get('status')) - assert_equal(response.links.creditor, - body.get('links')['creditor']) + assert isinstance(response, resources.MandateImport) + assert responses.calls[-1].request.headers.get('Idempotency-Key') is not None + assert response.created_at == body.get('created_at') + assert response.id == body.get('id') + assert response.scheme == body.get('scheme') + assert response.status == body.get('status') + assert response.links.creditor == body.get('links')['creditor'] def test_timeout_mandate_imports_submit_doesnt_retry(): fixture = helpers.load_fixture('mandate_imports')['submit'] with helpers.stub_timeout(fixture) as rsps: - with assert_raises(requests.ConnectTimeout): + with pytest.raises(requests.ConnectTimeout): response = helpers.client.mandate_imports.submit(*fixture['url_params']) - assert_equal(1, len(rsps.calls)) + assert len(rsps.calls) == 1 def test_502_mandate_imports_submit_doesnt_retry(): fixture = helpers.load_fixture('mandate_imports')['submit'] with helpers.stub_502(fixture) as rsps: - with assert_raises(MalformedResponseError): + with pytest.raises(MalformedResponseError): response = helpers.client.mandate_imports.submit(*fixture['url_params']) - assert_equal(1, len(rsps.calls)) + assert len(rsps.calls) == 1 @responses.activate @@ -159,26 +144,25 @@ def test_mandate_imports_cancel(): response = helpers.client.mandate_imports.cancel(*fixture['url_params']) body = fixture['body']['mandate_imports'] - assert_is_instance(response, resources.MandateImport) - assert_is_not_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal(response.created_at, body.get('created_at')) - assert_equal(response.id, body.get('id')) - assert_equal(response.scheme, body.get('scheme')) - assert_equal(response.status, body.get('status')) - assert_equal(response.links.creditor, - body.get('links')['creditor']) + assert isinstance(response, resources.MandateImport) + assert responses.calls[-1].request.headers.get('Idempotency-Key') is not None + assert response.created_at == body.get('created_at') + assert response.id == body.get('id') + assert response.scheme == body.get('scheme') + assert response.status == body.get('status') + assert response.links.creditor == body.get('links')['creditor'] def test_timeout_mandate_imports_cancel_doesnt_retry(): fixture = helpers.load_fixture('mandate_imports')['cancel'] with helpers.stub_timeout(fixture) as rsps: - with assert_raises(requests.ConnectTimeout): + with pytest.raises(requests.ConnectTimeout): response = helpers.client.mandate_imports.cancel(*fixture['url_params']) - assert_equal(1, len(rsps.calls)) + assert len(rsps.calls) == 1 def test_502_mandate_imports_cancel_doesnt_retry(): fixture = helpers.load_fixture('mandate_imports')['cancel'] with helpers.stub_502(fixture) as rsps: - with assert_raises(MalformedResponseError): + with pytest.raises(MalformedResponseError): response = helpers.client.mandate_imports.cancel(*fixture['url_params']) - assert_equal(1, len(rsps.calls)) + assert len(rsps.calls) == 1 diff --git a/tests/integration/mandate_pdfs_integration_test.py b/tests/integration/mandate_pdfs_integration_test.py index fbb67c9b..978e6b94 100644 --- a/tests/integration/mandate_pdfs_integration_test.py +++ b/tests/integration/mandate_pdfs_integration_test.py @@ -5,16 +5,9 @@ import json +import pytest import requests import responses -from nose.tools import ( - assert_equal, - assert_is_instance, - assert_is_none, - assert_is_not_none, - assert_not_equal, - assert_raises -) from gocardless_pro.errors import MalformedResponseError from gocardless_pro import resources @@ -30,31 +23,29 @@ def test_mandate_pdfs_create(): response = helpers.client.mandate_pdfs.create(*fixture['url_params']) body = fixture['body']['mandate_pdfs'] - assert_is_instance(response, resources.MandatePdf) - assert_is_not_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal(response.expires_at, body.get('expires_at')) - assert_equal(response.url, body.get('url')) + assert isinstance(response, resources.MandatePdf) + assert responses.calls[-1].request.headers.get('Idempotency-Key') is not None + assert response.expires_at == body.get('expires_at') + assert response.url == body.get('url') @responses.activate def test_timeout_mandate_pdfs_create_retries(): fixture = helpers.load_fixture('mandate_pdfs')['create'] with helpers.stub_timeout_then_response(fixture) as rsps: response = helpers.client.mandate_pdfs.create(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['mandate_pdfs'] - assert_is_instance(response, resources.MandatePdf) + assert isinstance(response, resources.MandatePdf) def test_502_mandate_pdfs_create_retries(): fixture = helpers.load_fixture('mandate_pdfs')['create'] with helpers.stub_502_then_response(fixture) as rsps: response = helpers.client.mandate_pdfs.create(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['mandate_pdfs'] - assert_is_instance(response, resources.MandatePdf) + assert isinstance(response, resources.MandatePdf) diff --git a/tests/integration/mandates_integration_test.py b/tests/integration/mandates_integration_test.py index 464ec98e..5370e564 100644 --- a/tests/integration/mandates_integration_test.py +++ b/tests/integration/mandates_integration_test.py @@ -5,16 +5,9 @@ import json +import pytest import requests import responses -from nose.tools import ( - assert_equal, - assert_is_instance, - assert_is_none, - assert_is_not_none, - assert_not_equal, - assert_raises -) from gocardless_pro.errors import MalformedResponseError from gocardless_pro import resources @@ -30,35 +23,27 @@ def test_mandates_create(): response = helpers.client.mandates.create(*fixture['url_params']) body = fixture['body']['mandates'] - assert_is_instance(response, resources.Mandate) - assert_is_not_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal(response.authorisation_source, body.get('authorisation_source')) - assert_equal(response.created_at, body.get('created_at')) - assert_equal(response.funds_settlement, body.get('funds_settlement')) - assert_equal(response.id, body.get('id')) - assert_equal(response.metadata, body.get('metadata')) - assert_equal(response.next_possible_charge_date, body.get('next_possible_charge_date')) - assert_equal(response.payments_require_approval, body.get('payments_require_approval')) - assert_equal(response.reference, body.get('reference')) - assert_equal(response.scheme, body.get('scheme')) - assert_equal(response.status, body.get('status')) - assert_equal(response.verified_at, body.get('verified_at')) - assert_equal(response.consent_parameters.end_date, - body.get('consent_parameters')['end_date']) - assert_equal(response.consent_parameters.max_amount_per_payment, - body.get('consent_parameters')['max_amount_per_payment']) - assert_equal(response.consent_parameters.periods, - body.get('consent_parameters')['periods']) - assert_equal(response.consent_parameters.start_date, - body.get('consent_parameters')['start_date']) - assert_equal(response.links.creditor, - body.get('links')['creditor']) - assert_equal(response.links.customer, - body.get('links')['customer']) - assert_equal(response.links.customer_bank_account, - body.get('links')['customer_bank_account']) - assert_equal(response.links.new_mandate, - body.get('links')['new_mandate']) + assert isinstance(response, resources.Mandate) + assert responses.calls[-1].request.headers.get('Idempotency-Key') is not None + assert response.authorisation_source == body.get('authorisation_source') + assert response.created_at == body.get('created_at') + assert response.funds_settlement == body.get('funds_settlement') + assert response.id == body.get('id') + assert response.metadata == body.get('metadata') + assert response.next_possible_charge_date == body.get('next_possible_charge_date') + assert response.payments_require_approval == body.get('payments_require_approval') + assert response.reference == body.get('reference') + assert response.scheme == body.get('scheme') + assert response.status == body.get('status') + assert response.verified_at == body.get('verified_at') + assert response.consent_parameters.end_date == body.get('consent_parameters')['end_date'] + assert response.consent_parameters.max_amount_per_payment == body.get('consent_parameters')['max_amount_per_payment'] + assert response.consent_parameters.periods == body.get('consent_parameters')['periods'] + assert response.consent_parameters.start_date == body.get('consent_parameters')['start_date'] + assert response.links.creditor == body.get('links')['creditor'] + assert response.links.customer == body.get('links')['customer'] + assert response.links.customer_bank_account == body.get('links')['customer_bank_account'] + assert response.links.new_mandate == body.get('links')['new_mandate'] @responses.activate def test_mandates_create_new_idempotency_key_for_each_call(): @@ -66,40 +51,37 @@ def test_mandates_create_new_idempotency_key_for_each_call(): helpers.stub_response(fixture) helpers.client.mandates.create(*fixture['url_params']) helpers.client.mandates.create(*fixture['url_params']) - assert_not_equal(responses.calls[0].request.headers.get('Idempotency-Key'), - responses.calls[1].request.headers.get('Idempotency-Key')) + assert responses.calls[0].request.headers.get('Idempotency-Key') != responses.calls[1].request.headers.get('Idempotency-Key') def test_timeout_mandates_create_idempotency_conflict(): create_fixture = helpers.load_fixture('mandates')['create'] get_fixture = helpers.load_fixture('mandates')['get'] with helpers.stub_timeout_then_idempotency_conflict(create_fixture, get_fixture) as rsps: response = helpers.client.mandates.create(*create_fixture['url_params']) - assert_equal(2, len(rsps.calls)) + assert len(rsps.calls) == 2 - assert_is_instance(response, resources.Mandate) + assert isinstance(response, resources.Mandate) @responses.activate def test_timeout_mandates_create_retries(): fixture = helpers.load_fixture('mandates')['create'] with helpers.stub_timeout_then_response(fixture) as rsps: response = helpers.client.mandates.create(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['mandates'] - assert_is_instance(response, resources.Mandate) + assert isinstance(response, resources.Mandate) def test_502_mandates_create_retries(): fixture = helpers.load_fixture('mandates')['create'] with helpers.stub_502_then_response(fixture) as rsps: response = helpers.client.mandates.create(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['mandates'] - assert_is_instance(response, resources.Mandate) + assert isinstance(response, resources.Mandate) @responses.activate @@ -109,65 +91,52 @@ def test_mandates_list(): response = helpers.client.mandates.list(*fixture['url_params']) body = fixture['body']['mandates'] - assert_is_instance(response, list_response.ListResponse) - assert_is_instance(response.records[0], resources.Mandate) - - assert_equal(response.before, fixture['body']['meta']['cursors']['before']) - assert_equal(response.after, fixture['body']['meta']['cursors']['after']) - assert_is_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal([r.authorisation_source for r in response.records], - [b.get('authorisation_source') for b in body]) - assert_equal([r.created_at for r in response.records], - [b.get('created_at') for b in body]) - assert_equal([r.funds_settlement for r in response.records], - [b.get('funds_settlement') for b in body]) - assert_equal([r.id for r in response.records], - [b.get('id') for b in body]) - assert_equal([r.metadata for r in response.records], - [b.get('metadata') for b in body]) - assert_equal([r.next_possible_charge_date for r in response.records], - [b.get('next_possible_charge_date') for b in body]) - assert_equal([r.payments_require_approval for r in response.records], - [b.get('payments_require_approval') for b in body]) - assert_equal([r.reference for r in response.records], - [b.get('reference') for b in body]) - assert_equal([r.scheme for r in response.records], - [b.get('scheme') for b in body]) - assert_equal([r.status for r in response.records], - [b.get('status') for b in body]) - assert_equal([r.verified_at for r in response.records], - [b.get('verified_at') for b in body]) + assert isinstance(response, list_response.ListResponse) + assert isinstance(response.records[0], resources.Mandate) + + assert response.before == fixture['body']['meta']['cursors']['before'] + assert response.after == fixture['body']['meta']['cursors']['after'] + assert responses.calls[-1].request.headers.get('Idempotency-Key') is None + assert [r.authorisation_source for r in response.records] == [b.get('authorisation_source') for b in body] + assert [r.created_at for r in response.records] == [b.get('created_at') for b in body] + assert [r.funds_settlement for r in response.records] == [b.get('funds_settlement') for b in body] + assert [r.id for r in response.records] == [b.get('id') for b in body] + assert [r.metadata for r in response.records] == [b.get('metadata') for b in body] + assert [r.next_possible_charge_date for r in response.records] == [b.get('next_possible_charge_date') for b in body] + assert [r.payments_require_approval for r in response.records] == [b.get('payments_require_approval') for b in body] + assert [r.reference for r in response.records] == [b.get('reference') for b in body] + assert [r.scheme for r in response.records] == [b.get('scheme') for b in body] + assert [r.status for r in response.records] == [b.get('status') for b in body] + assert [r.verified_at for r in response.records] == [b.get('verified_at') for b in body] @responses.activate def test_timeout_mandates_list_retries(): fixture = helpers.load_fixture('mandates')['list'] with helpers.stub_timeout_then_response(fixture) as rsps: response = helpers.client.mandates.list(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['mandates'] - assert_is_instance(response, list_response.ListResponse) - assert_is_instance(response.records[0], resources.Mandate) + assert isinstance(response, list_response.ListResponse) + assert isinstance(response.records[0], resources.Mandate) - assert_equal(response.before, fixture['body']['meta']['cursors']['before']) - assert_equal(response.after, fixture['body']['meta']['cursors']['after']) + assert response.before == fixture['body']['meta']['cursors']['before'] + assert response.after == fixture['body']['meta']['cursors']['after'] def test_502_mandates_list_retries(): fixture = helpers.load_fixture('mandates')['list'] with helpers.stub_502_then_response(fixture) as rsps: response = helpers.client.mandates.list(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['mandates'] - assert_is_instance(response, list_response.ListResponse) - assert_is_instance(response.records[0], resources.Mandate) + assert isinstance(response, list_response.ListResponse) + assert isinstance(response.records[0], resources.Mandate) - assert_equal(response.before, fixture['body']['meta']['cursors']['before']) - assert_equal(response.after, fixture['body']['meta']['cursors']['after']) + assert response.before == fixture['body']['meta']['cursors']['before'] + assert response.after == fixture['body']['meta']['cursors']['after'] @responses.activate def test_mandates_all(): @@ -184,9 +153,9 @@ def callback(request): responses.add_callback(fixture['method'], url, callback) all_records = list(helpers.client.mandates.all()) - assert_equal(len(all_records), len(fixture['body']['mandates']) * 2) + assert len(all_records) == len(fixture['body']['mandates']) * 2 for record in all_records: - assert_is_instance(record, resources.Mandate) + assert isinstance(record, resources.Mandate) @@ -197,58 +166,48 @@ def test_mandates_get(): response = helpers.client.mandates.get(*fixture['url_params']) body = fixture['body']['mandates'] - assert_is_instance(response, resources.Mandate) - assert_is_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal(response.authorisation_source, body.get('authorisation_source')) - assert_equal(response.created_at, body.get('created_at')) - assert_equal(response.funds_settlement, body.get('funds_settlement')) - assert_equal(response.id, body.get('id')) - assert_equal(response.metadata, body.get('metadata')) - assert_equal(response.next_possible_charge_date, body.get('next_possible_charge_date')) - assert_equal(response.payments_require_approval, body.get('payments_require_approval')) - assert_equal(response.reference, body.get('reference')) - assert_equal(response.scheme, body.get('scheme')) - assert_equal(response.status, body.get('status')) - assert_equal(response.verified_at, body.get('verified_at')) - assert_equal(response.consent_parameters.end_date, - body.get('consent_parameters')['end_date']) - assert_equal(response.consent_parameters.max_amount_per_payment, - body.get('consent_parameters')['max_amount_per_payment']) - assert_equal(response.consent_parameters.periods, - body.get('consent_parameters')['periods']) - assert_equal(response.consent_parameters.start_date, - body.get('consent_parameters')['start_date']) - assert_equal(response.links.creditor, - body.get('links')['creditor']) - assert_equal(response.links.customer, - body.get('links')['customer']) - assert_equal(response.links.customer_bank_account, - body.get('links')['customer_bank_account']) - assert_equal(response.links.new_mandate, - body.get('links')['new_mandate']) + assert isinstance(response, resources.Mandate) + assert responses.calls[-1].request.headers.get('Idempotency-Key') is None + assert response.authorisation_source == body.get('authorisation_source') + assert response.created_at == body.get('created_at') + assert response.funds_settlement == body.get('funds_settlement') + assert response.id == body.get('id') + assert response.metadata == body.get('metadata') + assert response.next_possible_charge_date == body.get('next_possible_charge_date') + assert response.payments_require_approval == body.get('payments_require_approval') + assert response.reference == body.get('reference') + assert response.scheme == body.get('scheme') + assert response.status == body.get('status') + assert response.verified_at == body.get('verified_at') + assert response.consent_parameters.end_date == body.get('consent_parameters')['end_date'] + assert response.consent_parameters.max_amount_per_payment == body.get('consent_parameters')['max_amount_per_payment'] + assert response.consent_parameters.periods == body.get('consent_parameters')['periods'] + assert response.consent_parameters.start_date == body.get('consent_parameters')['start_date'] + assert response.links.creditor == body.get('links')['creditor'] + assert response.links.customer == body.get('links')['customer'] + assert response.links.customer_bank_account == body.get('links')['customer_bank_account'] + assert response.links.new_mandate == body.get('links')['new_mandate'] @responses.activate def test_timeout_mandates_get_retries(): fixture = helpers.load_fixture('mandates')['get'] with helpers.stub_timeout_then_response(fixture) as rsps: response = helpers.client.mandates.get(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['mandates'] - assert_is_instance(response, resources.Mandate) + assert isinstance(response, resources.Mandate) def test_502_mandates_get_retries(): fixture = helpers.load_fixture('mandates')['get'] with helpers.stub_502_then_response(fixture) as rsps: response = helpers.client.mandates.get(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['mandates'] - assert_is_instance(response, resources.Mandate) + assert isinstance(response, resources.Mandate) @responses.activate @@ -258,58 +217,48 @@ def test_mandates_update(): response = helpers.client.mandates.update(*fixture['url_params']) body = fixture['body']['mandates'] - assert_is_instance(response, resources.Mandate) - assert_is_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal(response.authorisation_source, body.get('authorisation_source')) - assert_equal(response.created_at, body.get('created_at')) - assert_equal(response.funds_settlement, body.get('funds_settlement')) - assert_equal(response.id, body.get('id')) - assert_equal(response.metadata, body.get('metadata')) - assert_equal(response.next_possible_charge_date, body.get('next_possible_charge_date')) - assert_equal(response.payments_require_approval, body.get('payments_require_approval')) - assert_equal(response.reference, body.get('reference')) - assert_equal(response.scheme, body.get('scheme')) - assert_equal(response.status, body.get('status')) - assert_equal(response.verified_at, body.get('verified_at')) - assert_equal(response.consent_parameters.end_date, - body.get('consent_parameters')['end_date']) - assert_equal(response.consent_parameters.max_amount_per_payment, - body.get('consent_parameters')['max_amount_per_payment']) - assert_equal(response.consent_parameters.periods, - body.get('consent_parameters')['periods']) - assert_equal(response.consent_parameters.start_date, - body.get('consent_parameters')['start_date']) - assert_equal(response.links.creditor, - body.get('links')['creditor']) - assert_equal(response.links.customer, - body.get('links')['customer']) - assert_equal(response.links.customer_bank_account, - body.get('links')['customer_bank_account']) - assert_equal(response.links.new_mandate, - body.get('links')['new_mandate']) + assert isinstance(response, resources.Mandate) + assert responses.calls[-1].request.headers.get('Idempotency-Key') is None + assert response.authorisation_source == body.get('authorisation_source') + assert response.created_at == body.get('created_at') + assert response.funds_settlement == body.get('funds_settlement') + assert response.id == body.get('id') + assert response.metadata == body.get('metadata') + assert response.next_possible_charge_date == body.get('next_possible_charge_date') + assert response.payments_require_approval == body.get('payments_require_approval') + assert response.reference == body.get('reference') + assert response.scheme == body.get('scheme') + assert response.status == body.get('status') + assert response.verified_at == body.get('verified_at') + assert response.consent_parameters.end_date == body.get('consent_parameters')['end_date'] + assert response.consent_parameters.max_amount_per_payment == body.get('consent_parameters')['max_amount_per_payment'] + assert response.consent_parameters.periods == body.get('consent_parameters')['periods'] + assert response.consent_parameters.start_date == body.get('consent_parameters')['start_date'] + assert response.links.creditor == body.get('links')['creditor'] + assert response.links.customer == body.get('links')['customer'] + assert response.links.customer_bank_account == body.get('links')['customer_bank_account'] + assert response.links.new_mandate == body.get('links')['new_mandate'] @responses.activate def test_timeout_mandates_update_retries(): fixture = helpers.load_fixture('mandates')['update'] with helpers.stub_timeout_then_response(fixture) as rsps: response = helpers.client.mandates.update(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['mandates'] - assert_is_instance(response, resources.Mandate) + assert isinstance(response, resources.Mandate) def test_502_mandates_update_retries(): fixture = helpers.load_fixture('mandates')['update'] with helpers.stub_502_then_response(fixture) as rsps: response = helpers.client.mandates.update(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['mandates'] - assert_is_instance(response, resources.Mandate) + assert isinstance(response, resources.Mandate) @responses.activate @@ -319,49 +268,41 @@ def test_mandates_cancel(): response = helpers.client.mandates.cancel(*fixture['url_params']) body = fixture['body']['mandates'] - assert_is_instance(response, resources.Mandate) - assert_is_not_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal(response.authorisation_source, body.get('authorisation_source')) - assert_equal(response.created_at, body.get('created_at')) - assert_equal(response.funds_settlement, body.get('funds_settlement')) - assert_equal(response.id, body.get('id')) - assert_equal(response.metadata, body.get('metadata')) - assert_equal(response.next_possible_charge_date, body.get('next_possible_charge_date')) - assert_equal(response.payments_require_approval, body.get('payments_require_approval')) - assert_equal(response.reference, body.get('reference')) - assert_equal(response.scheme, body.get('scheme')) - assert_equal(response.status, body.get('status')) - assert_equal(response.verified_at, body.get('verified_at')) - assert_equal(response.consent_parameters.end_date, - body.get('consent_parameters')['end_date']) - assert_equal(response.consent_parameters.max_amount_per_payment, - body.get('consent_parameters')['max_amount_per_payment']) - assert_equal(response.consent_parameters.periods, - body.get('consent_parameters')['periods']) - assert_equal(response.consent_parameters.start_date, - body.get('consent_parameters')['start_date']) - assert_equal(response.links.creditor, - body.get('links')['creditor']) - assert_equal(response.links.customer, - body.get('links')['customer']) - assert_equal(response.links.customer_bank_account, - body.get('links')['customer_bank_account']) - assert_equal(response.links.new_mandate, - body.get('links')['new_mandate']) + assert isinstance(response, resources.Mandate) + assert responses.calls[-1].request.headers.get('Idempotency-Key') is not None + assert response.authorisation_source == body.get('authorisation_source') + assert response.created_at == body.get('created_at') + assert response.funds_settlement == body.get('funds_settlement') + assert response.id == body.get('id') + assert response.metadata == body.get('metadata') + assert response.next_possible_charge_date == body.get('next_possible_charge_date') + assert response.payments_require_approval == body.get('payments_require_approval') + assert response.reference == body.get('reference') + assert response.scheme == body.get('scheme') + assert response.status == body.get('status') + assert response.verified_at == body.get('verified_at') + assert response.consent_parameters.end_date == body.get('consent_parameters')['end_date'] + assert response.consent_parameters.max_amount_per_payment == body.get('consent_parameters')['max_amount_per_payment'] + assert response.consent_parameters.periods == body.get('consent_parameters')['periods'] + assert response.consent_parameters.start_date == body.get('consent_parameters')['start_date'] + assert response.links.creditor == body.get('links')['creditor'] + assert response.links.customer == body.get('links')['customer'] + assert response.links.customer_bank_account == body.get('links')['customer_bank_account'] + assert response.links.new_mandate == body.get('links')['new_mandate'] def test_timeout_mandates_cancel_doesnt_retry(): fixture = helpers.load_fixture('mandates')['cancel'] with helpers.stub_timeout(fixture) as rsps: - with assert_raises(requests.ConnectTimeout): + with pytest.raises(requests.ConnectTimeout): response = helpers.client.mandates.cancel(*fixture['url_params']) - assert_equal(1, len(rsps.calls)) + assert len(rsps.calls) == 1 def test_502_mandates_cancel_doesnt_retry(): fixture = helpers.load_fixture('mandates')['cancel'] with helpers.stub_502(fixture) as rsps: - with assert_raises(MalformedResponseError): + with pytest.raises(MalformedResponseError): response = helpers.client.mandates.cancel(*fixture['url_params']) - assert_equal(1, len(rsps.calls)) + assert len(rsps.calls) == 1 @responses.activate @@ -371,47 +312,39 @@ def test_mandates_reinstate(): response = helpers.client.mandates.reinstate(*fixture['url_params']) body = fixture['body']['mandates'] - assert_is_instance(response, resources.Mandate) - assert_is_not_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal(response.authorisation_source, body.get('authorisation_source')) - assert_equal(response.created_at, body.get('created_at')) - assert_equal(response.funds_settlement, body.get('funds_settlement')) - assert_equal(response.id, body.get('id')) - assert_equal(response.metadata, body.get('metadata')) - assert_equal(response.next_possible_charge_date, body.get('next_possible_charge_date')) - assert_equal(response.payments_require_approval, body.get('payments_require_approval')) - assert_equal(response.reference, body.get('reference')) - assert_equal(response.scheme, body.get('scheme')) - assert_equal(response.status, body.get('status')) - assert_equal(response.verified_at, body.get('verified_at')) - assert_equal(response.consent_parameters.end_date, - body.get('consent_parameters')['end_date']) - assert_equal(response.consent_parameters.max_amount_per_payment, - body.get('consent_parameters')['max_amount_per_payment']) - assert_equal(response.consent_parameters.periods, - body.get('consent_parameters')['periods']) - assert_equal(response.consent_parameters.start_date, - body.get('consent_parameters')['start_date']) - assert_equal(response.links.creditor, - body.get('links')['creditor']) - assert_equal(response.links.customer, - body.get('links')['customer']) - assert_equal(response.links.customer_bank_account, - body.get('links')['customer_bank_account']) - assert_equal(response.links.new_mandate, - body.get('links')['new_mandate']) + assert isinstance(response, resources.Mandate) + assert responses.calls[-1].request.headers.get('Idempotency-Key') is not None + assert response.authorisation_source == body.get('authorisation_source') + assert response.created_at == body.get('created_at') + assert response.funds_settlement == body.get('funds_settlement') + assert response.id == body.get('id') + assert response.metadata == body.get('metadata') + assert response.next_possible_charge_date == body.get('next_possible_charge_date') + assert response.payments_require_approval == body.get('payments_require_approval') + assert response.reference == body.get('reference') + assert response.scheme == body.get('scheme') + assert response.status == body.get('status') + assert response.verified_at == body.get('verified_at') + assert response.consent_parameters.end_date == body.get('consent_parameters')['end_date'] + assert response.consent_parameters.max_amount_per_payment == body.get('consent_parameters')['max_amount_per_payment'] + assert response.consent_parameters.periods == body.get('consent_parameters')['periods'] + assert response.consent_parameters.start_date == body.get('consent_parameters')['start_date'] + assert response.links.creditor == body.get('links')['creditor'] + assert response.links.customer == body.get('links')['customer'] + assert response.links.customer_bank_account == body.get('links')['customer_bank_account'] + assert response.links.new_mandate == body.get('links')['new_mandate'] def test_timeout_mandates_reinstate_doesnt_retry(): fixture = helpers.load_fixture('mandates')['reinstate'] with helpers.stub_timeout(fixture) as rsps: - with assert_raises(requests.ConnectTimeout): + with pytest.raises(requests.ConnectTimeout): response = helpers.client.mandates.reinstate(*fixture['url_params']) - assert_equal(1, len(rsps.calls)) + assert len(rsps.calls) == 1 def test_502_mandates_reinstate_doesnt_retry(): fixture = helpers.load_fixture('mandates')['reinstate'] with helpers.stub_502(fixture) as rsps: - with assert_raises(MalformedResponseError): + with pytest.raises(MalformedResponseError): response = helpers.client.mandates.reinstate(*fixture['url_params']) - assert_equal(1, len(rsps.calls)) + assert len(rsps.calls) == 1 diff --git a/tests/integration/negative_balance_limits_integration_test.py b/tests/integration/negative_balance_limits_integration_test.py index 14ca5c8d..d52000ea 100644 --- a/tests/integration/negative_balance_limits_integration_test.py +++ b/tests/integration/negative_balance_limits_integration_test.py @@ -5,16 +5,9 @@ import json +import pytest import requests import responses -from nose.tools import ( - assert_equal, - assert_is_instance, - assert_is_none, - assert_is_not_none, - assert_not_equal, - assert_raises -) from gocardless_pro.errors import MalformedResponseError from gocardless_pro import resources @@ -30,51 +23,45 @@ def test_negative_balance_limits_list(): response = helpers.client.negative_balance_limits.list(*fixture['url_params']) body = fixture['body']['negative_balance_limits'] - assert_is_instance(response, list_response.ListResponse) - assert_is_instance(response.records[0], resources.NegativeBalanceLimit) - - assert_equal(response.before, fixture['body']['meta']['cursors']['before']) - assert_equal(response.after, fixture['body']['meta']['cursors']['after']) - assert_is_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal([r.balance_limit for r in response.records], - [b.get('balance_limit') for b in body]) - assert_equal([r.created_at for r in response.records], - [b.get('created_at') for b in body]) - assert_equal([r.currency for r in response.records], - [b.get('currency') for b in body]) - assert_equal([r.id for r in response.records], - [b.get('id') for b in body]) + assert isinstance(response, list_response.ListResponse) + assert isinstance(response.records[0], resources.NegativeBalanceLimit) + + assert response.before == fixture['body']['meta']['cursors']['before'] + assert response.after == fixture['body']['meta']['cursors']['after'] + assert responses.calls[-1].request.headers.get('Idempotency-Key') is None + assert [r.balance_limit for r in response.records] == [b.get('balance_limit') for b in body] + assert [r.created_at for r in response.records] == [b.get('created_at') for b in body] + assert [r.currency for r in response.records] == [b.get('currency') for b in body] + assert [r.id for r in response.records] == [b.get('id') for b in body] @responses.activate def test_timeout_negative_balance_limits_list_retries(): fixture = helpers.load_fixture('negative_balance_limits')['list'] with helpers.stub_timeout_then_response(fixture) as rsps: response = helpers.client.negative_balance_limits.list(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['negative_balance_limits'] - assert_is_instance(response, list_response.ListResponse) - assert_is_instance(response.records[0], resources.NegativeBalanceLimit) + assert isinstance(response, list_response.ListResponse) + assert isinstance(response.records[0], resources.NegativeBalanceLimit) - assert_equal(response.before, fixture['body']['meta']['cursors']['before']) - assert_equal(response.after, fixture['body']['meta']['cursors']['after']) + assert response.before == fixture['body']['meta']['cursors']['before'] + assert response.after == fixture['body']['meta']['cursors']['after'] def test_502_negative_balance_limits_list_retries(): fixture = helpers.load_fixture('negative_balance_limits')['list'] with helpers.stub_502_then_response(fixture) as rsps: response = helpers.client.negative_balance_limits.list(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['negative_balance_limits'] - assert_is_instance(response, list_response.ListResponse) - assert_is_instance(response.records[0], resources.NegativeBalanceLimit) + assert isinstance(response, list_response.ListResponse) + assert isinstance(response.records[0], resources.NegativeBalanceLimit) - assert_equal(response.before, fixture['body']['meta']['cursors']['before']) - assert_equal(response.after, fixture['body']['meta']['cursors']['after']) + assert response.before == fixture['body']['meta']['cursors']['before'] + assert response.after == fixture['body']['meta']['cursors']['after'] @responses.activate def test_negative_balance_limits_all(): @@ -91,9 +78,9 @@ def callback(request): responses.add_callback(fixture['method'], url, callback) all_records = list(helpers.client.negative_balance_limits.all()) - assert_equal(len(all_records), len(fixture['body']['negative_balance_limits']) * 2) + assert len(all_records) == len(fixture['body']['negative_balance_limits']) * 2 for record in all_records: - assert_is_instance(record, resources.NegativeBalanceLimit) + assert isinstance(record, resources.NegativeBalanceLimit) @@ -104,37 +91,33 @@ def test_negative_balance_limits_create(): response = helpers.client.negative_balance_limits.create(*fixture['url_params']) body = fixture['body']['negative_balance_limits'] - assert_is_instance(response, resources.NegativeBalanceLimit) - assert_is_not_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal(response.balance_limit, body.get('balance_limit')) - assert_equal(response.created_at, body.get('created_at')) - assert_equal(response.currency, body.get('currency')) - assert_equal(response.id, body.get('id')) - assert_equal(response.links.creator_user, - body.get('links')['creator_user']) - assert_equal(response.links.creditor, - body.get('links')['creditor']) + assert isinstance(response, resources.NegativeBalanceLimit) + assert responses.calls[-1].request.headers.get('Idempotency-Key') is not None + assert response.balance_limit == body.get('balance_limit') + assert response.created_at == body.get('created_at') + assert response.currency == body.get('currency') + assert response.id == body.get('id') + assert response.links.creator_user == body.get('links')['creator_user'] + assert response.links.creditor == body.get('links')['creditor'] @responses.activate def test_timeout_negative_balance_limits_create_retries(): fixture = helpers.load_fixture('negative_balance_limits')['create'] with helpers.stub_timeout_then_response(fixture) as rsps: response = helpers.client.negative_balance_limits.create(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['negative_balance_limits'] - assert_is_instance(response, resources.NegativeBalanceLimit) + assert isinstance(response, resources.NegativeBalanceLimit) def test_502_negative_balance_limits_create_retries(): fixture = helpers.load_fixture('negative_balance_limits')['create'] with helpers.stub_502_then_response(fixture) as rsps: response = helpers.client.negative_balance_limits.create(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['negative_balance_limits'] - assert_is_instance(response, resources.NegativeBalanceLimit) + assert isinstance(response, resources.NegativeBalanceLimit) diff --git a/tests/integration/payer_authorisations_integration_test.py b/tests/integration/payer_authorisations_integration_test.py index 225ca343..faa8abce 100644 --- a/tests/integration/payer_authorisations_integration_test.py +++ b/tests/integration/payer_authorisations_integration_test.py @@ -5,16 +5,9 @@ import json +import pytest import requests import responses -from nose.tools import ( - assert_equal, - assert_is_instance, - assert_is_none, - assert_is_not_none, - assert_not_equal, - assert_raises -) from gocardless_pro.errors import MalformedResponseError from gocardless_pro import resources @@ -30,101 +23,66 @@ def test_payer_authorisations_get(): response = helpers.client.payer_authorisations.get(*fixture['url_params']) body = fixture['body']['payer_authorisations'] - assert_is_instance(response, resources.PayerAuthorisation) - assert_is_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal(response.created_at, body.get('created_at')) - assert_equal(response.id, body.get('id')) - assert_equal(response.incomplete_fields, body.get('incomplete_fields')) - assert_equal(response.status, body.get('status')) - assert_equal(response.bank_account.account_holder_name, - body.get('bank_account')['account_holder_name']) - assert_equal(response.bank_account.account_number, - body.get('bank_account')['account_number']) - assert_equal(response.bank_account.account_number_ending, - body.get('bank_account')['account_number_ending']) - assert_equal(response.bank_account.account_number_suffix, - body.get('bank_account')['account_number_suffix']) - assert_equal(response.bank_account.account_type, - body.get('bank_account')['account_type']) - assert_equal(response.bank_account.bank_code, - body.get('bank_account')['bank_code']) - assert_equal(response.bank_account.branch_code, - body.get('bank_account')['branch_code']) - assert_equal(response.bank_account.country_code, - body.get('bank_account')['country_code']) - assert_equal(response.bank_account.currency, - body.get('bank_account')['currency']) - assert_equal(response.bank_account.iban, - body.get('bank_account')['iban']) - assert_equal(response.bank_account.metadata, - body.get('bank_account')['metadata']) - assert_equal(response.customer.address_line1, - body.get('customer')['address_line1']) - assert_equal(response.customer.address_line2, - body.get('customer')['address_line2']) - assert_equal(response.customer.address_line3, - body.get('customer')['address_line3']) - assert_equal(response.customer.city, - body.get('customer')['city']) - assert_equal(response.customer.company_name, - body.get('customer')['company_name']) - assert_equal(response.customer.country_code, - body.get('customer')['country_code']) - assert_equal(response.customer.danish_identity_number, - body.get('customer')['danish_identity_number']) - assert_equal(response.customer.email, - body.get('customer')['email']) - assert_equal(response.customer.family_name, - body.get('customer')['family_name']) - assert_equal(response.customer.given_name, - body.get('customer')['given_name']) - assert_equal(response.customer.locale, - body.get('customer')['locale']) - assert_equal(response.customer.metadata, - body.get('customer')['metadata']) - assert_equal(response.customer.postal_code, - body.get('customer')['postal_code']) - assert_equal(response.customer.region, - body.get('customer')['region']) - assert_equal(response.customer.swedish_identity_number, - body.get('customer')['swedish_identity_number']) - assert_equal(response.links.bank_account, - body.get('links')['bank_account']) - assert_equal(response.links.customer, - body.get('links')['customer']) - assert_equal(response.links.mandate, - body.get('links')['mandate']) - assert_equal(response.mandate.metadata, - body.get('mandate')['metadata']) - assert_equal(response.mandate.payer_ip_address, - body.get('mandate')['payer_ip_address']) - assert_equal(response.mandate.reference, - body.get('mandate')['reference']) - assert_equal(response.mandate.scheme, - body.get('mandate')['scheme']) + assert isinstance(response, resources.PayerAuthorisation) + assert responses.calls[-1].request.headers.get('Idempotency-Key') is None + assert response.created_at == body.get('created_at') + assert response.id == body.get('id') + assert response.incomplete_fields == body.get('incomplete_fields') + assert response.status == body.get('status') + assert response.bank_account.account_holder_name == body.get('bank_account')['account_holder_name'] + assert response.bank_account.account_number == body.get('bank_account')['account_number'] + assert response.bank_account.account_number_ending == body.get('bank_account')['account_number_ending'] + assert response.bank_account.account_number_suffix == body.get('bank_account')['account_number_suffix'] + assert response.bank_account.account_type == body.get('bank_account')['account_type'] + assert response.bank_account.bank_code == body.get('bank_account')['bank_code'] + assert response.bank_account.branch_code == body.get('bank_account')['branch_code'] + assert response.bank_account.country_code == body.get('bank_account')['country_code'] + assert response.bank_account.currency == body.get('bank_account')['currency'] + assert response.bank_account.iban == body.get('bank_account')['iban'] + assert response.bank_account.metadata == body.get('bank_account')['metadata'] + assert response.customer.address_line1 == body.get('customer')['address_line1'] + assert response.customer.address_line2 == body.get('customer')['address_line2'] + assert response.customer.address_line3 == body.get('customer')['address_line3'] + assert response.customer.city == body.get('customer')['city'] + assert response.customer.company_name == body.get('customer')['company_name'] + assert response.customer.country_code == body.get('customer')['country_code'] + assert response.customer.danish_identity_number == body.get('customer')['danish_identity_number'] + assert response.customer.email == body.get('customer')['email'] + assert response.customer.family_name == body.get('customer')['family_name'] + assert response.customer.given_name == body.get('customer')['given_name'] + assert response.customer.locale == body.get('customer')['locale'] + assert response.customer.metadata == body.get('customer')['metadata'] + assert response.customer.postal_code == body.get('customer')['postal_code'] + assert response.customer.region == body.get('customer')['region'] + assert response.customer.swedish_identity_number == body.get('customer')['swedish_identity_number'] + assert response.links.bank_account == body.get('links')['bank_account'] + assert response.links.customer == body.get('links')['customer'] + assert response.links.mandate == body.get('links')['mandate'] + assert response.mandate.metadata == body.get('mandate')['metadata'] + assert response.mandate.payer_ip_address == body.get('mandate')['payer_ip_address'] + assert response.mandate.reference == body.get('mandate')['reference'] + assert response.mandate.scheme == body.get('mandate')['scheme'] @responses.activate def test_timeout_payer_authorisations_get_retries(): fixture = helpers.load_fixture('payer_authorisations')['get'] with helpers.stub_timeout_then_response(fixture) as rsps: response = helpers.client.payer_authorisations.get(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['payer_authorisations'] - assert_is_instance(response, resources.PayerAuthorisation) + assert isinstance(response, resources.PayerAuthorisation) def test_502_payer_authorisations_get_retries(): fixture = helpers.load_fixture('payer_authorisations')['get'] with helpers.stub_502_then_response(fixture) as rsps: response = helpers.client.payer_authorisations.get(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['payer_authorisations'] - assert_is_instance(response, resources.PayerAuthorisation) + assert isinstance(response, resources.PayerAuthorisation) @responses.activate @@ -134,78 +92,45 @@ def test_payer_authorisations_create(): response = helpers.client.payer_authorisations.create(*fixture['url_params']) body = fixture['body']['payer_authorisations'] - assert_is_instance(response, resources.PayerAuthorisation) - assert_is_not_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal(response.created_at, body.get('created_at')) - assert_equal(response.id, body.get('id')) - assert_equal(response.incomplete_fields, body.get('incomplete_fields')) - assert_equal(response.status, body.get('status')) - assert_equal(response.bank_account.account_holder_name, - body.get('bank_account')['account_holder_name']) - assert_equal(response.bank_account.account_number, - body.get('bank_account')['account_number']) - assert_equal(response.bank_account.account_number_ending, - body.get('bank_account')['account_number_ending']) - assert_equal(response.bank_account.account_number_suffix, - body.get('bank_account')['account_number_suffix']) - assert_equal(response.bank_account.account_type, - body.get('bank_account')['account_type']) - assert_equal(response.bank_account.bank_code, - body.get('bank_account')['bank_code']) - assert_equal(response.bank_account.branch_code, - body.get('bank_account')['branch_code']) - assert_equal(response.bank_account.country_code, - body.get('bank_account')['country_code']) - assert_equal(response.bank_account.currency, - body.get('bank_account')['currency']) - assert_equal(response.bank_account.iban, - body.get('bank_account')['iban']) - assert_equal(response.bank_account.metadata, - body.get('bank_account')['metadata']) - assert_equal(response.customer.address_line1, - body.get('customer')['address_line1']) - assert_equal(response.customer.address_line2, - body.get('customer')['address_line2']) - assert_equal(response.customer.address_line3, - body.get('customer')['address_line3']) - assert_equal(response.customer.city, - body.get('customer')['city']) - assert_equal(response.customer.company_name, - body.get('customer')['company_name']) - assert_equal(response.customer.country_code, - body.get('customer')['country_code']) - assert_equal(response.customer.danish_identity_number, - body.get('customer')['danish_identity_number']) - assert_equal(response.customer.email, - body.get('customer')['email']) - assert_equal(response.customer.family_name, - body.get('customer')['family_name']) - assert_equal(response.customer.given_name, - body.get('customer')['given_name']) - assert_equal(response.customer.locale, - body.get('customer')['locale']) - assert_equal(response.customer.metadata, - body.get('customer')['metadata']) - assert_equal(response.customer.postal_code, - body.get('customer')['postal_code']) - assert_equal(response.customer.region, - body.get('customer')['region']) - assert_equal(response.customer.swedish_identity_number, - body.get('customer')['swedish_identity_number']) - assert_equal(response.links.bank_account, - body.get('links')['bank_account']) - assert_equal(response.links.customer, - body.get('links')['customer']) - assert_equal(response.links.mandate, - body.get('links')['mandate']) - assert_equal(response.mandate.metadata, - body.get('mandate')['metadata']) - assert_equal(response.mandate.payer_ip_address, - body.get('mandate')['payer_ip_address']) - assert_equal(response.mandate.reference, - body.get('mandate')['reference']) - assert_equal(response.mandate.scheme, - body.get('mandate')['scheme']) + assert isinstance(response, resources.PayerAuthorisation) + assert responses.calls[-1].request.headers.get('Idempotency-Key') is not None + assert response.created_at == body.get('created_at') + assert response.id == body.get('id') + assert response.incomplete_fields == body.get('incomplete_fields') + assert response.status == body.get('status') + assert response.bank_account.account_holder_name == body.get('bank_account')['account_holder_name'] + assert response.bank_account.account_number == body.get('bank_account')['account_number'] + assert response.bank_account.account_number_ending == body.get('bank_account')['account_number_ending'] + assert response.bank_account.account_number_suffix == body.get('bank_account')['account_number_suffix'] + assert response.bank_account.account_type == body.get('bank_account')['account_type'] + assert response.bank_account.bank_code == body.get('bank_account')['bank_code'] + assert response.bank_account.branch_code == body.get('bank_account')['branch_code'] + assert response.bank_account.country_code == body.get('bank_account')['country_code'] + assert response.bank_account.currency == body.get('bank_account')['currency'] + assert response.bank_account.iban == body.get('bank_account')['iban'] + assert response.bank_account.metadata == body.get('bank_account')['metadata'] + assert response.customer.address_line1 == body.get('customer')['address_line1'] + assert response.customer.address_line2 == body.get('customer')['address_line2'] + assert response.customer.address_line3 == body.get('customer')['address_line3'] + assert response.customer.city == body.get('customer')['city'] + assert response.customer.company_name == body.get('customer')['company_name'] + assert response.customer.country_code == body.get('customer')['country_code'] + assert response.customer.danish_identity_number == body.get('customer')['danish_identity_number'] + assert response.customer.email == body.get('customer')['email'] + assert response.customer.family_name == body.get('customer')['family_name'] + assert response.customer.given_name == body.get('customer')['given_name'] + assert response.customer.locale == body.get('customer')['locale'] + assert response.customer.metadata == body.get('customer')['metadata'] + assert response.customer.postal_code == body.get('customer')['postal_code'] + assert response.customer.region == body.get('customer')['region'] + assert response.customer.swedish_identity_number == body.get('customer')['swedish_identity_number'] + assert response.links.bank_account == body.get('links')['bank_account'] + assert response.links.customer == body.get('links')['customer'] + assert response.links.mandate == body.get('links')['mandate'] + assert response.mandate.metadata == body.get('mandate')['metadata'] + assert response.mandate.payer_ip_address == body.get('mandate')['payer_ip_address'] + assert response.mandate.reference == body.get('mandate')['reference'] + assert response.mandate.scheme == body.get('mandate')['scheme'] @responses.activate def test_payer_authorisations_create_new_idempotency_key_for_each_call(): @@ -213,40 +138,37 @@ def test_payer_authorisations_create_new_idempotency_key_for_each_call(): helpers.stub_response(fixture) helpers.client.payer_authorisations.create(*fixture['url_params']) helpers.client.payer_authorisations.create(*fixture['url_params']) - assert_not_equal(responses.calls[0].request.headers.get('Idempotency-Key'), - responses.calls[1].request.headers.get('Idempotency-Key')) + assert responses.calls[0].request.headers.get('Idempotency-Key') != responses.calls[1].request.headers.get('Idempotency-Key') def test_timeout_payer_authorisations_create_idempotency_conflict(): create_fixture = helpers.load_fixture('payer_authorisations')['create'] get_fixture = helpers.load_fixture('payer_authorisations')['get'] with helpers.stub_timeout_then_idempotency_conflict(create_fixture, get_fixture) as rsps: response = helpers.client.payer_authorisations.create(*create_fixture['url_params']) - assert_equal(2, len(rsps.calls)) + assert len(rsps.calls) == 2 - assert_is_instance(response, resources.PayerAuthorisation) + assert isinstance(response, resources.PayerAuthorisation) @responses.activate def test_timeout_payer_authorisations_create_retries(): fixture = helpers.load_fixture('payer_authorisations')['create'] with helpers.stub_timeout_then_response(fixture) as rsps: response = helpers.client.payer_authorisations.create(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['payer_authorisations'] - assert_is_instance(response, resources.PayerAuthorisation) + assert isinstance(response, resources.PayerAuthorisation) def test_502_payer_authorisations_create_retries(): fixture = helpers.load_fixture('payer_authorisations')['create'] with helpers.stub_502_then_response(fixture) as rsps: response = helpers.client.payer_authorisations.create(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['payer_authorisations'] - assert_is_instance(response, resources.PayerAuthorisation) + assert isinstance(response, resources.PayerAuthorisation) @responses.activate @@ -256,101 +178,66 @@ def test_payer_authorisations_update(): response = helpers.client.payer_authorisations.update(*fixture['url_params']) body = fixture['body']['payer_authorisations'] - assert_is_instance(response, resources.PayerAuthorisation) - assert_is_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal(response.created_at, body.get('created_at')) - assert_equal(response.id, body.get('id')) - assert_equal(response.incomplete_fields, body.get('incomplete_fields')) - assert_equal(response.status, body.get('status')) - assert_equal(response.bank_account.account_holder_name, - body.get('bank_account')['account_holder_name']) - assert_equal(response.bank_account.account_number, - body.get('bank_account')['account_number']) - assert_equal(response.bank_account.account_number_ending, - body.get('bank_account')['account_number_ending']) - assert_equal(response.bank_account.account_number_suffix, - body.get('bank_account')['account_number_suffix']) - assert_equal(response.bank_account.account_type, - body.get('bank_account')['account_type']) - assert_equal(response.bank_account.bank_code, - body.get('bank_account')['bank_code']) - assert_equal(response.bank_account.branch_code, - body.get('bank_account')['branch_code']) - assert_equal(response.bank_account.country_code, - body.get('bank_account')['country_code']) - assert_equal(response.bank_account.currency, - body.get('bank_account')['currency']) - assert_equal(response.bank_account.iban, - body.get('bank_account')['iban']) - assert_equal(response.bank_account.metadata, - body.get('bank_account')['metadata']) - assert_equal(response.customer.address_line1, - body.get('customer')['address_line1']) - assert_equal(response.customer.address_line2, - body.get('customer')['address_line2']) - assert_equal(response.customer.address_line3, - body.get('customer')['address_line3']) - assert_equal(response.customer.city, - body.get('customer')['city']) - assert_equal(response.customer.company_name, - body.get('customer')['company_name']) - assert_equal(response.customer.country_code, - body.get('customer')['country_code']) - assert_equal(response.customer.danish_identity_number, - body.get('customer')['danish_identity_number']) - assert_equal(response.customer.email, - body.get('customer')['email']) - assert_equal(response.customer.family_name, - body.get('customer')['family_name']) - assert_equal(response.customer.given_name, - body.get('customer')['given_name']) - assert_equal(response.customer.locale, - body.get('customer')['locale']) - assert_equal(response.customer.metadata, - body.get('customer')['metadata']) - assert_equal(response.customer.postal_code, - body.get('customer')['postal_code']) - assert_equal(response.customer.region, - body.get('customer')['region']) - assert_equal(response.customer.swedish_identity_number, - body.get('customer')['swedish_identity_number']) - assert_equal(response.links.bank_account, - body.get('links')['bank_account']) - assert_equal(response.links.customer, - body.get('links')['customer']) - assert_equal(response.links.mandate, - body.get('links')['mandate']) - assert_equal(response.mandate.metadata, - body.get('mandate')['metadata']) - assert_equal(response.mandate.payer_ip_address, - body.get('mandate')['payer_ip_address']) - assert_equal(response.mandate.reference, - body.get('mandate')['reference']) - assert_equal(response.mandate.scheme, - body.get('mandate')['scheme']) + assert isinstance(response, resources.PayerAuthorisation) + assert responses.calls[-1].request.headers.get('Idempotency-Key') is None + assert response.created_at == body.get('created_at') + assert response.id == body.get('id') + assert response.incomplete_fields == body.get('incomplete_fields') + assert response.status == body.get('status') + assert response.bank_account.account_holder_name == body.get('bank_account')['account_holder_name'] + assert response.bank_account.account_number == body.get('bank_account')['account_number'] + assert response.bank_account.account_number_ending == body.get('bank_account')['account_number_ending'] + assert response.bank_account.account_number_suffix == body.get('bank_account')['account_number_suffix'] + assert response.bank_account.account_type == body.get('bank_account')['account_type'] + assert response.bank_account.bank_code == body.get('bank_account')['bank_code'] + assert response.bank_account.branch_code == body.get('bank_account')['branch_code'] + assert response.bank_account.country_code == body.get('bank_account')['country_code'] + assert response.bank_account.currency == body.get('bank_account')['currency'] + assert response.bank_account.iban == body.get('bank_account')['iban'] + assert response.bank_account.metadata == body.get('bank_account')['metadata'] + assert response.customer.address_line1 == body.get('customer')['address_line1'] + assert response.customer.address_line2 == body.get('customer')['address_line2'] + assert response.customer.address_line3 == body.get('customer')['address_line3'] + assert response.customer.city == body.get('customer')['city'] + assert response.customer.company_name == body.get('customer')['company_name'] + assert response.customer.country_code == body.get('customer')['country_code'] + assert response.customer.danish_identity_number == body.get('customer')['danish_identity_number'] + assert response.customer.email == body.get('customer')['email'] + assert response.customer.family_name == body.get('customer')['family_name'] + assert response.customer.given_name == body.get('customer')['given_name'] + assert response.customer.locale == body.get('customer')['locale'] + assert response.customer.metadata == body.get('customer')['metadata'] + assert response.customer.postal_code == body.get('customer')['postal_code'] + assert response.customer.region == body.get('customer')['region'] + assert response.customer.swedish_identity_number == body.get('customer')['swedish_identity_number'] + assert response.links.bank_account == body.get('links')['bank_account'] + assert response.links.customer == body.get('links')['customer'] + assert response.links.mandate == body.get('links')['mandate'] + assert response.mandate.metadata == body.get('mandate')['metadata'] + assert response.mandate.payer_ip_address == body.get('mandate')['payer_ip_address'] + assert response.mandate.reference == body.get('mandate')['reference'] + assert response.mandate.scheme == body.get('mandate')['scheme'] @responses.activate def test_timeout_payer_authorisations_update_retries(): fixture = helpers.load_fixture('payer_authorisations')['update'] with helpers.stub_timeout_then_response(fixture) as rsps: response = helpers.client.payer_authorisations.update(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['payer_authorisations'] - assert_is_instance(response, resources.PayerAuthorisation) + assert isinstance(response, resources.PayerAuthorisation) def test_502_payer_authorisations_update_retries(): fixture = helpers.load_fixture('payer_authorisations')['update'] with helpers.stub_502_then_response(fixture) as rsps: response = helpers.client.payer_authorisations.update(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['payer_authorisations'] - assert_is_instance(response, resources.PayerAuthorisation) + assert isinstance(response, resources.PayerAuthorisation) @responses.activate @@ -360,92 +247,59 @@ def test_payer_authorisations_submit(): response = helpers.client.payer_authorisations.submit(*fixture['url_params']) body = fixture['body']['payer_authorisations'] - assert_is_instance(response, resources.PayerAuthorisation) - assert_is_not_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal(response.created_at, body.get('created_at')) - assert_equal(response.id, body.get('id')) - assert_equal(response.incomplete_fields, body.get('incomplete_fields')) - assert_equal(response.status, body.get('status')) - assert_equal(response.bank_account.account_holder_name, - body.get('bank_account')['account_holder_name']) - assert_equal(response.bank_account.account_number, - body.get('bank_account')['account_number']) - assert_equal(response.bank_account.account_number_ending, - body.get('bank_account')['account_number_ending']) - assert_equal(response.bank_account.account_number_suffix, - body.get('bank_account')['account_number_suffix']) - assert_equal(response.bank_account.account_type, - body.get('bank_account')['account_type']) - assert_equal(response.bank_account.bank_code, - body.get('bank_account')['bank_code']) - assert_equal(response.bank_account.branch_code, - body.get('bank_account')['branch_code']) - assert_equal(response.bank_account.country_code, - body.get('bank_account')['country_code']) - assert_equal(response.bank_account.currency, - body.get('bank_account')['currency']) - assert_equal(response.bank_account.iban, - body.get('bank_account')['iban']) - assert_equal(response.bank_account.metadata, - body.get('bank_account')['metadata']) - assert_equal(response.customer.address_line1, - body.get('customer')['address_line1']) - assert_equal(response.customer.address_line2, - body.get('customer')['address_line2']) - assert_equal(response.customer.address_line3, - body.get('customer')['address_line3']) - assert_equal(response.customer.city, - body.get('customer')['city']) - assert_equal(response.customer.company_name, - body.get('customer')['company_name']) - assert_equal(response.customer.country_code, - body.get('customer')['country_code']) - assert_equal(response.customer.danish_identity_number, - body.get('customer')['danish_identity_number']) - assert_equal(response.customer.email, - body.get('customer')['email']) - assert_equal(response.customer.family_name, - body.get('customer')['family_name']) - assert_equal(response.customer.given_name, - body.get('customer')['given_name']) - assert_equal(response.customer.locale, - body.get('customer')['locale']) - assert_equal(response.customer.metadata, - body.get('customer')['metadata']) - assert_equal(response.customer.postal_code, - body.get('customer')['postal_code']) - assert_equal(response.customer.region, - body.get('customer')['region']) - assert_equal(response.customer.swedish_identity_number, - body.get('customer')['swedish_identity_number']) - assert_equal(response.links.bank_account, - body.get('links')['bank_account']) - assert_equal(response.links.customer, - body.get('links')['customer']) - assert_equal(response.links.mandate, - body.get('links')['mandate']) - assert_equal(response.mandate.metadata, - body.get('mandate')['metadata']) - assert_equal(response.mandate.payer_ip_address, - body.get('mandate')['payer_ip_address']) - assert_equal(response.mandate.reference, - body.get('mandate')['reference']) - assert_equal(response.mandate.scheme, - body.get('mandate')['scheme']) + assert isinstance(response, resources.PayerAuthorisation) + assert responses.calls[-1].request.headers.get('Idempotency-Key') is not None + assert response.created_at == body.get('created_at') + assert response.id == body.get('id') + assert response.incomplete_fields == body.get('incomplete_fields') + assert response.status == body.get('status') + assert response.bank_account.account_holder_name == body.get('bank_account')['account_holder_name'] + assert response.bank_account.account_number == body.get('bank_account')['account_number'] + assert response.bank_account.account_number_ending == body.get('bank_account')['account_number_ending'] + assert response.bank_account.account_number_suffix == body.get('bank_account')['account_number_suffix'] + assert response.bank_account.account_type == body.get('bank_account')['account_type'] + assert response.bank_account.bank_code == body.get('bank_account')['bank_code'] + assert response.bank_account.branch_code == body.get('bank_account')['branch_code'] + assert response.bank_account.country_code == body.get('bank_account')['country_code'] + assert response.bank_account.currency == body.get('bank_account')['currency'] + assert response.bank_account.iban == body.get('bank_account')['iban'] + assert response.bank_account.metadata == body.get('bank_account')['metadata'] + assert response.customer.address_line1 == body.get('customer')['address_line1'] + assert response.customer.address_line2 == body.get('customer')['address_line2'] + assert response.customer.address_line3 == body.get('customer')['address_line3'] + assert response.customer.city == body.get('customer')['city'] + assert response.customer.company_name == body.get('customer')['company_name'] + assert response.customer.country_code == body.get('customer')['country_code'] + assert response.customer.danish_identity_number == body.get('customer')['danish_identity_number'] + assert response.customer.email == body.get('customer')['email'] + assert response.customer.family_name == body.get('customer')['family_name'] + assert response.customer.given_name == body.get('customer')['given_name'] + assert response.customer.locale == body.get('customer')['locale'] + assert response.customer.metadata == body.get('customer')['metadata'] + assert response.customer.postal_code == body.get('customer')['postal_code'] + assert response.customer.region == body.get('customer')['region'] + assert response.customer.swedish_identity_number == body.get('customer')['swedish_identity_number'] + assert response.links.bank_account == body.get('links')['bank_account'] + assert response.links.customer == body.get('links')['customer'] + assert response.links.mandate == body.get('links')['mandate'] + assert response.mandate.metadata == body.get('mandate')['metadata'] + assert response.mandate.payer_ip_address == body.get('mandate')['payer_ip_address'] + assert response.mandate.reference == body.get('mandate')['reference'] + assert response.mandate.scheme == body.get('mandate')['scheme'] def test_timeout_payer_authorisations_submit_doesnt_retry(): fixture = helpers.load_fixture('payer_authorisations')['submit'] with helpers.stub_timeout(fixture) as rsps: - with assert_raises(requests.ConnectTimeout): + with pytest.raises(requests.ConnectTimeout): response = helpers.client.payer_authorisations.submit(*fixture['url_params']) - assert_equal(1, len(rsps.calls)) + assert len(rsps.calls) == 1 def test_502_payer_authorisations_submit_doesnt_retry(): fixture = helpers.load_fixture('payer_authorisations')['submit'] with helpers.stub_502(fixture) as rsps: - with assert_raises(MalformedResponseError): + with pytest.raises(MalformedResponseError): response = helpers.client.payer_authorisations.submit(*fixture['url_params']) - assert_equal(1, len(rsps.calls)) + assert len(rsps.calls) == 1 @responses.activate @@ -455,90 +309,57 @@ def test_payer_authorisations_confirm(): response = helpers.client.payer_authorisations.confirm(*fixture['url_params']) body = fixture['body']['payer_authorisations'] - assert_is_instance(response, resources.PayerAuthorisation) - assert_is_not_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal(response.created_at, body.get('created_at')) - assert_equal(response.id, body.get('id')) - assert_equal(response.incomplete_fields, body.get('incomplete_fields')) - assert_equal(response.status, body.get('status')) - assert_equal(response.bank_account.account_holder_name, - body.get('bank_account')['account_holder_name']) - assert_equal(response.bank_account.account_number, - body.get('bank_account')['account_number']) - assert_equal(response.bank_account.account_number_ending, - body.get('bank_account')['account_number_ending']) - assert_equal(response.bank_account.account_number_suffix, - body.get('bank_account')['account_number_suffix']) - assert_equal(response.bank_account.account_type, - body.get('bank_account')['account_type']) - assert_equal(response.bank_account.bank_code, - body.get('bank_account')['bank_code']) - assert_equal(response.bank_account.branch_code, - body.get('bank_account')['branch_code']) - assert_equal(response.bank_account.country_code, - body.get('bank_account')['country_code']) - assert_equal(response.bank_account.currency, - body.get('bank_account')['currency']) - assert_equal(response.bank_account.iban, - body.get('bank_account')['iban']) - assert_equal(response.bank_account.metadata, - body.get('bank_account')['metadata']) - assert_equal(response.customer.address_line1, - body.get('customer')['address_line1']) - assert_equal(response.customer.address_line2, - body.get('customer')['address_line2']) - assert_equal(response.customer.address_line3, - body.get('customer')['address_line3']) - assert_equal(response.customer.city, - body.get('customer')['city']) - assert_equal(response.customer.company_name, - body.get('customer')['company_name']) - assert_equal(response.customer.country_code, - body.get('customer')['country_code']) - assert_equal(response.customer.danish_identity_number, - body.get('customer')['danish_identity_number']) - assert_equal(response.customer.email, - body.get('customer')['email']) - assert_equal(response.customer.family_name, - body.get('customer')['family_name']) - assert_equal(response.customer.given_name, - body.get('customer')['given_name']) - assert_equal(response.customer.locale, - body.get('customer')['locale']) - assert_equal(response.customer.metadata, - body.get('customer')['metadata']) - assert_equal(response.customer.postal_code, - body.get('customer')['postal_code']) - assert_equal(response.customer.region, - body.get('customer')['region']) - assert_equal(response.customer.swedish_identity_number, - body.get('customer')['swedish_identity_number']) - assert_equal(response.links.bank_account, - body.get('links')['bank_account']) - assert_equal(response.links.customer, - body.get('links')['customer']) - assert_equal(response.links.mandate, - body.get('links')['mandate']) - assert_equal(response.mandate.metadata, - body.get('mandate')['metadata']) - assert_equal(response.mandate.payer_ip_address, - body.get('mandate')['payer_ip_address']) - assert_equal(response.mandate.reference, - body.get('mandate')['reference']) - assert_equal(response.mandate.scheme, - body.get('mandate')['scheme']) + assert isinstance(response, resources.PayerAuthorisation) + assert responses.calls[-1].request.headers.get('Idempotency-Key') is not None + assert response.created_at == body.get('created_at') + assert response.id == body.get('id') + assert response.incomplete_fields == body.get('incomplete_fields') + assert response.status == body.get('status') + assert response.bank_account.account_holder_name == body.get('bank_account')['account_holder_name'] + assert response.bank_account.account_number == body.get('bank_account')['account_number'] + assert response.bank_account.account_number_ending == body.get('bank_account')['account_number_ending'] + assert response.bank_account.account_number_suffix == body.get('bank_account')['account_number_suffix'] + assert response.bank_account.account_type == body.get('bank_account')['account_type'] + assert response.bank_account.bank_code == body.get('bank_account')['bank_code'] + assert response.bank_account.branch_code == body.get('bank_account')['branch_code'] + assert response.bank_account.country_code == body.get('bank_account')['country_code'] + assert response.bank_account.currency == body.get('bank_account')['currency'] + assert response.bank_account.iban == body.get('bank_account')['iban'] + assert response.bank_account.metadata == body.get('bank_account')['metadata'] + assert response.customer.address_line1 == body.get('customer')['address_line1'] + assert response.customer.address_line2 == body.get('customer')['address_line2'] + assert response.customer.address_line3 == body.get('customer')['address_line3'] + assert response.customer.city == body.get('customer')['city'] + assert response.customer.company_name == body.get('customer')['company_name'] + assert response.customer.country_code == body.get('customer')['country_code'] + assert response.customer.danish_identity_number == body.get('customer')['danish_identity_number'] + assert response.customer.email == body.get('customer')['email'] + assert response.customer.family_name == body.get('customer')['family_name'] + assert response.customer.given_name == body.get('customer')['given_name'] + assert response.customer.locale == body.get('customer')['locale'] + assert response.customer.metadata == body.get('customer')['metadata'] + assert response.customer.postal_code == body.get('customer')['postal_code'] + assert response.customer.region == body.get('customer')['region'] + assert response.customer.swedish_identity_number == body.get('customer')['swedish_identity_number'] + assert response.links.bank_account == body.get('links')['bank_account'] + assert response.links.customer == body.get('links')['customer'] + assert response.links.mandate == body.get('links')['mandate'] + assert response.mandate.metadata == body.get('mandate')['metadata'] + assert response.mandate.payer_ip_address == body.get('mandate')['payer_ip_address'] + assert response.mandate.reference == body.get('mandate')['reference'] + assert response.mandate.scheme == body.get('mandate')['scheme'] def test_timeout_payer_authorisations_confirm_doesnt_retry(): fixture = helpers.load_fixture('payer_authorisations')['confirm'] with helpers.stub_timeout(fixture) as rsps: - with assert_raises(requests.ConnectTimeout): + with pytest.raises(requests.ConnectTimeout): response = helpers.client.payer_authorisations.confirm(*fixture['url_params']) - assert_equal(1, len(rsps.calls)) + assert len(rsps.calls) == 1 def test_502_payer_authorisations_confirm_doesnt_retry(): fixture = helpers.load_fixture('payer_authorisations')['confirm'] with helpers.stub_502(fixture) as rsps: - with assert_raises(MalformedResponseError): + with pytest.raises(MalformedResponseError): response = helpers.client.payer_authorisations.confirm(*fixture['url_params']) - assert_equal(1, len(rsps.calls)) + assert len(rsps.calls) == 1 diff --git a/tests/integration/payments_integration_test.py b/tests/integration/payments_integration_test.py index 8f249558..39da1727 100644 --- a/tests/integration/payments_integration_test.py +++ b/tests/integration/payments_integration_test.py @@ -5,16 +5,9 @@ import json +import pytest import requests import responses -from nose.tools import ( - assert_equal, - assert_is_instance, - assert_is_none, - assert_is_not_none, - assert_not_equal, - assert_raises -) from gocardless_pro.errors import MalformedResponseError from gocardless_pro import resources @@ -30,37 +23,28 @@ def test_payments_create(): response = helpers.client.payments.create(*fixture['url_params']) body = fixture['body']['payments'] - assert_is_instance(response, resources.Payment) - assert_is_not_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal(response.amount, body.get('amount')) - assert_equal(response.amount_refunded, body.get('amount_refunded')) - assert_equal(response.charge_date, body.get('charge_date')) - assert_equal(response.created_at, body.get('created_at')) - assert_equal(response.currency, body.get('currency')) - assert_equal(response.description, body.get('description')) - assert_equal(response.id, body.get('id')) - assert_equal(response.metadata, body.get('metadata')) - assert_equal(response.reference, body.get('reference')) - assert_equal(response.retry_if_possible, body.get('retry_if_possible')) - assert_equal(response.status, body.get('status')) - assert_equal(response.fx.estimated_exchange_rate, - body.get('fx')['estimated_exchange_rate']) - assert_equal(response.fx.exchange_rate, - body.get('fx')['exchange_rate']) - assert_equal(response.fx.fx_amount, - body.get('fx')['fx_amount']) - assert_equal(response.fx.fx_currency, - body.get('fx')['fx_currency']) - assert_equal(response.links.creditor, - body.get('links')['creditor']) - assert_equal(response.links.instalment_schedule, - body.get('links')['instalment_schedule']) - assert_equal(response.links.mandate, - body.get('links')['mandate']) - assert_equal(response.links.payout, - body.get('links')['payout']) - assert_equal(response.links.subscription, - body.get('links')['subscription']) + assert isinstance(response, resources.Payment) + assert responses.calls[-1].request.headers.get('Idempotency-Key') is not None + assert response.amount == body.get('amount') + assert response.amount_refunded == body.get('amount_refunded') + assert response.charge_date == body.get('charge_date') + assert response.created_at == body.get('created_at') + assert response.currency == body.get('currency') + assert response.description == body.get('description') + assert response.id == body.get('id') + assert response.metadata == body.get('metadata') + assert response.reference == body.get('reference') + assert response.retry_if_possible == body.get('retry_if_possible') + assert response.status == body.get('status') + assert response.fx.estimated_exchange_rate == body.get('fx')['estimated_exchange_rate'] + assert response.fx.exchange_rate == body.get('fx')['exchange_rate'] + assert response.fx.fx_amount == body.get('fx')['fx_amount'] + assert response.fx.fx_currency == body.get('fx')['fx_currency'] + assert response.links.creditor == body.get('links')['creditor'] + assert response.links.instalment_schedule == body.get('links')['instalment_schedule'] + assert response.links.mandate == body.get('links')['mandate'] + assert response.links.payout == body.get('links')['payout'] + assert response.links.subscription == body.get('links')['subscription'] @responses.activate def test_payments_create_new_idempotency_key_for_each_call(): @@ -68,40 +52,37 @@ def test_payments_create_new_idempotency_key_for_each_call(): helpers.stub_response(fixture) helpers.client.payments.create(*fixture['url_params']) helpers.client.payments.create(*fixture['url_params']) - assert_not_equal(responses.calls[0].request.headers.get('Idempotency-Key'), - responses.calls[1].request.headers.get('Idempotency-Key')) + assert responses.calls[0].request.headers.get('Idempotency-Key') != responses.calls[1].request.headers.get('Idempotency-Key') def test_timeout_payments_create_idempotency_conflict(): create_fixture = helpers.load_fixture('payments')['create'] get_fixture = helpers.load_fixture('payments')['get'] with helpers.stub_timeout_then_idempotency_conflict(create_fixture, get_fixture) as rsps: response = helpers.client.payments.create(*create_fixture['url_params']) - assert_equal(2, len(rsps.calls)) + assert len(rsps.calls) == 2 - assert_is_instance(response, resources.Payment) + assert isinstance(response, resources.Payment) @responses.activate def test_timeout_payments_create_retries(): fixture = helpers.load_fixture('payments')['create'] with helpers.stub_timeout_then_response(fixture) as rsps: response = helpers.client.payments.create(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['payments'] - assert_is_instance(response, resources.Payment) + assert isinstance(response, resources.Payment) def test_502_payments_create_retries(): fixture = helpers.load_fixture('payments')['create'] with helpers.stub_502_then_response(fixture) as rsps: response = helpers.client.payments.create(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['payments'] - assert_is_instance(response, resources.Payment) + assert isinstance(response, resources.Payment) @responses.activate @@ -111,65 +92,52 @@ def test_payments_list(): response = helpers.client.payments.list(*fixture['url_params']) body = fixture['body']['payments'] - assert_is_instance(response, list_response.ListResponse) - assert_is_instance(response.records[0], resources.Payment) - - assert_equal(response.before, fixture['body']['meta']['cursors']['before']) - assert_equal(response.after, fixture['body']['meta']['cursors']['after']) - assert_is_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal([r.amount for r in response.records], - [b.get('amount') for b in body]) - assert_equal([r.amount_refunded for r in response.records], - [b.get('amount_refunded') for b in body]) - assert_equal([r.charge_date for r in response.records], - [b.get('charge_date') for b in body]) - assert_equal([r.created_at for r in response.records], - [b.get('created_at') for b in body]) - assert_equal([r.currency for r in response.records], - [b.get('currency') for b in body]) - assert_equal([r.description for r in response.records], - [b.get('description') for b in body]) - assert_equal([r.id for r in response.records], - [b.get('id') for b in body]) - assert_equal([r.metadata for r in response.records], - [b.get('metadata') for b in body]) - assert_equal([r.reference for r in response.records], - [b.get('reference') for b in body]) - assert_equal([r.retry_if_possible for r in response.records], - [b.get('retry_if_possible') for b in body]) - assert_equal([r.status for r in response.records], - [b.get('status') for b in body]) + assert isinstance(response, list_response.ListResponse) + assert isinstance(response.records[0], resources.Payment) + + assert response.before == fixture['body']['meta']['cursors']['before'] + assert response.after == fixture['body']['meta']['cursors']['after'] + assert responses.calls[-1].request.headers.get('Idempotency-Key') is None + assert [r.amount for r in response.records] == [b.get('amount') for b in body] + assert [r.amount_refunded for r in response.records] == [b.get('amount_refunded') for b in body] + assert [r.charge_date for r in response.records] == [b.get('charge_date') for b in body] + assert [r.created_at for r in response.records] == [b.get('created_at') for b in body] + assert [r.currency for r in response.records] == [b.get('currency') for b in body] + assert [r.description for r in response.records] == [b.get('description') for b in body] + assert [r.id for r in response.records] == [b.get('id') for b in body] + assert [r.metadata for r in response.records] == [b.get('metadata') for b in body] + assert [r.reference for r in response.records] == [b.get('reference') for b in body] + assert [r.retry_if_possible for r in response.records] == [b.get('retry_if_possible') for b in body] + assert [r.status for r in response.records] == [b.get('status') for b in body] @responses.activate def test_timeout_payments_list_retries(): fixture = helpers.load_fixture('payments')['list'] with helpers.stub_timeout_then_response(fixture) as rsps: response = helpers.client.payments.list(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['payments'] - assert_is_instance(response, list_response.ListResponse) - assert_is_instance(response.records[0], resources.Payment) + assert isinstance(response, list_response.ListResponse) + assert isinstance(response.records[0], resources.Payment) - assert_equal(response.before, fixture['body']['meta']['cursors']['before']) - assert_equal(response.after, fixture['body']['meta']['cursors']['after']) + assert response.before == fixture['body']['meta']['cursors']['before'] + assert response.after == fixture['body']['meta']['cursors']['after'] def test_502_payments_list_retries(): fixture = helpers.load_fixture('payments')['list'] with helpers.stub_502_then_response(fixture) as rsps: response = helpers.client.payments.list(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['payments'] - assert_is_instance(response, list_response.ListResponse) - assert_is_instance(response.records[0], resources.Payment) + assert isinstance(response, list_response.ListResponse) + assert isinstance(response.records[0], resources.Payment) - assert_equal(response.before, fixture['body']['meta']['cursors']['before']) - assert_equal(response.after, fixture['body']['meta']['cursors']['after']) + assert response.before == fixture['body']['meta']['cursors']['before'] + assert response.after == fixture['body']['meta']['cursors']['after'] @responses.activate def test_payments_all(): @@ -186,9 +154,9 @@ def callback(request): responses.add_callback(fixture['method'], url, callback) all_records = list(helpers.client.payments.all()) - assert_equal(len(all_records), len(fixture['body']['payments']) * 2) + assert len(all_records) == len(fixture['body']['payments']) * 2 for record in all_records: - assert_is_instance(record, resources.Payment) + assert isinstance(record, resources.Payment) @@ -199,60 +167,49 @@ def test_payments_get(): response = helpers.client.payments.get(*fixture['url_params']) body = fixture['body']['payments'] - assert_is_instance(response, resources.Payment) - assert_is_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal(response.amount, body.get('amount')) - assert_equal(response.amount_refunded, body.get('amount_refunded')) - assert_equal(response.charge_date, body.get('charge_date')) - assert_equal(response.created_at, body.get('created_at')) - assert_equal(response.currency, body.get('currency')) - assert_equal(response.description, body.get('description')) - assert_equal(response.id, body.get('id')) - assert_equal(response.metadata, body.get('metadata')) - assert_equal(response.reference, body.get('reference')) - assert_equal(response.retry_if_possible, body.get('retry_if_possible')) - assert_equal(response.status, body.get('status')) - assert_equal(response.fx.estimated_exchange_rate, - body.get('fx')['estimated_exchange_rate']) - assert_equal(response.fx.exchange_rate, - body.get('fx')['exchange_rate']) - assert_equal(response.fx.fx_amount, - body.get('fx')['fx_amount']) - assert_equal(response.fx.fx_currency, - body.get('fx')['fx_currency']) - assert_equal(response.links.creditor, - body.get('links')['creditor']) - assert_equal(response.links.instalment_schedule, - body.get('links')['instalment_schedule']) - assert_equal(response.links.mandate, - body.get('links')['mandate']) - assert_equal(response.links.payout, - body.get('links')['payout']) - assert_equal(response.links.subscription, - body.get('links')['subscription']) + assert isinstance(response, resources.Payment) + assert responses.calls[-1].request.headers.get('Idempotency-Key') is None + assert response.amount == body.get('amount') + assert response.amount_refunded == body.get('amount_refunded') + assert response.charge_date == body.get('charge_date') + assert response.created_at == body.get('created_at') + assert response.currency == body.get('currency') + assert response.description == body.get('description') + assert response.id == body.get('id') + assert response.metadata == body.get('metadata') + assert response.reference == body.get('reference') + assert response.retry_if_possible == body.get('retry_if_possible') + assert response.status == body.get('status') + assert response.fx.estimated_exchange_rate == body.get('fx')['estimated_exchange_rate'] + assert response.fx.exchange_rate == body.get('fx')['exchange_rate'] + assert response.fx.fx_amount == body.get('fx')['fx_amount'] + assert response.fx.fx_currency == body.get('fx')['fx_currency'] + assert response.links.creditor == body.get('links')['creditor'] + assert response.links.instalment_schedule == body.get('links')['instalment_schedule'] + assert response.links.mandate == body.get('links')['mandate'] + assert response.links.payout == body.get('links')['payout'] + assert response.links.subscription == body.get('links')['subscription'] @responses.activate def test_timeout_payments_get_retries(): fixture = helpers.load_fixture('payments')['get'] with helpers.stub_timeout_then_response(fixture) as rsps: response = helpers.client.payments.get(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['payments'] - assert_is_instance(response, resources.Payment) + assert isinstance(response, resources.Payment) def test_502_payments_get_retries(): fixture = helpers.load_fixture('payments')['get'] with helpers.stub_502_then_response(fixture) as rsps: response = helpers.client.payments.get(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['payments'] - assert_is_instance(response, resources.Payment) + assert isinstance(response, resources.Payment) @responses.activate @@ -262,60 +219,49 @@ def test_payments_update(): response = helpers.client.payments.update(*fixture['url_params']) body = fixture['body']['payments'] - assert_is_instance(response, resources.Payment) - assert_is_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal(response.amount, body.get('amount')) - assert_equal(response.amount_refunded, body.get('amount_refunded')) - assert_equal(response.charge_date, body.get('charge_date')) - assert_equal(response.created_at, body.get('created_at')) - assert_equal(response.currency, body.get('currency')) - assert_equal(response.description, body.get('description')) - assert_equal(response.id, body.get('id')) - assert_equal(response.metadata, body.get('metadata')) - assert_equal(response.reference, body.get('reference')) - assert_equal(response.retry_if_possible, body.get('retry_if_possible')) - assert_equal(response.status, body.get('status')) - assert_equal(response.fx.estimated_exchange_rate, - body.get('fx')['estimated_exchange_rate']) - assert_equal(response.fx.exchange_rate, - body.get('fx')['exchange_rate']) - assert_equal(response.fx.fx_amount, - body.get('fx')['fx_amount']) - assert_equal(response.fx.fx_currency, - body.get('fx')['fx_currency']) - assert_equal(response.links.creditor, - body.get('links')['creditor']) - assert_equal(response.links.instalment_schedule, - body.get('links')['instalment_schedule']) - assert_equal(response.links.mandate, - body.get('links')['mandate']) - assert_equal(response.links.payout, - body.get('links')['payout']) - assert_equal(response.links.subscription, - body.get('links')['subscription']) + assert isinstance(response, resources.Payment) + assert responses.calls[-1].request.headers.get('Idempotency-Key') is None + assert response.amount == body.get('amount') + assert response.amount_refunded == body.get('amount_refunded') + assert response.charge_date == body.get('charge_date') + assert response.created_at == body.get('created_at') + assert response.currency == body.get('currency') + assert response.description == body.get('description') + assert response.id == body.get('id') + assert response.metadata == body.get('metadata') + assert response.reference == body.get('reference') + assert response.retry_if_possible == body.get('retry_if_possible') + assert response.status == body.get('status') + assert response.fx.estimated_exchange_rate == body.get('fx')['estimated_exchange_rate'] + assert response.fx.exchange_rate == body.get('fx')['exchange_rate'] + assert response.fx.fx_amount == body.get('fx')['fx_amount'] + assert response.fx.fx_currency == body.get('fx')['fx_currency'] + assert response.links.creditor == body.get('links')['creditor'] + assert response.links.instalment_schedule == body.get('links')['instalment_schedule'] + assert response.links.mandate == body.get('links')['mandate'] + assert response.links.payout == body.get('links')['payout'] + assert response.links.subscription == body.get('links')['subscription'] @responses.activate def test_timeout_payments_update_retries(): fixture = helpers.load_fixture('payments')['update'] with helpers.stub_timeout_then_response(fixture) as rsps: response = helpers.client.payments.update(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['payments'] - assert_is_instance(response, resources.Payment) + assert isinstance(response, resources.Payment) def test_502_payments_update_retries(): fixture = helpers.load_fixture('payments')['update'] with helpers.stub_502_then_response(fixture) as rsps: response = helpers.client.payments.update(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['payments'] - assert_is_instance(response, resources.Payment) + assert isinstance(response, resources.Payment) @responses.activate @@ -325,51 +271,42 @@ def test_payments_cancel(): response = helpers.client.payments.cancel(*fixture['url_params']) body = fixture['body']['payments'] - assert_is_instance(response, resources.Payment) - assert_is_not_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal(response.amount, body.get('amount')) - assert_equal(response.amount_refunded, body.get('amount_refunded')) - assert_equal(response.charge_date, body.get('charge_date')) - assert_equal(response.created_at, body.get('created_at')) - assert_equal(response.currency, body.get('currency')) - assert_equal(response.description, body.get('description')) - assert_equal(response.id, body.get('id')) - assert_equal(response.metadata, body.get('metadata')) - assert_equal(response.reference, body.get('reference')) - assert_equal(response.retry_if_possible, body.get('retry_if_possible')) - assert_equal(response.status, body.get('status')) - assert_equal(response.fx.estimated_exchange_rate, - body.get('fx')['estimated_exchange_rate']) - assert_equal(response.fx.exchange_rate, - body.get('fx')['exchange_rate']) - assert_equal(response.fx.fx_amount, - body.get('fx')['fx_amount']) - assert_equal(response.fx.fx_currency, - body.get('fx')['fx_currency']) - assert_equal(response.links.creditor, - body.get('links')['creditor']) - assert_equal(response.links.instalment_schedule, - body.get('links')['instalment_schedule']) - assert_equal(response.links.mandate, - body.get('links')['mandate']) - assert_equal(response.links.payout, - body.get('links')['payout']) - assert_equal(response.links.subscription, - body.get('links')['subscription']) + assert isinstance(response, resources.Payment) + assert responses.calls[-1].request.headers.get('Idempotency-Key') is not None + assert response.amount == body.get('amount') + assert response.amount_refunded == body.get('amount_refunded') + assert response.charge_date == body.get('charge_date') + assert response.created_at == body.get('created_at') + assert response.currency == body.get('currency') + assert response.description == body.get('description') + assert response.id == body.get('id') + assert response.metadata == body.get('metadata') + assert response.reference == body.get('reference') + assert response.retry_if_possible == body.get('retry_if_possible') + assert response.status == body.get('status') + assert response.fx.estimated_exchange_rate == body.get('fx')['estimated_exchange_rate'] + assert response.fx.exchange_rate == body.get('fx')['exchange_rate'] + assert response.fx.fx_amount == body.get('fx')['fx_amount'] + assert response.fx.fx_currency == body.get('fx')['fx_currency'] + assert response.links.creditor == body.get('links')['creditor'] + assert response.links.instalment_schedule == body.get('links')['instalment_schedule'] + assert response.links.mandate == body.get('links')['mandate'] + assert response.links.payout == body.get('links')['payout'] + assert response.links.subscription == body.get('links')['subscription'] def test_timeout_payments_cancel_doesnt_retry(): fixture = helpers.load_fixture('payments')['cancel'] with helpers.stub_timeout(fixture) as rsps: - with assert_raises(requests.ConnectTimeout): + with pytest.raises(requests.ConnectTimeout): response = helpers.client.payments.cancel(*fixture['url_params']) - assert_equal(1, len(rsps.calls)) + assert len(rsps.calls) == 1 def test_502_payments_cancel_doesnt_retry(): fixture = helpers.load_fixture('payments')['cancel'] with helpers.stub_502(fixture) as rsps: - with assert_raises(MalformedResponseError): + with pytest.raises(MalformedResponseError): response = helpers.client.payments.cancel(*fixture['url_params']) - assert_equal(1, len(rsps.calls)) + assert len(rsps.calls) == 1 @responses.activate @@ -379,49 +316,40 @@ def test_payments_retry(): response = helpers.client.payments.retry(*fixture['url_params']) body = fixture['body']['payments'] - assert_is_instance(response, resources.Payment) - assert_is_not_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal(response.amount, body.get('amount')) - assert_equal(response.amount_refunded, body.get('amount_refunded')) - assert_equal(response.charge_date, body.get('charge_date')) - assert_equal(response.created_at, body.get('created_at')) - assert_equal(response.currency, body.get('currency')) - assert_equal(response.description, body.get('description')) - assert_equal(response.id, body.get('id')) - assert_equal(response.metadata, body.get('metadata')) - assert_equal(response.reference, body.get('reference')) - assert_equal(response.retry_if_possible, body.get('retry_if_possible')) - assert_equal(response.status, body.get('status')) - assert_equal(response.fx.estimated_exchange_rate, - body.get('fx')['estimated_exchange_rate']) - assert_equal(response.fx.exchange_rate, - body.get('fx')['exchange_rate']) - assert_equal(response.fx.fx_amount, - body.get('fx')['fx_amount']) - assert_equal(response.fx.fx_currency, - body.get('fx')['fx_currency']) - assert_equal(response.links.creditor, - body.get('links')['creditor']) - assert_equal(response.links.instalment_schedule, - body.get('links')['instalment_schedule']) - assert_equal(response.links.mandate, - body.get('links')['mandate']) - assert_equal(response.links.payout, - body.get('links')['payout']) - assert_equal(response.links.subscription, - body.get('links')['subscription']) + assert isinstance(response, resources.Payment) + assert responses.calls[-1].request.headers.get('Idempotency-Key') is not None + assert response.amount == body.get('amount') + assert response.amount_refunded == body.get('amount_refunded') + assert response.charge_date == body.get('charge_date') + assert response.created_at == body.get('created_at') + assert response.currency == body.get('currency') + assert response.description == body.get('description') + assert response.id == body.get('id') + assert response.metadata == body.get('metadata') + assert response.reference == body.get('reference') + assert response.retry_if_possible == body.get('retry_if_possible') + assert response.status == body.get('status') + assert response.fx.estimated_exchange_rate == body.get('fx')['estimated_exchange_rate'] + assert response.fx.exchange_rate == body.get('fx')['exchange_rate'] + assert response.fx.fx_amount == body.get('fx')['fx_amount'] + assert response.fx.fx_currency == body.get('fx')['fx_currency'] + assert response.links.creditor == body.get('links')['creditor'] + assert response.links.instalment_schedule == body.get('links')['instalment_schedule'] + assert response.links.mandate == body.get('links')['mandate'] + assert response.links.payout == body.get('links')['payout'] + assert response.links.subscription == body.get('links')['subscription'] def test_timeout_payments_retry_doesnt_retry(): fixture = helpers.load_fixture('payments')['retry'] with helpers.stub_timeout(fixture) as rsps: - with assert_raises(requests.ConnectTimeout): + with pytest.raises(requests.ConnectTimeout): response = helpers.client.payments.retry(*fixture['url_params']) - assert_equal(1, len(rsps.calls)) + assert len(rsps.calls) == 1 def test_502_payments_retry_doesnt_retry(): fixture = helpers.load_fixture('payments')['retry'] with helpers.stub_502(fixture) as rsps: - with assert_raises(MalformedResponseError): + with pytest.raises(MalformedResponseError): response = helpers.client.payments.retry(*fixture['url_params']) - assert_equal(1, len(rsps.calls)) + assert len(rsps.calls) == 1 diff --git a/tests/integration/payout_items_integration_test.py b/tests/integration/payout_items_integration_test.py index e0f72dea..c3f13af9 100644 --- a/tests/integration/payout_items_integration_test.py +++ b/tests/integration/payout_items_integration_test.py @@ -5,16 +5,9 @@ import json +import pytest import requests import responses -from nose.tools import ( - assert_equal, - assert_is_instance, - assert_is_none, - assert_is_not_none, - assert_not_equal, - assert_raises -) from gocardless_pro.errors import MalformedResponseError from gocardless_pro import resources @@ -30,49 +23,44 @@ def test_payout_items_list(): response = helpers.client.payout_items.list(*fixture['url_params']) body = fixture['body']['payout_items'] - assert_is_instance(response, list_response.ListResponse) - assert_is_instance(response.records[0], resources.PayoutItem) + assert isinstance(response, list_response.ListResponse) + assert isinstance(response.records[0], resources.PayoutItem) - assert_equal(response.before, fixture['body']['meta']['cursors']['before']) - assert_equal(response.after, fixture['body']['meta']['cursors']['after']) - assert_is_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal([r.amount for r in response.records], - [b.get('amount') for b in body]) - assert_equal([r.taxes for r in response.records], - [b.get('taxes') for b in body]) - assert_equal([r.type for r in response.records], - [b.get('type') for b in body]) + assert response.before == fixture['body']['meta']['cursors']['before'] + assert response.after == fixture['body']['meta']['cursors']['after'] + assert responses.calls[-1].request.headers.get('Idempotency-Key') is None + assert [r.amount for r in response.records] == [b.get('amount') for b in body] + assert [r.taxes for r in response.records] == [b.get('taxes') for b in body] + assert [r.type for r in response.records] == [b.get('type') for b in body] @responses.activate def test_timeout_payout_items_list_retries(): fixture = helpers.load_fixture('payout_items')['list'] with helpers.stub_timeout_then_response(fixture) as rsps: response = helpers.client.payout_items.list(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['payout_items'] - assert_is_instance(response, list_response.ListResponse) - assert_is_instance(response.records[0], resources.PayoutItem) + assert isinstance(response, list_response.ListResponse) + assert isinstance(response.records[0], resources.PayoutItem) - assert_equal(response.before, fixture['body']['meta']['cursors']['before']) - assert_equal(response.after, fixture['body']['meta']['cursors']['after']) + assert response.before == fixture['body']['meta']['cursors']['before'] + assert response.after == fixture['body']['meta']['cursors']['after'] def test_502_payout_items_list_retries(): fixture = helpers.load_fixture('payout_items')['list'] with helpers.stub_502_then_response(fixture) as rsps: response = helpers.client.payout_items.list(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['payout_items'] - assert_is_instance(response, list_response.ListResponse) - assert_is_instance(response.records[0], resources.PayoutItem) + assert isinstance(response, list_response.ListResponse) + assert isinstance(response.records[0], resources.PayoutItem) - assert_equal(response.before, fixture['body']['meta']['cursors']['before']) - assert_equal(response.after, fixture['body']['meta']['cursors']['after']) + assert response.before == fixture['body']['meta']['cursors']['before'] + assert response.after == fixture['body']['meta']['cursors']['after'] @responses.activate def test_payout_items_all(): @@ -89,8 +77,8 @@ def callback(request): responses.add_callback(fixture['method'], url, callback) all_records = list(helpers.client.payout_items.all()) - assert_equal(len(all_records), len(fixture['body']['payout_items']) * 2) + assert len(all_records) == len(fixture['body']['payout_items']) * 2 for record in all_records: - assert_is_instance(record, resources.PayoutItem) + assert isinstance(record, resources.PayoutItem) diff --git a/tests/integration/payouts_integration_test.py b/tests/integration/payouts_integration_test.py index 4d8bb0ea..51e27c9b 100644 --- a/tests/integration/payouts_integration_test.py +++ b/tests/integration/payouts_integration_test.py @@ -5,16 +5,9 @@ import json +import pytest import requests import responses -from nose.tools import ( - assert_equal, - assert_is_instance, - assert_is_none, - assert_is_not_none, - assert_not_equal, - assert_raises -) from gocardless_pro.errors import MalformedResponseError from gocardless_pro import resources @@ -30,65 +23,52 @@ def test_payouts_list(): response = helpers.client.payouts.list(*fixture['url_params']) body = fixture['body']['payouts'] - assert_is_instance(response, list_response.ListResponse) - assert_is_instance(response.records[0], resources.Payout) - - assert_equal(response.before, fixture['body']['meta']['cursors']['before']) - assert_equal(response.after, fixture['body']['meta']['cursors']['after']) - assert_is_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal([r.amount for r in response.records], - [b.get('amount') for b in body]) - assert_equal([r.arrival_date for r in response.records], - [b.get('arrival_date') for b in body]) - assert_equal([r.created_at for r in response.records], - [b.get('created_at') for b in body]) - assert_equal([r.currency for r in response.records], - [b.get('currency') for b in body]) - assert_equal([r.deducted_fees for r in response.records], - [b.get('deducted_fees') for b in body]) - assert_equal([r.id for r in response.records], - [b.get('id') for b in body]) - assert_equal([r.metadata for r in response.records], - [b.get('metadata') for b in body]) - assert_equal([r.payout_type for r in response.records], - [b.get('payout_type') for b in body]) - assert_equal([r.reference for r in response.records], - [b.get('reference') for b in body]) - assert_equal([r.status for r in response.records], - [b.get('status') for b in body]) - assert_equal([r.tax_currency for r in response.records], - [b.get('tax_currency') for b in body]) + assert isinstance(response, list_response.ListResponse) + assert isinstance(response.records[0], resources.Payout) + + assert response.before == fixture['body']['meta']['cursors']['before'] + assert response.after == fixture['body']['meta']['cursors']['after'] + assert responses.calls[-1].request.headers.get('Idempotency-Key') is None + assert [r.amount for r in response.records] == [b.get('amount') for b in body] + assert [r.arrival_date for r in response.records] == [b.get('arrival_date') for b in body] + assert [r.created_at for r in response.records] == [b.get('created_at') for b in body] + assert [r.currency for r in response.records] == [b.get('currency') for b in body] + assert [r.deducted_fees for r in response.records] == [b.get('deducted_fees') for b in body] + assert [r.id for r in response.records] == [b.get('id') for b in body] + assert [r.metadata for r in response.records] == [b.get('metadata') for b in body] + assert [r.payout_type for r in response.records] == [b.get('payout_type') for b in body] + assert [r.reference for r in response.records] == [b.get('reference') for b in body] + assert [r.status for r in response.records] == [b.get('status') for b in body] + assert [r.tax_currency for r in response.records] == [b.get('tax_currency') for b in body] @responses.activate def test_timeout_payouts_list_retries(): fixture = helpers.load_fixture('payouts')['list'] with helpers.stub_timeout_then_response(fixture) as rsps: response = helpers.client.payouts.list(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['payouts'] - assert_is_instance(response, list_response.ListResponse) - assert_is_instance(response.records[0], resources.Payout) + assert isinstance(response, list_response.ListResponse) + assert isinstance(response.records[0], resources.Payout) - assert_equal(response.before, fixture['body']['meta']['cursors']['before']) - assert_equal(response.after, fixture['body']['meta']['cursors']['after']) + assert response.before == fixture['body']['meta']['cursors']['before'] + assert response.after == fixture['body']['meta']['cursors']['after'] def test_502_payouts_list_retries(): fixture = helpers.load_fixture('payouts')['list'] with helpers.stub_502_then_response(fixture) as rsps: response = helpers.client.payouts.list(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['payouts'] - assert_is_instance(response, list_response.ListResponse) - assert_is_instance(response.records[0], resources.Payout) + assert isinstance(response, list_response.ListResponse) + assert isinstance(response.records[0], resources.Payout) - assert_equal(response.before, fixture['body']['meta']['cursors']['before']) - assert_equal(response.after, fixture['body']['meta']['cursors']['after']) + assert response.before == fixture['body']['meta']['cursors']['before'] + assert response.after == fixture['body']['meta']['cursors']['after'] @responses.activate def test_payouts_all(): @@ -105,9 +85,9 @@ def callback(request): responses.add_callback(fixture['method'], url, callback) all_records = list(helpers.client.payouts.all()) - assert_equal(len(all_records), len(fixture['body']['payouts']) * 2) + assert len(all_records) == len(fixture['body']['payouts']) * 2 for record in all_records: - assert_is_instance(record, resources.Payout) + assert isinstance(record, resources.Payout) @@ -118,54 +98,46 @@ def test_payouts_get(): response = helpers.client.payouts.get(*fixture['url_params']) body = fixture['body']['payouts'] - assert_is_instance(response, resources.Payout) - assert_is_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal(response.amount, body.get('amount')) - assert_equal(response.arrival_date, body.get('arrival_date')) - assert_equal(response.created_at, body.get('created_at')) - assert_equal(response.currency, body.get('currency')) - assert_equal(response.deducted_fees, body.get('deducted_fees')) - assert_equal(response.id, body.get('id')) - assert_equal(response.metadata, body.get('metadata')) - assert_equal(response.payout_type, body.get('payout_type')) - assert_equal(response.reference, body.get('reference')) - assert_equal(response.status, body.get('status')) - assert_equal(response.tax_currency, body.get('tax_currency')) - assert_equal(response.fx.estimated_exchange_rate, - body.get('fx')['estimated_exchange_rate']) - assert_equal(response.fx.exchange_rate, - body.get('fx')['exchange_rate']) - assert_equal(response.fx.fx_amount, - body.get('fx')['fx_amount']) - assert_equal(response.fx.fx_currency, - body.get('fx')['fx_currency']) - assert_equal(response.links.creditor, - body.get('links')['creditor']) - assert_equal(response.links.creditor_bank_account, - body.get('links')['creditor_bank_account']) + assert isinstance(response, resources.Payout) + assert responses.calls[-1].request.headers.get('Idempotency-Key') is None + assert response.amount == body.get('amount') + assert response.arrival_date == body.get('arrival_date') + assert response.created_at == body.get('created_at') + assert response.currency == body.get('currency') + assert response.deducted_fees == body.get('deducted_fees') + assert response.id == body.get('id') + assert response.metadata == body.get('metadata') + assert response.payout_type == body.get('payout_type') + assert response.reference == body.get('reference') + assert response.status == body.get('status') + assert response.tax_currency == body.get('tax_currency') + assert response.fx.estimated_exchange_rate == body.get('fx')['estimated_exchange_rate'] + assert response.fx.exchange_rate == body.get('fx')['exchange_rate'] + assert response.fx.fx_amount == body.get('fx')['fx_amount'] + assert response.fx.fx_currency == body.get('fx')['fx_currency'] + assert response.links.creditor == body.get('links')['creditor'] + assert response.links.creditor_bank_account == body.get('links')['creditor_bank_account'] @responses.activate def test_timeout_payouts_get_retries(): fixture = helpers.load_fixture('payouts')['get'] with helpers.stub_timeout_then_response(fixture) as rsps: response = helpers.client.payouts.get(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['payouts'] - assert_is_instance(response, resources.Payout) + assert isinstance(response, resources.Payout) def test_502_payouts_get_retries(): fixture = helpers.load_fixture('payouts')['get'] with helpers.stub_502_then_response(fixture) as rsps: response = helpers.client.payouts.get(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['payouts'] - assert_is_instance(response, resources.Payout) + assert isinstance(response, resources.Payout) @responses.activate @@ -175,52 +147,44 @@ def test_payouts_update(): response = helpers.client.payouts.update(*fixture['url_params']) body = fixture['body']['payouts'] - assert_is_instance(response, resources.Payout) - assert_is_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal(response.amount, body.get('amount')) - assert_equal(response.arrival_date, body.get('arrival_date')) - assert_equal(response.created_at, body.get('created_at')) - assert_equal(response.currency, body.get('currency')) - assert_equal(response.deducted_fees, body.get('deducted_fees')) - assert_equal(response.id, body.get('id')) - assert_equal(response.metadata, body.get('metadata')) - assert_equal(response.payout_type, body.get('payout_type')) - assert_equal(response.reference, body.get('reference')) - assert_equal(response.status, body.get('status')) - assert_equal(response.tax_currency, body.get('tax_currency')) - assert_equal(response.fx.estimated_exchange_rate, - body.get('fx')['estimated_exchange_rate']) - assert_equal(response.fx.exchange_rate, - body.get('fx')['exchange_rate']) - assert_equal(response.fx.fx_amount, - body.get('fx')['fx_amount']) - assert_equal(response.fx.fx_currency, - body.get('fx')['fx_currency']) - assert_equal(response.links.creditor, - body.get('links')['creditor']) - assert_equal(response.links.creditor_bank_account, - body.get('links')['creditor_bank_account']) + assert isinstance(response, resources.Payout) + assert responses.calls[-1].request.headers.get('Idempotency-Key') is None + assert response.amount == body.get('amount') + assert response.arrival_date == body.get('arrival_date') + assert response.created_at == body.get('created_at') + assert response.currency == body.get('currency') + assert response.deducted_fees == body.get('deducted_fees') + assert response.id == body.get('id') + assert response.metadata == body.get('metadata') + assert response.payout_type == body.get('payout_type') + assert response.reference == body.get('reference') + assert response.status == body.get('status') + assert response.tax_currency == body.get('tax_currency') + assert response.fx.estimated_exchange_rate == body.get('fx')['estimated_exchange_rate'] + assert response.fx.exchange_rate == body.get('fx')['exchange_rate'] + assert response.fx.fx_amount == body.get('fx')['fx_amount'] + assert response.fx.fx_currency == body.get('fx')['fx_currency'] + assert response.links.creditor == body.get('links')['creditor'] + assert response.links.creditor_bank_account == body.get('links')['creditor_bank_account'] @responses.activate def test_timeout_payouts_update_retries(): fixture = helpers.load_fixture('payouts')['update'] with helpers.stub_timeout_then_response(fixture) as rsps: response = helpers.client.payouts.update(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['payouts'] - assert_is_instance(response, resources.Payout) + assert isinstance(response, resources.Payout) def test_502_payouts_update_retries(): fixture = helpers.load_fixture('payouts')['update'] with helpers.stub_502_then_response(fixture) as rsps: response = helpers.client.payouts.update(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['payouts'] - assert_is_instance(response, resources.Payout) + assert isinstance(response, resources.Payout) diff --git a/tests/integration/redirect_flows_integration_test.py b/tests/integration/redirect_flows_integration_test.py index 534a948b..56854243 100644 --- a/tests/integration/redirect_flows_integration_test.py +++ b/tests/integration/redirect_flows_integration_test.py @@ -5,16 +5,9 @@ import json +import pytest import requests import responses -from nose.tools import ( - assert_equal, - assert_is_instance, - assert_is_none, - assert_is_not_none, - assert_not_equal, - assert_raises -) from gocardless_pro.errors import MalformedResponseError from gocardless_pro import resources @@ -30,28 +23,23 @@ def test_redirect_flows_create(): response = helpers.client.redirect_flows.create(*fixture['url_params']) body = fixture['body']['redirect_flows'] - assert_is_instance(response, resources.RedirectFlow) - assert_is_not_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal(response.confirmation_url, body.get('confirmation_url')) - assert_equal(response.created_at, body.get('created_at')) - assert_equal(response.description, body.get('description')) - assert_equal(response.id, body.get('id')) - assert_equal(response.mandate_reference, body.get('mandate_reference')) - assert_equal(response.metadata, body.get('metadata')) - assert_equal(response.redirect_url, body.get('redirect_url')) - assert_equal(response.scheme, body.get('scheme')) - assert_equal(response.session_token, body.get('session_token')) - assert_equal(response.success_redirect_url, body.get('success_redirect_url')) - assert_equal(response.links.billing_request, - body.get('links')['billing_request']) - assert_equal(response.links.creditor, - body.get('links')['creditor']) - assert_equal(response.links.customer, - body.get('links')['customer']) - assert_equal(response.links.customer_bank_account, - body.get('links')['customer_bank_account']) - assert_equal(response.links.mandate, - body.get('links')['mandate']) + assert isinstance(response, resources.RedirectFlow) + assert responses.calls[-1].request.headers.get('Idempotency-Key') is not None + assert response.confirmation_url == body.get('confirmation_url') + assert response.created_at == body.get('created_at') + assert response.description == body.get('description') + assert response.id == body.get('id') + assert response.mandate_reference == body.get('mandate_reference') + assert response.metadata == body.get('metadata') + assert response.redirect_url == body.get('redirect_url') + assert response.scheme == body.get('scheme') + assert response.session_token == body.get('session_token') + assert response.success_redirect_url == body.get('success_redirect_url') + assert response.links.billing_request == body.get('links')['billing_request'] + assert response.links.creditor == body.get('links')['creditor'] + assert response.links.customer == body.get('links')['customer'] + assert response.links.customer_bank_account == body.get('links')['customer_bank_account'] + assert response.links.mandate == body.get('links')['mandate'] @responses.activate def test_redirect_flows_create_new_idempotency_key_for_each_call(): @@ -59,40 +47,37 @@ def test_redirect_flows_create_new_idempotency_key_for_each_call(): helpers.stub_response(fixture) helpers.client.redirect_flows.create(*fixture['url_params']) helpers.client.redirect_flows.create(*fixture['url_params']) - assert_not_equal(responses.calls[0].request.headers.get('Idempotency-Key'), - responses.calls[1].request.headers.get('Idempotency-Key')) + assert responses.calls[0].request.headers.get('Idempotency-Key') != responses.calls[1].request.headers.get('Idempotency-Key') def test_timeout_redirect_flows_create_idempotency_conflict(): create_fixture = helpers.load_fixture('redirect_flows')['create'] get_fixture = helpers.load_fixture('redirect_flows')['get'] with helpers.stub_timeout_then_idempotency_conflict(create_fixture, get_fixture) as rsps: response = helpers.client.redirect_flows.create(*create_fixture['url_params']) - assert_equal(2, len(rsps.calls)) + assert len(rsps.calls) == 2 - assert_is_instance(response, resources.RedirectFlow) + assert isinstance(response, resources.RedirectFlow) @responses.activate def test_timeout_redirect_flows_create_retries(): fixture = helpers.load_fixture('redirect_flows')['create'] with helpers.stub_timeout_then_response(fixture) as rsps: response = helpers.client.redirect_flows.create(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['redirect_flows'] - assert_is_instance(response, resources.RedirectFlow) + assert isinstance(response, resources.RedirectFlow) def test_502_redirect_flows_create_retries(): fixture = helpers.load_fixture('redirect_flows')['create'] with helpers.stub_502_then_response(fixture) as rsps: response = helpers.client.redirect_flows.create(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['redirect_flows'] - assert_is_instance(response, resources.RedirectFlow) + assert isinstance(response, resources.RedirectFlow) @responses.activate @@ -102,51 +87,44 @@ def test_redirect_flows_get(): response = helpers.client.redirect_flows.get(*fixture['url_params']) body = fixture['body']['redirect_flows'] - assert_is_instance(response, resources.RedirectFlow) - assert_is_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal(response.confirmation_url, body.get('confirmation_url')) - assert_equal(response.created_at, body.get('created_at')) - assert_equal(response.description, body.get('description')) - assert_equal(response.id, body.get('id')) - assert_equal(response.mandate_reference, body.get('mandate_reference')) - assert_equal(response.metadata, body.get('metadata')) - assert_equal(response.redirect_url, body.get('redirect_url')) - assert_equal(response.scheme, body.get('scheme')) - assert_equal(response.session_token, body.get('session_token')) - assert_equal(response.success_redirect_url, body.get('success_redirect_url')) - assert_equal(response.links.billing_request, - body.get('links')['billing_request']) - assert_equal(response.links.creditor, - body.get('links')['creditor']) - assert_equal(response.links.customer, - body.get('links')['customer']) - assert_equal(response.links.customer_bank_account, - body.get('links')['customer_bank_account']) - assert_equal(response.links.mandate, - body.get('links')['mandate']) + assert isinstance(response, resources.RedirectFlow) + assert responses.calls[-1].request.headers.get('Idempotency-Key') is None + assert response.confirmation_url == body.get('confirmation_url') + assert response.created_at == body.get('created_at') + assert response.description == body.get('description') + assert response.id == body.get('id') + assert response.mandate_reference == body.get('mandate_reference') + assert response.metadata == body.get('metadata') + assert response.redirect_url == body.get('redirect_url') + assert response.scheme == body.get('scheme') + assert response.session_token == body.get('session_token') + assert response.success_redirect_url == body.get('success_redirect_url') + assert response.links.billing_request == body.get('links')['billing_request'] + assert response.links.creditor == body.get('links')['creditor'] + assert response.links.customer == body.get('links')['customer'] + assert response.links.customer_bank_account == body.get('links')['customer_bank_account'] + assert response.links.mandate == body.get('links')['mandate'] @responses.activate def test_timeout_redirect_flows_get_retries(): fixture = helpers.load_fixture('redirect_flows')['get'] with helpers.stub_timeout_then_response(fixture) as rsps: response = helpers.client.redirect_flows.get(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['redirect_flows'] - assert_is_instance(response, resources.RedirectFlow) + assert isinstance(response, resources.RedirectFlow) def test_502_redirect_flows_get_retries(): fixture = helpers.load_fixture('redirect_flows')['get'] with helpers.stub_502_then_response(fixture) as rsps: response = helpers.client.redirect_flows.get(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['redirect_flows'] - assert_is_instance(response, resources.RedirectFlow) + assert isinstance(response, resources.RedirectFlow) @responses.activate @@ -156,40 +134,35 @@ def test_redirect_flows_complete(): response = helpers.client.redirect_flows.complete(*fixture['url_params']) body = fixture['body']['redirect_flows'] - assert_is_instance(response, resources.RedirectFlow) - assert_is_not_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal(response.confirmation_url, body.get('confirmation_url')) - assert_equal(response.created_at, body.get('created_at')) - assert_equal(response.description, body.get('description')) - assert_equal(response.id, body.get('id')) - assert_equal(response.mandate_reference, body.get('mandate_reference')) - assert_equal(response.metadata, body.get('metadata')) - assert_equal(response.redirect_url, body.get('redirect_url')) - assert_equal(response.scheme, body.get('scheme')) - assert_equal(response.session_token, body.get('session_token')) - assert_equal(response.success_redirect_url, body.get('success_redirect_url')) - assert_equal(response.links.billing_request, - body.get('links')['billing_request']) - assert_equal(response.links.creditor, - body.get('links')['creditor']) - assert_equal(response.links.customer, - body.get('links')['customer']) - assert_equal(response.links.customer_bank_account, - body.get('links')['customer_bank_account']) - assert_equal(response.links.mandate, - body.get('links')['mandate']) + assert isinstance(response, resources.RedirectFlow) + assert responses.calls[-1].request.headers.get('Idempotency-Key') is not None + assert response.confirmation_url == body.get('confirmation_url') + assert response.created_at == body.get('created_at') + assert response.description == body.get('description') + assert response.id == body.get('id') + assert response.mandate_reference == body.get('mandate_reference') + assert response.metadata == body.get('metadata') + assert response.redirect_url == body.get('redirect_url') + assert response.scheme == body.get('scheme') + assert response.session_token == body.get('session_token') + assert response.success_redirect_url == body.get('success_redirect_url') + assert response.links.billing_request == body.get('links')['billing_request'] + assert response.links.creditor == body.get('links')['creditor'] + assert response.links.customer == body.get('links')['customer'] + assert response.links.customer_bank_account == body.get('links')['customer_bank_account'] + assert response.links.mandate == body.get('links')['mandate'] def test_timeout_redirect_flows_complete_doesnt_retry(): fixture = helpers.load_fixture('redirect_flows')['complete'] with helpers.stub_timeout(fixture) as rsps: - with assert_raises(requests.ConnectTimeout): + with pytest.raises(requests.ConnectTimeout): response = helpers.client.redirect_flows.complete(*fixture['url_params']) - assert_equal(1, len(rsps.calls)) + assert len(rsps.calls) == 1 def test_502_redirect_flows_complete_doesnt_retry(): fixture = helpers.load_fixture('redirect_flows')['complete'] with helpers.stub_502(fixture) as rsps: - with assert_raises(MalformedResponseError): + with pytest.raises(MalformedResponseError): response = helpers.client.redirect_flows.complete(*fixture['url_params']) - assert_equal(1, len(rsps.calls)) + assert len(rsps.calls) == 1 diff --git a/tests/integration/refunds_integration_test.py b/tests/integration/refunds_integration_test.py index c8476e9c..8f45c958 100644 --- a/tests/integration/refunds_integration_test.py +++ b/tests/integration/refunds_integration_test.py @@ -5,16 +5,9 @@ import json +import pytest import requests import responses -from nose.tools import ( - assert_equal, - assert_is_instance, - assert_is_none, - assert_is_not_none, - assert_not_equal, - assert_raises -) from gocardless_pro.errors import MalformedResponseError from gocardless_pro import resources @@ -30,27 +23,21 @@ def test_refunds_create(): response = helpers.client.refunds.create(*fixture['url_params']) body = fixture['body']['refunds'] - assert_is_instance(response, resources.Refund) - assert_is_not_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal(response.amount, body.get('amount')) - assert_equal(response.created_at, body.get('created_at')) - assert_equal(response.currency, body.get('currency')) - assert_equal(response.id, body.get('id')) - assert_equal(response.metadata, body.get('metadata')) - assert_equal(response.reference, body.get('reference')) - assert_equal(response.status, body.get('status')) - assert_equal(response.fx.estimated_exchange_rate, - body.get('fx')['estimated_exchange_rate']) - assert_equal(response.fx.exchange_rate, - body.get('fx')['exchange_rate']) - assert_equal(response.fx.fx_amount, - body.get('fx')['fx_amount']) - assert_equal(response.fx.fx_currency, - body.get('fx')['fx_currency']) - assert_equal(response.links.mandate, - body.get('links')['mandate']) - assert_equal(response.links.payment, - body.get('links')['payment']) + assert isinstance(response, resources.Refund) + assert responses.calls[-1].request.headers.get('Idempotency-Key') is not None + assert response.amount == body.get('amount') + assert response.created_at == body.get('created_at') + assert response.currency == body.get('currency') + assert response.id == body.get('id') + assert response.metadata == body.get('metadata') + assert response.reference == body.get('reference') + assert response.status == body.get('status') + assert response.fx.estimated_exchange_rate == body.get('fx')['estimated_exchange_rate'] + assert response.fx.exchange_rate == body.get('fx')['exchange_rate'] + assert response.fx.fx_amount == body.get('fx')['fx_amount'] + assert response.fx.fx_currency == body.get('fx')['fx_currency'] + assert response.links.mandate == body.get('links')['mandate'] + assert response.links.payment == body.get('links')['payment'] @responses.activate def test_refunds_create_new_idempotency_key_for_each_call(): @@ -58,40 +45,37 @@ def test_refunds_create_new_idempotency_key_for_each_call(): helpers.stub_response(fixture) helpers.client.refunds.create(*fixture['url_params']) helpers.client.refunds.create(*fixture['url_params']) - assert_not_equal(responses.calls[0].request.headers.get('Idempotency-Key'), - responses.calls[1].request.headers.get('Idempotency-Key')) + assert responses.calls[0].request.headers.get('Idempotency-Key') != responses.calls[1].request.headers.get('Idempotency-Key') def test_timeout_refunds_create_idempotency_conflict(): create_fixture = helpers.load_fixture('refunds')['create'] get_fixture = helpers.load_fixture('refunds')['get'] with helpers.stub_timeout_then_idempotency_conflict(create_fixture, get_fixture) as rsps: response = helpers.client.refunds.create(*create_fixture['url_params']) - assert_equal(2, len(rsps.calls)) + assert len(rsps.calls) == 2 - assert_is_instance(response, resources.Refund) + assert isinstance(response, resources.Refund) @responses.activate def test_timeout_refunds_create_retries(): fixture = helpers.load_fixture('refunds')['create'] with helpers.stub_timeout_then_response(fixture) as rsps: response = helpers.client.refunds.create(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['refunds'] - assert_is_instance(response, resources.Refund) + assert isinstance(response, resources.Refund) def test_502_refunds_create_retries(): fixture = helpers.load_fixture('refunds')['create'] with helpers.stub_502_then_response(fixture) as rsps: response = helpers.client.refunds.create(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['refunds'] - assert_is_instance(response, resources.Refund) + assert isinstance(response, resources.Refund) @responses.activate @@ -101,57 +85,48 @@ def test_refunds_list(): response = helpers.client.refunds.list(*fixture['url_params']) body = fixture['body']['refunds'] - assert_is_instance(response, list_response.ListResponse) - assert_is_instance(response.records[0], resources.Refund) - - assert_equal(response.before, fixture['body']['meta']['cursors']['before']) - assert_equal(response.after, fixture['body']['meta']['cursors']['after']) - assert_is_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal([r.amount for r in response.records], - [b.get('amount') for b in body]) - assert_equal([r.created_at for r in response.records], - [b.get('created_at') for b in body]) - assert_equal([r.currency for r in response.records], - [b.get('currency') for b in body]) - assert_equal([r.id for r in response.records], - [b.get('id') for b in body]) - assert_equal([r.metadata for r in response.records], - [b.get('metadata') for b in body]) - assert_equal([r.reference for r in response.records], - [b.get('reference') for b in body]) - assert_equal([r.status for r in response.records], - [b.get('status') for b in body]) + assert isinstance(response, list_response.ListResponse) + assert isinstance(response.records[0], resources.Refund) + + assert response.before == fixture['body']['meta']['cursors']['before'] + assert response.after == fixture['body']['meta']['cursors']['after'] + assert responses.calls[-1].request.headers.get('Idempotency-Key') is None + assert [r.amount for r in response.records] == [b.get('amount') for b in body] + assert [r.created_at for r in response.records] == [b.get('created_at') for b in body] + assert [r.currency for r in response.records] == [b.get('currency') for b in body] + assert [r.id for r in response.records] == [b.get('id') for b in body] + assert [r.metadata for r in response.records] == [b.get('metadata') for b in body] + assert [r.reference for r in response.records] == [b.get('reference') for b in body] + assert [r.status for r in response.records] == [b.get('status') for b in body] @responses.activate def test_timeout_refunds_list_retries(): fixture = helpers.load_fixture('refunds')['list'] with helpers.stub_timeout_then_response(fixture) as rsps: response = helpers.client.refunds.list(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['refunds'] - assert_is_instance(response, list_response.ListResponse) - assert_is_instance(response.records[0], resources.Refund) + assert isinstance(response, list_response.ListResponse) + assert isinstance(response.records[0], resources.Refund) - assert_equal(response.before, fixture['body']['meta']['cursors']['before']) - assert_equal(response.after, fixture['body']['meta']['cursors']['after']) + assert response.before == fixture['body']['meta']['cursors']['before'] + assert response.after == fixture['body']['meta']['cursors']['after'] def test_502_refunds_list_retries(): fixture = helpers.load_fixture('refunds')['list'] with helpers.stub_502_then_response(fixture) as rsps: response = helpers.client.refunds.list(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['refunds'] - assert_is_instance(response, list_response.ListResponse) - assert_is_instance(response.records[0], resources.Refund) + assert isinstance(response, list_response.ListResponse) + assert isinstance(response.records[0], resources.Refund) - assert_equal(response.before, fixture['body']['meta']['cursors']['before']) - assert_equal(response.after, fixture['body']['meta']['cursors']['after']) + assert response.before == fixture['body']['meta']['cursors']['before'] + assert response.after == fixture['body']['meta']['cursors']['after'] @responses.activate def test_refunds_all(): @@ -168,9 +143,9 @@ def callback(request): responses.add_callback(fixture['method'], url, callback) all_records = list(helpers.client.refunds.all()) - assert_equal(len(all_records), len(fixture['body']['refunds']) * 2) + assert len(all_records) == len(fixture['body']['refunds']) * 2 for record in all_records: - assert_is_instance(record, resources.Refund) + assert isinstance(record, resources.Refund) @@ -181,50 +156,42 @@ def test_refunds_get(): response = helpers.client.refunds.get(*fixture['url_params']) body = fixture['body']['refunds'] - assert_is_instance(response, resources.Refund) - assert_is_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal(response.amount, body.get('amount')) - assert_equal(response.created_at, body.get('created_at')) - assert_equal(response.currency, body.get('currency')) - assert_equal(response.id, body.get('id')) - assert_equal(response.metadata, body.get('metadata')) - assert_equal(response.reference, body.get('reference')) - assert_equal(response.status, body.get('status')) - assert_equal(response.fx.estimated_exchange_rate, - body.get('fx')['estimated_exchange_rate']) - assert_equal(response.fx.exchange_rate, - body.get('fx')['exchange_rate']) - assert_equal(response.fx.fx_amount, - body.get('fx')['fx_amount']) - assert_equal(response.fx.fx_currency, - body.get('fx')['fx_currency']) - assert_equal(response.links.mandate, - body.get('links')['mandate']) - assert_equal(response.links.payment, - body.get('links')['payment']) + assert isinstance(response, resources.Refund) + assert responses.calls[-1].request.headers.get('Idempotency-Key') is None + assert response.amount == body.get('amount') + assert response.created_at == body.get('created_at') + assert response.currency == body.get('currency') + assert response.id == body.get('id') + assert response.metadata == body.get('metadata') + assert response.reference == body.get('reference') + assert response.status == body.get('status') + assert response.fx.estimated_exchange_rate == body.get('fx')['estimated_exchange_rate'] + assert response.fx.exchange_rate == body.get('fx')['exchange_rate'] + assert response.fx.fx_amount == body.get('fx')['fx_amount'] + assert response.fx.fx_currency == body.get('fx')['fx_currency'] + assert response.links.mandate == body.get('links')['mandate'] + assert response.links.payment == body.get('links')['payment'] @responses.activate def test_timeout_refunds_get_retries(): fixture = helpers.load_fixture('refunds')['get'] with helpers.stub_timeout_then_response(fixture) as rsps: response = helpers.client.refunds.get(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['refunds'] - assert_is_instance(response, resources.Refund) + assert isinstance(response, resources.Refund) def test_502_refunds_get_retries(): fixture = helpers.load_fixture('refunds')['get'] with helpers.stub_502_then_response(fixture) as rsps: response = helpers.client.refunds.get(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['refunds'] - assert_is_instance(response, resources.Refund) + assert isinstance(response, resources.Refund) @responses.activate @@ -234,48 +201,40 @@ def test_refunds_update(): response = helpers.client.refunds.update(*fixture['url_params']) body = fixture['body']['refunds'] - assert_is_instance(response, resources.Refund) - assert_is_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal(response.amount, body.get('amount')) - assert_equal(response.created_at, body.get('created_at')) - assert_equal(response.currency, body.get('currency')) - assert_equal(response.id, body.get('id')) - assert_equal(response.metadata, body.get('metadata')) - assert_equal(response.reference, body.get('reference')) - assert_equal(response.status, body.get('status')) - assert_equal(response.fx.estimated_exchange_rate, - body.get('fx')['estimated_exchange_rate']) - assert_equal(response.fx.exchange_rate, - body.get('fx')['exchange_rate']) - assert_equal(response.fx.fx_amount, - body.get('fx')['fx_amount']) - assert_equal(response.fx.fx_currency, - body.get('fx')['fx_currency']) - assert_equal(response.links.mandate, - body.get('links')['mandate']) - assert_equal(response.links.payment, - body.get('links')['payment']) + assert isinstance(response, resources.Refund) + assert responses.calls[-1].request.headers.get('Idempotency-Key') is None + assert response.amount == body.get('amount') + assert response.created_at == body.get('created_at') + assert response.currency == body.get('currency') + assert response.id == body.get('id') + assert response.metadata == body.get('metadata') + assert response.reference == body.get('reference') + assert response.status == body.get('status') + assert response.fx.estimated_exchange_rate == body.get('fx')['estimated_exchange_rate'] + assert response.fx.exchange_rate == body.get('fx')['exchange_rate'] + assert response.fx.fx_amount == body.get('fx')['fx_amount'] + assert response.fx.fx_currency == body.get('fx')['fx_currency'] + assert response.links.mandate == body.get('links')['mandate'] + assert response.links.payment == body.get('links')['payment'] @responses.activate def test_timeout_refunds_update_retries(): fixture = helpers.load_fixture('refunds')['update'] with helpers.stub_timeout_then_response(fixture) as rsps: response = helpers.client.refunds.update(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['refunds'] - assert_is_instance(response, resources.Refund) + assert isinstance(response, resources.Refund) def test_502_refunds_update_retries(): fixture = helpers.load_fixture('refunds')['update'] with helpers.stub_502_then_response(fixture) as rsps: response = helpers.client.refunds.update(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['refunds'] - assert_is_instance(response, resources.Refund) + assert isinstance(response, resources.Refund) diff --git a/tests/integration/scenario_simulators_integration_test.py b/tests/integration/scenario_simulators_integration_test.py index 929abb8d..1062e0f2 100644 --- a/tests/integration/scenario_simulators_integration_test.py +++ b/tests/integration/scenario_simulators_integration_test.py @@ -5,16 +5,9 @@ import json +import pytest import requests import responses -from nose.tools import ( - assert_equal, - assert_is_instance, - assert_is_none, - assert_is_not_none, - assert_not_equal, - assert_raises -) from gocardless_pro.errors import MalformedResponseError from gocardless_pro import resources @@ -30,21 +23,21 @@ def test_scenario_simulators_run(): response = helpers.client.scenario_simulators.run(*fixture['url_params']) body = fixture['body']['scenario_simulators'] - assert_is_instance(response, resources.ScenarioSimulator) - assert_is_not_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal(response.id, body.get('id')) + assert isinstance(response, resources.ScenarioSimulator) + assert responses.calls[-1].request.headers.get('Idempotency-Key') is not None + assert response.id == body.get('id') def test_timeout_scenario_simulators_run_doesnt_retry(): fixture = helpers.load_fixture('scenario_simulators')['run'] with helpers.stub_timeout(fixture) as rsps: - with assert_raises(requests.ConnectTimeout): + with pytest.raises(requests.ConnectTimeout): response = helpers.client.scenario_simulators.run(*fixture['url_params']) - assert_equal(1, len(rsps.calls)) + assert len(rsps.calls) == 1 def test_502_scenario_simulators_run_doesnt_retry(): fixture = helpers.load_fixture('scenario_simulators')['run'] with helpers.stub_502(fixture) as rsps: - with assert_raises(MalformedResponseError): + with pytest.raises(MalformedResponseError): response = helpers.client.scenario_simulators.run(*fixture['url_params']) - assert_equal(1, len(rsps.calls)) + assert len(rsps.calls) == 1 diff --git a/tests/integration/scheme_identifiers_integration_test.py b/tests/integration/scheme_identifiers_integration_test.py index d5b766e8..81d1d63b 100644 --- a/tests/integration/scheme_identifiers_integration_test.py +++ b/tests/integration/scheme_identifiers_integration_test.py @@ -5,16 +5,9 @@ import json +import pytest import requests import responses -from nose.tools import ( - assert_equal, - assert_is_instance, - assert_is_none, - assert_is_not_none, - assert_not_equal, - assert_raises -) from gocardless_pro.errors import MalformedResponseError from gocardless_pro import resources @@ -30,26 +23,26 @@ def test_scheme_identifiers_create(): response = helpers.client.scheme_identifiers.create(*fixture['url_params']) body = fixture['body']['scheme_identifiers'] - assert_is_instance(response, resources.SchemeIdentifier) - assert_is_not_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal(response.address_line1, body.get('address_line1')) - assert_equal(response.address_line2, body.get('address_line2')) - assert_equal(response.address_line3, body.get('address_line3')) - assert_equal(response.can_specify_mandate_reference, body.get('can_specify_mandate_reference')) - assert_equal(response.city, body.get('city')) - assert_equal(response.country_code, body.get('country_code')) - assert_equal(response.created_at, body.get('created_at')) - assert_equal(response.currency, body.get('currency')) - assert_equal(response.email, body.get('email')) - assert_equal(response.id, body.get('id')) - assert_equal(response.minimum_advance_notice, body.get('minimum_advance_notice')) - assert_equal(response.name, body.get('name')) - assert_equal(response.phone_number, body.get('phone_number')) - assert_equal(response.postal_code, body.get('postal_code')) - assert_equal(response.reference, body.get('reference')) - assert_equal(response.region, body.get('region')) - assert_equal(response.scheme, body.get('scheme')) - assert_equal(response.status, body.get('status')) + assert isinstance(response, resources.SchemeIdentifier) + assert responses.calls[-1].request.headers.get('Idempotency-Key') is not None + assert response.address_line1 == body.get('address_line1') + assert response.address_line2 == body.get('address_line2') + assert response.address_line3 == body.get('address_line3') + assert response.can_specify_mandate_reference == body.get('can_specify_mandate_reference') + assert response.city == body.get('city') + assert response.country_code == body.get('country_code') + assert response.created_at == body.get('created_at') + assert response.currency == body.get('currency') + assert response.email == body.get('email') + assert response.id == body.get('id') + assert response.minimum_advance_notice == body.get('minimum_advance_notice') + assert response.name == body.get('name') + assert response.phone_number == body.get('phone_number') + assert response.postal_code == body.get('postal_code') + assert response.reference == body.get('reference') + assert response.region == body.get('region') + assert response.scheme == body.get('scheme') + assert response.status == body.get('status') @responses.activate def test_scheme_identifiers_create_new_idempotency_key_for_each_call(): @@ -57,40 +50,37 @@ def test_scheme_identifiers_create_new_idempotency_key_for_each_call(): helpers.stub_response(fixture) helpers.client.scheme_identifiers.create(*fixture['url_params']) helpers.client.scheme_identifiers.create(*fixture['url_params']) - assert_not_equal(responses.calls[0].request.headers.get('Idempotency-Key'), - responses.calls[1].request.headers.get('Idempotency-Key')) + assert responses.calls[0].request.headers.get('Idempotency-Key') != responses.calls[1].request.headers.get('Idempotency-Key') def test_timeout_scheme_identifiers_create_idempotency_conflict(): create_fixture = helpers.load_fixture('scheme_identifiers')['create'] get_fixture = helpers.load_fixture('scheme_identifiers')['get'] with helpers.stub_timeout_then_idempotency_conflict(create_fixture, get_fixture) as rsps: response = helpers.client.scheme_identifiers.create(*create_fixture['url_params']) - assert_equal(2, len(rsps.calls)) + assert len(rsps.calls) == 2 - assert_is_instance(response, resources.SchemeIdentifier) + assert isinstance(response, resources.SchemeIdentifier) @responses.activate def test_timeout_scheme_identifiers_create_retries(): fixture = helpers.load_fixture('scheme_identifiers')['create'] with helpers.stub_timeout_then_response(fixture) as rsps: response = helpers.client.scheme_identifiers.create(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['scheme_identifiers'] - assert_is_instance(response, resources.SchemeIdentifier) + assert isinstance(response, resources.SchemeIdentifier) def test_502_scheme_identifiers_create_retries(): fixture = helpers.load_fixture('scheme_identifiers')['create'] with helpers.stub_502_then_response(fixture) as rsps: response = helpers.client.scheme_identifiers.create(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['scheme_identifiers'] - assert_is_instance(response, resources.SchemeIdentifier) + assert isinstance(response, resources.SchemeIdentifier) @responses.activate @@ -100,79 +90,59 @@ def test_scheme_identifiers_list(): response = helpers.client.scheme_identifiers.list(*fixture['url_params']) body = fixture['body']['scheme_identifiers'] - assert_is_instance(response, list_response.ListResponse) - assert_is_instance(response.records[0], resources.SchemeIdentifier) - - assert_equal(response.before, fixture['body']['meta']['cursors']['before']) - assert_equal(response.after, fixture['body']['meta']['cursors']['after']) - assert_is_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal([r.address_line1 for r in response.records], - [b.get('address_line1') for b in body]) - assert_equal([r.address_line2 for r in response.records], - [b.get('address_line2') for b in body]) - assert_equal([r.address_line3 for r in response.records], - [b.get('address_line3') for b in body]) - assert_equal([r.can_specify_mandate_reference for r in response.records], - [b.get('can_specify_mandate_reference') for b in body]) - assert_equal([r.city for r in response.records], - [b.get('city') for b in body]) - assert_equal([r.country_code for r in response.records], - [b.get('country_code') for b in body]) - assert_equal([r.created_at for r in response.records], - [b.get('created_at') for b in body]) - assert_equal([r.currency for r in response.records], - [b.get('currency') for b in body]) - assert_equal([r.email for r in response.records], - [b.get('email') for b in body]) - assert_equal([r.id for r in response.records], - [b.get('id') for b in body]) - assert_equal([r.minimum_advance_notice for r in response.records], - [b.get('minimum_advance_notice') for b in body]) - assert_equal([r.name for r in response.records], - [b.get('name') for b in body]) - assert_equal([r.phone_number for r in response.records], - [b.get('phone_number') for b in body]) - assert_equal([r.postal_code for r in response.records], - [b.get('postal_code') for b in body]) - assert_equal([r.reference for r in response.records], - [b.get('reference') for b in body]) - assert_equal([r.region for r in response.records], - [b.get('region') for b in body]) - assert_equal([r.scheme for r in response.records], - [b.get('scheme') for b in body]) - assert_equal([r.status for r in response.records], - [b.get('status') for b in body]) + assert isinstance(response, list_response.ListResponse) + assert isinstance(response.records[0], resources.SchemeIdentifier) + + assert response.before == fixture['body']['meta']['cursors']['before'] + assert response.after == fixture['body']['meta']['cursors']['after'] + assert responses.calls[-1].request.headers.get('Idempotency-Key') is None + assert [r.address_line1 for r in response.records] == [b.get('address_line1') for b in body] + assert [r.address_line2 for r in response.records] == [b.get('address_line2') for b in body] + assert [r.address_line3 for r in response.records] == [b.get('address_line3') for b in body] + assert [r.can_specify_mandate_reference for r in response.records] == [b.get('can_specify_mandate_reference') for b in body] + assert [r.city for r in response.records] == [b.get('city') for b in body] + assert [r.country_code for r in response.records] == [b.get('country_code') for b in body] + assert [r.created_at for r in response.records] == [b.get('created_at') for b in body] + assert [r.currency for r in response.records] == [b.get('currency') for b in body] + assert [r.email for r in response.records] == [b.get('email') for b in body] + assert [r.id for r in response.records] == [b.get('id') for b in body] + assert [r.minimum_advance_notice for r in response.records] == [b.get('minimum_advance_notice') for b in body] + assert [r.name for r in response.records] == [b.get('name') for b in body] + assert [r.phone_number for r in response.records] == [b.get('phone_number') for b in body] + assert [r.postal_code for r in response.records] == [b.get('postal_code') for b in body] + assert [r.reference for r in response.records] == [b.get('reference') for b in body] + assert [r.region for r in response.records] == [b.get('region') for b in body] + assert [r.scheme for r in response.records] == [b.get('scheme') for b in body] + assert [r.status for r in response.records] == [b.get('status') for b in body] @responses.activate def test_timeout_scheme_identifiers_list_retries(): fixture = helpers.load_fixture('scheme_identifiers')['list'] with helpers.stub_timeout_then_response(fixture) as rsps: response = helpers.client.scheme_identifiers.list(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['scheme_identifiers'] - assert_is_instance(response, list_response.ListResponse) - assert_is_instance(response.records[0], resources.SchemeIdentifier) + assert isinstance(response, list_response.ListResponse) + assert isinstance(response.records[0], resources.SchemeIdentifier) - assert_equal(response.before, fixture['body']['meta']['cursors']['before']) - assert_equal(response.after, fixture['body']['meta']['cursors']['after']) + assert response.before == fixture['body']['meta']['cursors']['before'] + assert response.after == fixture['body']['meta']['cursors']['after'] def test_502_scheme_identifiers_list_retries(): fixture = helpers.load_fixture('scheme_identifiers')['list'] with helpers.stub_502_then_response(fixture) as rsps: response = helpers.client.scheme_identifiers.list(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['scheme_identifiers'] - assert_is_instance(response, list_response.ListResponse) - assert_is_instance(response.records[0], resources.SchemeIdentifier) + assert isinstance(response, list_response.ListResponse) + assert isinstance(response.records[0], resources.SchemeIdentifier) - assert_equal(response.before, fixture['body']['meta']['cursors']['before']) - assert_equal(response.after, fixture['body']['meta']['cursors']['after']) + assert response.before == fixture['body']['meta']['cursors']['before'] + assert response.after == fixture['body']['meta']['cursors']['after'] @responses.activate def test_scheme_identifiers_all(): @@ -189,9 +159,9 @@ def callback(request): responses.add_callback(fixture['method'], url, callback) all_records = list(helpers.client.scheme_identifiers.all()) - assert_equal(len(all_records), len(fixture['body']['scheme_identifiers']) * 2) + assert len(all_records) == len(fixture['body']['scheme_identifiers']) * 2 for record in all_records: - assert_is_instance(record, resources.SchemeIdentifier) + assert isinstance(record, resources.SchemeIdentifier) @@ -202,47 +172,45 @@ def test_scheme_identifiers_get(): response = helpers.client.scheme_identifiers.get(*fixture['url_params']) body = fixture['body']['scheme_identifiers'] - assert_is_instance(response, resources.SchemeIdentifier) - assert_is_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal(response.address_line1, body.get('address_line1')) - assert_equal(response.address_line2, body.get('address_line2')) - assert_equal(response.address_line3, body.get('address_line3')) - assert_equal(response.can_specify_mandate_reference, body.get('can_specify_mandate_reference')) - assert_equal(response.city, body.get('city')) - assert_equal(response.country_code, body.get('country_code')) - assert_equal(response.created_at, body.get('created_at')) - assert_equal(response.currency, body.get('currency')) - assert_equal(response.email, body.get('email')) - assert_equal(response.id, body.get('id')) - assert_equal(response.minimum_advance_notice, body.get('minimum_advance_notice')) - assert_equal(response.name, body.get('name')) - assert_equal(response.phone_number, body.get('phone_number')) - assert_equal(response.postal_code, body.get('postal_code')) - assert_equal(response.reference, body.get('reference')) - assert_equal(response.region, body.get('region')) - assert_equal(response.scheme, body.get('scheme')) - assert_equal(response.status, body.get('status')) + assert isinstance(response, resources.SchemeIdentifier) + assert responses.calls[-1].request.headers.get('Idempotency-Key') is None + assert response.address_line1 == body.get('address_line1') + assert response.address_line2 == body.get('address_line2') + assert response.address_line3 == body.get('address_line3') + assert response.can_specify_mandate_reference == body.get('can_specify_mandate_reference') + assert response.city == body.get('city') + assert response.country_code == body.get('country_code') + assert response.created_at == body.get('created_at') + assert response.currency == body.get('currency') + assert response.email == body.get('email') + assert response.id == body.get('id') + assert response.minimum_advance_notice == body.get('minimum_advance_notice') + assert response.name == body.get('name') + assert response.phone_number == body.get('phone_number') + assert response.postal_code == body.get('postal_code') + assert response.reference == body.get('reference') + assert response.region == body.get('region') + assert response.scheme == body.get('scheme') + assert response.status == body.get('status') @responses.activate def test_timeout_scheme_identifiers_get_retries(): fixture = helpers.load_fixture('scheme_identifiers')['get'] with helpers.stub_timeout_then_response(fixture) as rsps: response = helpers.client.scheme_identifiers.get(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['scheme_identifiers'] - assert_is_instance(response, resources.SchemeIdentifier) + assert isinstance(response, resources.SchemeIdentifier) def test_502_scheme_identifiers_get_retries(): fixture = helpers.load_fixture('scheme_identifiers')['get'] with helpers.stub_502_then_response(fixture) as rsps: response = helpers.client.scheme_identifiers.get(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['scheme_identifiers'] - assert_is_instance(response, resources.SchemeIdentifier) + assert isinstance(response, resources.SchemeIdentifier) diff --git a/tests/integration/subscriptions_integration_test.py b/tests/integration/subscriptions_integration_test.py index 6c114579..3c6e1121 100644 --- a/tests/integration/subscriptions_integration_test.py +++ b/tests/integration/subscriptions_integration_test.py @@ -5,16 +5,9 @@ import json +import pytest import requests import responses -from nose.tools import ( - assert_equal, - assert_is_instance, - assert_is_none, - assert_is_not_none, - assert_not_equal, - assert_raises -) from gocardless_pro.errors import MalformedResponseError from gocardless_pro import resources @@ -30,29 +23,28 @@ def test_subscriptions_create(): response = helpers.client.subscriptions.create(*fixture['url_params']) body = fixture['body']['subscriptions'] - assert_is_instance(response, resources.Subscription) - assert_is_not_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal(response.amount, body.get('amount')) - assert_equal(response.app_fee, body.get('app_fee')) - assert_equal(response.count, body.get('count')) - assert_equal(response.created_at, body.get('created_at')) - assert_equal(response.currency, body.get('currency')) - assert_equal(response.day_of_month, body.get('day_of_month')) - assert_equal(response.earliest_charge_date_after_resume, body.get('earliest_charge_date_after_resume')) - assert_equal(response.end_date, body.get('end_date')) - assert_equal(response.id, body.get('id')) - assert_equal(response.interval, body.get('interval')) - assert_equal(response.interval_unit, body.get('interval_unit')) - assert_equal(response.metadata, body.get('metadata')) - assert_equal(response.month, body.get('month')) - assert_equal(response.name, body.get('name')) - assert_equal(response.payment_reference, body.get('payment_reference')) - assert_equal(response.retry_if_possible, body.get('retry_if_possible')) - assert_equal(response.start_date, body.get('start_date')) - assert_equal(response.status, body.get('status')) - assert_equal(response.upcoming_payments, body.get('upcoming_payments')) - assert_equal(response.links.mandate, - body.get('links')['mandate']) + assert isinstance(response, resources.Subscription) + assert responses.calls[-1].request.headers.get('Idempotency-Key') is not None + assert response.amount == body.get('amount') + assert response.app_fee == body.get('app_fee') + assert response.count == body.get('count') + assert response.created_at == body.get('created_at') + assert response.currency == body.get('currency') + assert response.day_of_month == body.get('day_of_month') + assert response.earliest_charge_date_after_resume == body.get('earliest_charge_date_after_resume') + assert response.end_date == body.get('end_date') + assert response.id == body.get('id') + assert response.interval == body.get('interval') + assert response.interval_unit == body.get('interval_unit') + assert response.metadata == body.get('metadata') + assert response.month == body.get('month') + assert response.name == body.get('name') + assert response.payment_reference == body.get('payment_reference') + assert response.retry_if_possible == body.get('retry_if_possible') + assert response.start_date == body.get('start_date') + assert response.status == body.get('status') + assert response.upcoming_payments == body.get('upcoming_payments') + assert response.links.mandate == body.get('links')['mandate'] @responses.activate def test_subscriptions_create_new_idempotency_key_for_each_call(): @@ -60,40 +52,37 @@ def test_subscriptions_create_new_idempotency_key_for_each_call(): helpers.stub_response(fixture) helpers.client.subscriptions.create(*fixture['url_params']) helpers.client.subscriptions.create(*fixture['url_params']) - assert_not_equal(responses.calls[0].request.headers.get('Idempotency-Key'), - responses.calls[1].request.headers.get('Idempotency-Key')) + assert responses.calls[0].request.headers.get('Idempotency-Key') != responses.calls[1].request.headers.get('Idempotency-Key') def test_timeout_subscriptions_create_idempotency_conflict(): create_fixture = helpers.load_fixture('subscriptions')['create'] get_fixture = helpers.load_fixture('subscriptions')['get'] with helpers.stub_timeout_then_idempotency_conflict(create_fixture, get_fixture) as rsps: response = helpers.client.subscriptions.create(*create_fixture['url_params']) - assert_equal(2, len(rsps.calls)) + assert len(rsps.calls) == 2 - assert_is_instance(response, resources.Subscription) + assert isinstance(response, resources.Subscription) @responses.activate def test_timeout_subscriptions_create_retries(): fixture = helpers.load_fixture('subscriptions')['create'] with helpers.stub_timeout_then_response(fixture) as rsps: response = helpers.client.subscriptions.create(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['subscriptions'] - assert_is_instance(response, resources.Subscription) + assert isinstance(response, resources.Subscription) def test_502_subscriptions_create_retries(): fixture = helpers.load_fixture('subscriptions')['create'] with helpers.stub_502_then_response(fixture) as rsps: response = helpers.client.subscriptions.create(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['subscriptions'] - assert_is_instance(response, resources.Subscription) + assert isinstance(response, resources.Subscription) @responses.activate @@ -103,81 +92,60 @@ def test_subscriptions_list(): response = helpers.client.subscriptions.list(*fixture['url_params']) body = fixture['body']['subscriptions'] - assert_is_instance(response, list_response.ListResponse) - assert_is_instance(response.records[0], resources.Subscription) - - assert_equal(response.before, fixture['body']['meta']['cursors']['before']) - assert_equal(response.after, fixture['body']['meta']['cursors']['after']) - assert_is_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal([r.amount for r in response.records], - [b.get('amount') for b in body]) - assert_equal([r.app_fee for r in response.records], - [b.get('app_fee') for b in body]) - assert_equal([r.count for r in response.records], - [b.get('count') for b in body]) - assert_equal([r.created_at for r in response.records], - [b.get('created_at') for b in body]) - assert_equal([r.currency for r in response.records], - [b.get('currency') for b in body]) - assert_equal([r.day_of_month for r in response.records], - [b.get('day_of_month') for b in body]) - assert_equal([r.earliest_charge_date_after_resume for r in response.records], - [b.get('earliest_charge_date_after_resume') for b in body]) - assert_equal([r.end_date for r in response.records], - [b.get('end_date') for b in body]) - assert_equal([r.id for r in response.records], - [b.get('id') for b in body]) - assert_equal([r.interval for r in response.records], - [b.get('interval') for b in body]) - assert_equal([r.interval_unit for r in response.records], - [b.get('interval_unit') for b in body]) - assert_equal([r.metadata for r in response.records], - [b.get('metadata') for b in body]) - assert_equal([r.month for r in response.records], - [b.get('month') for b in body]) - assert_equal([r.name for r in response.records], - [b.get('name') for b in body]) - assert_equal([r.payment_reference for r in response.records], - [b.get('payment_reference') for b in body]) - assert_equal([r.retry_if_possible for r in response.records], - [b.get('retry_if_possible') for b in body]) - assert_equal([r.start_date for r in response.records], - [b.get('start_date') for b in body]) - assert_equal([r.status for r in response.records], - [b.get('status') for b in body]) - assert_equal([r.upcoming_payments for r in response.records], - [b.get('upcoming_payments') for b in body]) + assert isinstance(response, list_response.ListResponse) + assert isinstance(response.records[0], resources.Subscription) + + assert response.before == fixture['body']['meta']['cursors']['before'] + assert response.after == fixture['body']['meta']['cursors']['after'] + assert responses.calls[-1].request.headers.get('Idempotency-Key') is None + assert [r.amount for r in response.records] == [b.get('amount') for b in body] + assert [r.app_fee for r in response.records] == [b.get('app_fee') for b in body] + assert [r.count for r in response.records] == [b.get('count') for b in body] + assert [r.created_at for r in response.records] == [b.get('created_at') for b in body] + assert [r.currency for r in response.records] == [b.get('currency') for b in body] + assert [r.day_of_month for r in response.records] == [b.get('day_of_month') for b in body] + assert [r.earliest_charge_date_after_resume for r in response.records] == [b.get('earliest_charge_date_after_resume') for b in body] + assert [r.end_date for r in response.records] == [b.get('end_date') for b in body] + assert [r.id for r in response.records] == [b.get('id') for b in body] + assert [r.interval for r in response.records] == [b.get('interval') for b in body] + assert [r.interval_unit for r in response.records] == [b.get('interval_unit') for b in body] + assert [r.metadata for r in response.records] == [b.get('metadata') for b in body] + assert [r.month for r in response.records] == [b.get('month') for b in body] + assert [r.name for r in response.records] == [b.get('name') for b in body] + assert [r.payment_reference for r in response.records] == [b.get('payment_reference') for b in body] + assert [r.retry_if_possible for r in response.records] == [b.get('retry_if_possible') for b in body] + assert [r.start_date for r in response.records] == [b.get('start_date') for b in body] + assert [r.status for r in response.records] == [b.get('status') for b in body] + assert [r.upcoming_payments for r in response.records] == [b.get('upcoming_payments') for b in body] @responses.activate def test_timeout_subscriptions_list_retries(): fixture = helpers.load_fixture('subscriptions')['list'] with helpers.stub_timeout_then_response(fixture) as rsps: response = helpers.client.subscriptions.list(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['subscriptions'] - assert_is_instance(response, list_response.ListResponse) - assert_is_instance(response.records[0], resources.Subscription) + assert isinstance(response, list_response.ListResponse) + assert isinstance(response.records[0], resources.Subscription) - assert_equal(response.before, fixture['body']['meta']['cursors']['before']) - assert_equal(response.after, fixture['body']['meta']['cursors']['after']) + assert response.before == fixture['body']['meta']['cursors']['before'] + assert response.after == fixture['body']['meta']['cursors']['after'] def test_502_subscriptions_list_retries(): fixture = helpers.load_fixture('subscriptions')['list'] with helpers.stub_502_then_response(fixture) as rsps: response = helpers.client.subscriptions.list(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['subscriptions'] - assert_is_instance(response, list_response.ListResponse) - assert_is_instance(response.records[0], resources.Subscription) + assert isinstance(response, list_response.ListResponse) + assert isinstance(response.records[0], resources.Subscription) - assert_equal(response.before, fixture['body']['meta']['cursors']['before']) - assert_equal(response.after, fixture['body']['meta']['cursors']['after']) + assert response.before == fixture['body']['meta']['cursors']['before'] + assert response.after == fixture['body']['meta']['cursors']['after'] @responses.activate def test_subscriptions_all(): @@ -194,9 +162,9 @@ def callback(request): responses.add_callback(fixture['method'], url, callback) all_records = list(helpers.client.subscriptions.all()) - assert_equal(len(all_records), len(fixture['body']['subscriptions']) * 2) + assert len(all_records) == len(fixture['body']['subscriptions']) * 2 for record in all_records: - assert_is_instance(record, resources.Subscription) + assert isinstance(record, resources.Subscription) @@ -207,52 +175,49 @@ def test_subscriptions_get(): response = helpers.client.subscriptions.get(*fixture['url_params']) body = fixture['body']['subscriptions'] - assert_is_instance(response, resources.Subscription) - assert_is_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal(response.amount, body.get('amount')) - assert_equal(response.app_fee, body.get('app_fee')) - assert_equal(response.count, body.get('count')) - assert_equal(response.created_at, body.get('created_at')) - assert_equal(response.currency, body.get('currency')) - assert_equal(response.day_of_month, body.get('day_of_month')) - assert_equal(response.earliest_charge_date_after_resume, body.get('earliest_charge_date_after_resume')) - assert_equal(response.end_date, body.get('end_date')) - assert_equal(response.id, body.get('id')) - assert_equal(response.interval, body.get('interval')) - assert_equal(response.interval_unit, body.get('interval_unit')) - assert_equal(response.metadata, body.get('metadata')) - assert_equal(response.month, body.get('month')) - assert_equal(response.name, body.get('name')) - assert_equal(response.payment_reference, body.get('payment_reference')) - assert_equal(response.retry_if_possible, body.get('retry_if_possible')) - assert_equal(response.start_date, body.get('start_date')) - assert_equal(response.status, body.get('status')) - assert_equal(response.upcoming_payments, body.get('upcoming_payments')) - assert_equal(response.links.mandate, - body.get('links')['mandate']) + assert isinstance(response, resources.Subscription) + assert responses.calls[-1].request.headers.get('Idempotency-Key') is None + assert response.amount == body.get('amount') + assert response.app_fee == body.get('app_fee') + assert response.count == body.get('count') + assert response.created_at == body.get('created_at') + assert response.currency == body.get('currency') + assert response.day_of_month == body.get('day_of_month') + assert response.earliest_charge_date_after_resume == body.get('earliest_charge_date_after_resume') + assert response.end_date == body.get('end_date') + assert response.id == body.get('id') + assert response.interval == body.get('interval') + assert response.interval_unit == body.get('interval_unit') + assert response.metadata == body.get('metadata') + assert response.month == body.get('month') + assert response.name == body.get('name') + assert response.payment_reference == body.get('payment_reference') + assert response.retry_if_possible == body.get('retry_if_possible') + assert response.start_date == body.get('start_date') + assert response.status == body.get('status') + assert response.upcoming_payments == body.get('upcoming_payments') + assert response.links.mandate == body.get('links')['mandate'] @responses.activate def test_timeout_subscriptions_get_retries(): fixture = helpers.load_fixture('subscriptions')['get'] with helpers.stub_timeout_then_response(fixture) as rsps: response = helpers.client.subscriptions.get(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['subscriptions'] - assert_is_instance(response, resources.Subscription) + assert isinstance(response, resources.Subscription) def test_502_subscriptions_get_retries(): fixture = helpers.load_fixture('subscriptions')['get'] with helpers.stub_502_then_response(fixture) as rsps: response = helpers.client.subscriptions.get(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['subscriptions'] - assert_is_instance(response, resources.Subscription) + assert isinstance(response, resources.Subscription) @responses.activate @@ -262,52 +227,49 @@ def test_subscriptions_update(): response = helpers.client.subscriptions.update(*fixture['url_params']) body = fixture['body']['subscriptions'] - assert_is_instance(response, resources.Subscription) - assert_is_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal(response.amount, body.get('amount')) - assert_equal(response.app_fee, body.get('app_fee')) - assert_equal(response.count, body.get('count')) - assert_equal(response.created_at, body.get('created_at')) - assert_equal(response.currency, body.get('currency')) - assert_equal(response.day_of_month, body.get('day_of_month')) - assert_equal(response.earliest_charge_date_after_resume, body.get('earliest_charge_date_after_resume')) - assert_equal(response.end_date, body.get('end_date')) - assert_equal(response.id, body.get('id')) - assert_equal(response.interval, body.get('interval')) - assert_equal(response.interval_unit, body.get('interval_unit')) - assert_equal(response.metadata, body.get('metadata')) - assert_equal(response.month, body.get('month')) - assert_equal(response.name, body.get('name')) - assert_equal(response.payment_reference, body.get('payment_reference')) - assert_equal(response.retry_if_possible, body.get('retry_if_possible')) - assert_equal(response.start_date, body.get('start_date')) - assert_equal(response.status, body.get('status')) - assert_equal(response.upcoming_payments, body.get('upcoming_payments')) - assert_equal(response.links.mandate, - body.get('links')['mandate']) + assert isinstance(response, resources.Subscription) + assert responses.calls[-1].request.headers.get('Idempotency-Key') is None + assert response.amount == body.get('amount') + assert response.app_fee == body.get('app_fee') + assert response.count == body.get('count') + assert response.created_at == body.get('created_at') + assert response.currency == body.get('currency') + assert response.day_of_month == body.get('day_of_month') + assert response.earliest_charge_date_after_resume == body.get('earliest_charge_date_after_resume') + assert response.end_date == body.get('end_date') + assert response.id == body.get('id') + assert response.interval == body.get('interval') + assert response.interval_unit == body.get('interval_unit') + assert response.metadata == body.get('metadata') + assert response.month == body.get('month') + assert response.name == body.get('name') + assert response.payment_reference == body.get('payment_reference') + assert response.retry_if_possible == body.get('retry_if_possible') + assert response.start_date == body.get('start_date') + assert response.status == body.get('status') + assert response.upcoming_payments == body.get('upcoming_payments') + assert response.links.mandate == body.get('links')['mandate'] @responses.activate def test_timeout_subscriptions_update_retries(): fixture = helpers.load_fixture('subscriptions')['update'] with helpers.stub_timeout_then_response(fixture) as rsps: response = helpers.client.subscriptions.update(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['subscriptions'] - assert_is_instance(response, resources.Subscription) + assert isinstance(response, resources.Subscription) def test_502_subscriptions_update_retries(): fixture = helpers.load_fixture('subscriptions')['update'] with helpers.stub_502_then_response(fixture) as rsps: response = helpers.client.subscriptions.update(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['subscriptions'] - assert_is_instance(response, resources.Subscription) + assert isinstance(response, resources.Subscription) @responses.activate @@ -317,43 +279,42 @@ def test_subscriptions_pause(): response = helpers.client.subscriptions.pause(*fixture['url_params']) body = fixture['body']['subscriptions'] - assert_is_instance(response, resources.Subscription) - assert_is_not_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal(response.amount, body.get('amount')) - assert_equal(response.app_fee, body.get('app_fee')) - assert_equal(response.count, body.get('count')) - assert_equal(response.created_at, body.get('created_at')) - assert_equal(response.currency, body.get('currency')) - assert_equal(response.day_of_month, body.get('day_of_month')) - assert_equal(response.earliest_charge_date_after_resume, body.get('earliest_charge_date_after_resume')) - assert_equal(response.end_date, body.get('end_date')) - assert_equal(response.id, body.get('id')) - assert_equal(response.interval, body.get('interval')) - assert_equal(response.interval_unit, body.get('interval_unit')) - assert_equal(response.metadata, body.get('metadata')) - assert_equal(response.month, body.get('month')) - assert_equal(response.name, body.get('name')) - assert_equal(response.payment_reference, body.get('payment_reference')) - assert_equal(response.retry_if_possible, body.get('retry_if_possible')) - assert_equal(response.start_date, body.get('start_date')) - assert_equal(response.status, body.get('status')) - assert_equal(response.upcoming_payments, body.get('upcoming_payments')) - assert_equal(response.links.mandate, - body.get('links')['mandate']) + assert isinstance(response, resources.Subscription) + assert responses.calls[-1].request.headers.get('Idempotency-Key') is not None + assert response.amount == body.get('amount') + assert response.app_fee == body.get('app_fee') + assert response.count == body.get('count') + assert response.created_at == body.get('created_at') + assert response.currency == body.get('currency') + assert response.day_of_month == body.get('day_of_month') + assert response.earliest_charge_date_after_resume == body.get('earliest_charge_date_after_resume') + assert response.end_date == body.get('end_date') + assert response.id == body.get('id') + assert response.interval == body.get('interval') + assert response.interval_unit == body.get('interval_unit') + assert response.metadata == body.get('metadata') + assert response.month == body.get('month') + assert response.name == body.get('name') + assert response.payment_reference == body.get('payment_reference') + assert response.retry_if_possible == body.get('retry_if_possible') + assert response.start_date == body.get('start_date') + assert response.status == body.get('status') + assert response.upcoming_payments == body.get('upcoming_payments') + assert response.links.mandate == body.get('links')['mandate'] def test_timeout_subscriptions_pause_doesnt_retry(): fixture = helpers.load_fixture('subscriptions')['pause'] with helpers.stub_timeout(fixture) as rsps: - with assert_raises(requests.ConnectTimeout): + with pytest.raises(requests.ConnectTimeout): response = helpers.client.subscriptions.pause(*fixture['url_params']) - assert_equal(1, len(rsps.calls)) + assert len(rsps.calls) == 1 def test_502_subscriptions_pause_doesnt_retry(): fixture = helpers.load_fixture('subscriptions')['pause'] with helpers.stub_502(fixture) as rsps: - with assert_raises(MalformedResponseError): + with pytest.raises(MalformedResponseError): response = helpers.client.subscriptions.pause(*fixture['url_params']) - assert_equal(1, len(rsps.calls)) + assert len(rsps.calls) == 1 @responses.activate @@ -363,43 +324,42 @@ def test_subscriptions_resume(): response = helpers.client.subscriptions.resume(*fixture['url_params']) body = fixture['body']['subscriptions'] - assert_is_instance(response, resources.Subscription) - assert_is_not_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal(response.amount, body.get('amount')) - assert_equal(response.app_fee, body.get('app_fee')) - assert_equal(response.count, body.get('count')) - assert_equal(response.created_at, body.get('created_at')) - assert_equal(response.currency, body.get('currency')) - assert_equal(response.day_of_month, body.get('day_of_month')) - assert_equal(response.earliest_charge_date_after_resume, body.get('earliest_charge_date_after_resume')) - assert_equal(response.end_date, body.get('end_date')) - assert_equal(response.id, body.get('id')) - assert_equal(response.interval, body.get('interval')) - assert_equal(response.interval_unit, body.get('interval_unit')) - assert_equal(response.metadata, body.get('metadata')) - assert_equal(response.month, body.get('month')) - assert_equal(response.name, body.get('name')) - assert_equal(response.payment_reference, body.get('payment_reference')) - assert_equal(response.retry_if_possible, body.get('retry_if_possible')) - assert_equal(response.start_date, body.get('start_date')) - assert_equal(response.status, body.get('status')) - assert_equal(response.upcoming_payments, body.get('upcoming_payments')) - assert_equal(response.links.mandate, - body.get('links')['mandate']) + assert isinstance(response, resources.Subscription) + assert responses.calls[-1].request.headers.get('Idempotency-Key') is not None + assert response.amount == body.get('amount') + assert response.app_fee == body.get('app_fee') + assert response.count == body.get('count') + assert response.created_at == body.get('created_at') + assert response.currency == body.get('currency') + assert response.day_of_month == body.get('day_of_month') + assert response.earliest_charge_date_after_resume == body.get('earliest_charge_date_after_resume') + assert response.end_date == body.get('end_date') + assert response.id == body.get('id') + assert response.interval == body.get('interval') + assert response.interval_unit == body.get('interval_unit') + assert response.metadata == body.get('metadata') + assert response.month == body.get('month') + assert response.name == body.get('name') + assert response.payment_reference == body.get('payment_reference') + assert response.retry_if_possible == body.get('retry_if_possible') + assert response.start_date == body.get('start_date') + assert response.status == body.get('status') + assert response.upcoming_payments == body.get('upcoming_payments') + assert response.links.mandate == body.get('links')['mandate'] def test_timeout_subscriptions_resume_doesnt_retry(): fixture = helpers.load_fixture('subscriptions')['resume'] with helpers.stub_timeout(fixture) as rsps: - with assert_raises(requests.ConnectTimeout): + with pytest.raises(requests.ConnectTimeout): response = helpers.client.subscriptions.resume(*fixture['url_params']) - assert_equal(1, len(rsps.calls)) + assert len(rsps.calls) == 1 def test_502_subscriptions_resume_doesnt_retry(): fixture = helpers.load_fixture('subscriptions')['resume'] with helpers.stub_502(fixture) as rsps: - with assert_raises(MalformedResponseError): + with pytest.raises(MalformedResponseError): response = helpers.client.subscriptions.resume(*fixture['url_params']) - assert_equal(1, len(rsps.calls)) + assert len(rsps.calls) == 1 @responses.activate @@ -409,41 +369,40 @@ def test_subscriptions_cancel(): response = helpers.client.subscriptions.cancel(*fixture['url_params']) body = fixture['body']['subscriptions'] - assert_is_instance(response, resources.Subscription) - assert_is_not_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal(response.amount, body.get('amount')) - assert_equal(response.app_fee, body.get('app_fee')) - assert_equal(response.count, body.get('count')) - assert_equal(response.created_at, body.get('created_at')) - assert_equal(response.currency, body.get('currency')) - assert_equal(response.day_of_month, body.get('day_of_month')) - assert_equal(response.earliest_charge_date_after_resume, body.get('earliest_charge_date_after_resume')) - assert_equal(response.end_date, body.get('end_date')) - assert_equal(response.id, body.get('id')) - assert_equal(response.interval, body.get('interval')) - assert_equal(response.interval_unit, body.get('interval_unit')) - assert_equal(response.metadata, body.get('metadata')) - assert_equal(response.month, body.get('month')) - assert_equal(response.name, body.get('name')) - assert_equal(response.payment_reference, body.get('payment_reference')) - assert_equal(response.retry_if_possible, body.get('retry_if_possible')) - assert_equal(response.start_date, body.get('start_date')) - assert_equal(response.status, body.get('status')) - assert_equal(response.upcoming_payments, body.get('upcoming_payments')) - assert_equal(response.links.mandate, - body.get('links')['mandate']) + assert isinstance(response, resources.Subscription) + assert responses.calls[-1].request.headers.get('Idempotency-Key') is not None + assert response.amount == body.get('amount') + assert response.app_fee == body.get('app_fee') + assert response.count == body.get('count') + assert response.created_at == body.get('created_at') + assert response.currency == body.get('currency') + assert response.day_of_month == body.get('day_of_month') + assert response.earliest_charge_date_after_resume == body.get('earliest_charge_date_after_resume') + assert response.end_date == body.get('end_date') + assert response.id == body.get('id') + assert response.interval == body.get('interval') + assert response.interval_unit == body.get('interval_unit') + assert response.metadata == body.get('metadata') + assert response.month == body.get('month') + assert response.name == body.get('name') + assert response.payment_reference == body.get('payment_reference') + assert response.retry_if_possible == body.get('retry_if_possible') + assert response.start_date == body.get('start_date') + assert response.status == body.get('status') + assert response.upcoming_payments == body.get('upcoming_payments') + assert response.links.mandate == body.get('links')['mandate'] def test_timeout_subscriptions_cancel_doesnt_retry(): fixture = helpers.load_fixture('subscriptions')['cancel'] with helpers.stub_timeout(fixture) as rsps: - with assert_raises(requests.ConnectTimeout): + with pytest.raises(requests.ConnectTimeout): response = helpers.client.subscriptions.cancel(*fixture['url_params']) - assert_equal(1, len(rsps.calls)) + assert len(rsps.calls) == 1 def test_502_subscriptions_cancel_doesnt_retry(): fixture = helpers.load_fixture('subscriptions')['cancel'] with helpers.stub_502(fixture) as rsps: - with assert_raises(MalformedResponseError): + with pytest.raises(MalformedResponseError): response = helpers.client.subscriptions.cancel(*fixture['url_params']) - assert_equal(1, len(rsps.calls)) + assert len(rsps.calls) == 1 diff --git a/tests/integration/tax_rates_integration_test.py b/tests/integration/tax_rates_integration_test.py index cdd76adf..99f0c195 100644 --- a/tests/integration/tax_rates_integration_test.py +++ b/tests/integration/tax_rates_integration_test.py @@ -5,16 +5,9 @@ import json +import pytest import requests import responses -from nose.tools import ( - assert_equal, - assert_is_instance, - assert_is_none, - assert_is_not_none, - assert_not_equal, - assert_raises -) from gocardless_pro.errors import MalformedResponseError from gocardless_pro import resources @@ -30,55 +23,47 @@ def test_tax_rates_list(): response = helpers.client.tax_rates.list(*fixture['url_params']) body = fixture['body']['tax_rates'] - assert_is_instance(response, list_response.ListResponse) - assert_is_instance(response.records[0], resources.TaxRate) - - assert_equal(response.before, fixture['body']['meta']['cursors']['before']) - assert_equal(response.after, fixture['body']['meta']['cursors']['after']) - assert_is_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal([r.end_date for r in response.records], - [b.get('end_date') for b in body]) - assert_equal([r.id for r in response.records], - [b.get('id') for b in body]) - assert_equal([r.jurisdiction for r in response.records], - [b.get('jurisdiction') for b in body]) - assert_equal([r.percentage for r in response.records], - [b.get('percentage') for b in body]) - assert_equal([r.start_date for r in response.records], - [b.get('start_date') for b in body]) - assert_equal([r.type for r in response.records], - [b.get('type') for b in body]) + assert isinstance(response, list_response.ListResponse) + assert isinstance(response.records[0], resources.TaxRate) + + assert response.before == fixture['body']['meta']['cursors']['before'] + assert response.after == fixture['body']['meta']['cursors']['after'] + assert responses.calls[-1].request.headers.get('Idempotency-Key') is None + assert [r.end_date for r in response.records] == [b.get('end_date') for b in body] + assert [r.id for r in response.records] == [b.get('id') for b in body] + assert [r.jurisdiction for r in response.records] == [b.get('jurisdiction') for b in body] + assert [r.percentage for r in response.records] == [b.get('percentage') for b in body] + assert [r.start_date for r in response.records] == [b.get('start_date') for b in body] + assert [r.type for r in response.records] == [b.get('type') for b in body] @responses.activate def test_timeout_tax_rates_list_retries(): fixture = helpers.load_fixture('tax_rates')['list'] with helpers.stub_timeout_then_response(fixture) as rsps: response = helpers.client.tax_rates.list(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['tax_rates'] - assert_is_instance(response, list_response.ListResponse) - assert_is_instance(response.records[0], resources.TaxRate) + assert isinstance(response, list_response.ListResponse) + assert isinstance(response.records[0], resources.TaxRate) - assert_equal(response.before, fixture['body']['meta']['cursors']['before']) - assert_equal(response.after, fixture['body']['meta']['cursors']['after']) + assert response.before == fixture['body']['meta']['cursors']['before'] + assert response.after == fixture['body']['meta']['cursors']['after'] def test_502_tax_rates_list_retries(): fixture = helpers.load_fixture('tax_rates')['list'] with helpers.stub_502_then_response(fixture) as rsps: response = helpers.client.tax_rates.list(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['tax_rates'] - assert_is_instance(response, list_response.ListResponse) - assert_is_instance(response.records[0], resources.TaxRate) + assert isinstance(response, list_response.ListResponse) + assert isinstance(response.records[0], resources.TaxRate) - assert_equal(response.before, fixture['body']['meta']['cursors']['before']) - assert_equal(response.after, fixture['body']['meta']['cursors']['after']) + assert response.before == fixture['body']['meta']['cursors']['before'] + assert response.after == fixture['body']['meta']['cursors']['after'] @responses.activate def test_tax_rates_all(): @@ -95,9 +80,9 @@ def callback(request): responses.add_callback(fixture['method'], url, callback) all_records = list(helpers.client.tax_rates.all()) - assert_equal(len(all_records), len(fixture['body']['tax_rates']) * 2) + assert len(all_records) == len(fixture['body']['tax_rates']) * 2 for record in all_records: - assert_is_instance(record, resources.TaxRate) + assert isinstance(record, resources.TaxRate) @@ -108,35 +93,33 @@ def test_tax_rates_get(): response = helpers.client.tax_rates.get(*fixture['url_params']) body = fixture['body']['tax_rates'] - assert_is_instance(response, resources.TaxRate) - assert_is_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal(response.end_date, body.get('end_date')) - assert_equal(response.id, body.get('id')) - assert_equal(response.jurisdiction, body.get('jurisdiction')) - assert_equal(response.percentage, body.get('percentage')) - assert_equal(response.start_date, body.get('start_date')) - assert_equal(response.type, body.get('type')) + assert isinstance(response, resources.TaxRate) + assert responses.calls[-1].request.headers.get('Idempotency-Key') is None + assert response.end_date == body.get('end_date') + assert response.id == body.get('id') + assert response.jurisdiction == body.get('jurisdiction') + assert response.percentage == body.get('percentage') + assert response.start_date == body.get('start_date') + assert response.type == body.get('type') @responses.activate def test_timeout_tax_rates_get_retries(): fixture = helpers.load_fixture('tax_rates')['get'] with helpers.stub_timeout_then_response(fixture) as rsps: response = helpers.client.tax_rates.get(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['tax_rates'] - assert_is_instance(response, resources.TaxRate) + assert isinstance(response, resources.TaxRate) def test_502_tax_rates_get_retries(): fixture = helpers.load_fixture('tax_rates')['get'] with helpers.stub_502_then_response(fixture) as rsps: response = helpers.client.tax_rates.get(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['tax_rates'] - assert_is_instance(response, resources.TaxRate) + assert isinstance(response, resources.TaxRate) diff --git a/tests/integration/verification_details_integration_test.py b/tests/integration/verification_details_integration_test.py index a9eb2887..00368a6f 100644 --- a/tests/integration/verification_details_integration_test.py +++ b/tests/integration/verification_details_integration_test.py @@ -5,16 +5,9 @@ import json +import pytest import requests import responses -from nose.tools import ( - assert_equal, - assert_is_instance, - assert_is_none, - assert_is_not_none, - assert_not_equal, - assert_raises -) from gocardless_pro.errors import MalformedResponseError from gocardless_pro import resources @@ -30,42 +23,39 @@ def test_verification_details_create(): response = helpers.client.verification_details.create(*fixture['url_params']) body = fixture['body']['verification_details'] - assert_is_instance(response, resources.VerificationDetail) - assert_is_not_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal(response.address_line1, body.get('address_line1')) - assert_equal(response.address_line2, body.get('address_line2')) - assert_equal(response.address_line3, body.get('address_line3')) - assert_equal(response.city, body.get('city')) - assert_equal(response.company_number, body.get('company_number')) - assert_equal(response.description, body.get('description')) - assert_equal(response.directors, body.get('directors')) - assert_equal(response.name, body.get('name')) - assert_equal(response.postal_code, body.get('postal_code')) - assert_equal(response.links.creditor, - body.get('links')['creditor']) + assert isinstance(response, resources.VerificationDetail) + assert responses.calls[-1].request.headers.get('Idempotency-Key') is not None + assert response.address_line1 == body.get('address_line1') + assert response.address_line2 == body.get('address_line2') + assert response.address_line3 == body.get('address_line3') + assert response.city == body.get('city') + assert response.company_number == body.get('company_number') + assert response.description == body.get('description') + assert response.directors == body.get('directors') + assert response.name == body.get('name') + assert response.postal_code == body.get('postal_code') + assert response.links.creditor == body.get('links')['creditor'] @responses.activate def test_timeout_verification_details_create_retries(): fixture = helpers.load_fixture('verification_details')['create'] with helpers.stub_timeout_then_response(fixture) as rsps: response = helpers.client.verification_details.create(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['verification_details'] - assert_is_instance(response, resources.VerificationDetail) + assert isinstance(response, resources.VerificationDetail) def test_502_verification_details_create_retries(): fixture = helpers.load_fixture('verification_details')['create'] with helpers.stub_502_then_response(fixture) as rsps: response = helpers.client.verification_details.create(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['verification_details'] - assert_is_instance(response, resources.VerificationDetail) + assert isinstance(response, resources.VerificationDetail) @responses.activate @@ -75,61 +65,50 @@ def test_verification_details_list(): response = helpers.client.verification_details.list(*fixture['url_params']) body = fixture['body']['verification_details'] - assert_is_instance(response, list_response.ListResponse) - assert_is_instance(response.records[0], resources.VerificationDetail) - - assert_equal(response.before, fixture['body']['meta']['cursors']['before']) - assert_equal(response.after, fixture['body']['meta']['cursors']['after']) - assert_is_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal([r.address_line1 for r in response.records], - [b.get('address_line1') for b in body]) - assert_equal([r.address_line2 for r in response.records], - [b.get('address_line2') for b in body]) - assert_equal([r.address_line3 for r in response.records], - [b.get('address_line3') for b in body]) - assert_equal([r.city for r in response.records], - [b.get('city') for b in body]) - assert_equal([r.company_number for r in response.records], - [b.get('company_number') for b in body]) - assert_equal([r.description for r in response.records], - [b.get('description') for b in body]) - assert_equal([r.directors for r in response.records], - [b.get('directors') for b in body]) - assert_equal([r.name for r in response.records], - [b.get('name') for b in body]) - assert_equal([r.postal_code for r in response.records], - [b.get('postal_code') for b in body]) + assert isinstance(response, list_response.ListResponse) + assert isinstance(response.records[0], resources.VerificationDetail) + + assert response.before == fixture['body']['meta']['cursors']['before'] + assert response.after == fixture['body']['meta']['cursors']['after'] + assert responses.calls[-1].request.headers.get('Idempotency-Key') is None + assert [r.address_line1 for r in response.records] == [b.get('address_line1') for b in body] + assert [r.address_line2 for r in response.records] == [b.get('address_line2') for b in body] + assert [r.address_line3 for r in response.records] == [b.get('address_line3') for b in body] + assert [r.city for r in response.records] == [b.get('city') for b in body] + assert [r.company_number for r in response.records] == [b.get('company_number') for b in body] + assert [r.description for r in response.records] == [b.get('description') for b in body] + assert [r.directors for r in response.records] == [b.get('directors') for b in body] + assert [r.name for r in response.records] == [b.get('name') for b in body] + assert [r.postal_code for r in response.records] == [b.get('postal_code') for b in body] @responses.activate def test_timeout_verification_details_list_retries(): fixture = helpers.load_fixture('verification_details')['list'] with helpers.stub_timeout_then_response(fixture) as rsps: response = helpers.client.verification_details.list(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['verification_details'] - assert_is_instance(response, list_response.ListResponse) - assert_is_instance(response.records[0], resources.VerificationDetail) + assert isinstance(response, list_response.ListResponse) + assert isinstance(response.records[0], resources.VerificationDetail) - assert_equal(response.before, fixture['body']['meta']['cursors']['before']) - assert_equal(response.after, fixture['body']['meta']['cursors']['after']) + assert response.before == fixture['body']['meta']['cursors']['before'] + assert response.after == fixture['body']['meta']['cursors']['after'] def test_502_verification_details_list_retries(): fixture = helpers.load_fixture('verification_details')['list'] with helpers.stub_502_then_response(fixture) as rsps: response = helpers.client.verification_details.list(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['verification_details'] - assert_is_instance(response, list_response.ListResponse) - assert_is_instance(response.records[0], resources.VerificationDetail) + assert isinstance(response, list_response.ListResponse) + assert isinstance(response.records[0], resources.VerificationDetail) - assert_equal(response.before, fixture['body']['meta']['cursors']['before']) - assert_equal(response.after, fixture['body']['meta']['cursors']['after']) + assert response.before == fixture['body']['meta']['cursors']['before'] + assert response.after == fixture['body']['meta']['cursors']['after'] @responses.activate def test_verification_details_all(): @@ -146,8 +125,8 @@ def callback(request): responses.add_callback(fixture['method'], url, callback) all_records = list(helpers.client.verification_details.all()) - assert_equal(len(all_records), len(fixture['body']['verification_details']) * 2) + assert len(all_records) == len(fixture['body']['verification_details']) * 2 for record in all_records: - assert_is_instance(record, resources.VerificationDetail) + assert isinstance(record, resources.VerificationDetail) diff --git a/tests/integration/webhooks_integration_test.py b/tests/integration/webhooks_integration_test.py index 43522646..5f7ea24c 100644 --- a/tests/integration/webhooks_integration_test.py +++ b/tests/integration/webhooks_integration_test.py @@ -5,16 +5,9 @@ import json +import pytest import requests import responses -from nose.tools import ( - assert_equal, - assert_is_instance, - assert_is_none, - assert_is_not_none, - assert_not_equal, - assert_raises -) from gocardless_pro.errors import MalformedResponseError from gocardless_pro import resources @@ -30,69 +23,54 @@ def test_webhooks_list(): response = helpers.client.webhooks.list(*fixture['url_params']) body = fixture['body']['webhooks'] - assert_is_instance(response, list_response.ListResponse) - assert_is_instance(response.records[0], resources.Webhook) - - assert_equal(response.before, fixture['body']['meta']['cursors']['before']) - assert_equal(response.after, fixture['body']['meta']['cursors']['after']) - assert_is_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal([r.created_at for r in response.records], - [b.get('created_at') for b in body]) - assert_equal([r.id for r in response.records], - [b.get('id') for b in body]) - assert_equal([r.is_test for r in response.records], - [b.get('is_test') for b in body]) - assert_equal([r.request_body for r in response.records], - [b.get('request_body') for b in body]) - assert_equal([r.request_headers for r in response.records], - [b.get('request_headers') for b in body]) - assert_equal([r.response_body for r in response.records], - [b.get('response_body') for b in body]) - assert_equal([r.response_body_truncated for r in response.records], - [b.get('response_body_truncated') for b in body]) - assert_equal([r.response_code for r in response.records], - [b.get('response_code') for b in body]) - assert_equal([r.response_headers for r in response.records], - [b.get('response_headers') for b in body]) - assert_equal([r.response_headers_content_truncated for r in response.records], - [b.get('response_headers_content_truncated') for b in body]) - assert_equal([r.response_headers_count_truncated for r in response.records], - [b.get('response_headers_count_truncated') for b in body]) - assert_equal([r.successful for r in response.records], - [b.get('successful') for b in body]) - assert_equal([r.url for r in response.records], - [b.get('url') for b in body]) + assert isinstance(response, list_response.ListResponse) + assert isinstance(response.records[0], resources.Webhook) + + assert response.before == fixture['body']['meta']['cursors']['before'] + assert response.after == fixture['body']['meta']['cursors']['after'] + assert responses.calls[-1].request.headers.get('Idempotency-Key') is None + assert [r.created_at for r in response.records] == [b.get('created_at') for b in body] + assert [r.id for r in response.records] == [b.get('id') for b in body] + assert [r.is_test for r in response.records] == [b.get('is_test') for b in body] + assert [r.request_body for r in response.records] == [b.get('request_body') for b in body] + assert [r.request_headers for r in response.records] == [b.get('request_headers') for b in body] + assert [r.response_body for r in response.records] == [b.get('response_body') for b in body] + assert [r.response_body_truncated for r in response.records] == [b.get('response_body_truncated') for b in body] + assert [r.response_code for r in response.records] == [b.get('response_code') for b in body] + assert [r.response_headers for r in response.records] == [b.get('response_headers') for b in body] + assert [r.response_headers_content_truncated for r in response.records] == [b.get('response_headers_content_truncated') for b in body] + assert [r.response_headers_count_truncated for r in response.records] == [b.get('response_headers_count_truncated') for b in body] + assert [r.successful for r in response.records] == [b.get('successful') for b in body] + assert [r.url for r in response.records] == [b.get('url') for b in body] @responses.activate def test_timeout_webhooks_list_retries(): fixture = helpers.load_fixture('webhooks')['list'] with helpers.stub_timeout_then_response(fixture) as rsps: response = helpers.client.webhooks.list(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['webhooks'] - assert_is_instance(response, list_response.ListResponse) - assert_is_instance(response.records[0], resources.Webhook) + assert isinstance(response, list_response.ListResponse) + assert isinstance(response.records[0], resources.Webhook) - assert_equal(response.before, fixture['body']['meta']['cursors']['before']) - assert_equal(response.after, fixture['body']['meta']['cursors']['after']) + assert response.before == fixture['body']['meta']['cursors']['before'] + assert response.after == fixture['body']['meta']['cursors']['after'] def test_502_webhooks_list_retries(): fixture = helpers.load_fixture('webhooks')['list'] with helpers.stub_502_then_response(fixture) as rsps: response = helpers.client.webhooks.list(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['webhooks'] - assert_is_instance(response, list_response.ListResponse) - assert_is_instance(response.records[0], resources.Webhook) + assert isinstance(response, list_response.ListResponse) + assert isinstance(response.records[0], resources.Webhook) - assert_equal(response.before, fixture['body']['meta']['cursors']['before']) - assert_equal(response.after, fixture['body']['meta']['cursors']['after']) + assert response.before == fixture['body']['meta']['cursors']['before'] + assert response.after == fixture['body']['meta']['cursors']['after'] @responses.activate def test_webhooks_all(): @@ -109,9 +87,9 @@ def callback(request): responses.add_callback(fixture['method'], url, callback) all_records = list(helpers.client.webhooks.all()) - assert_equal(len(all_records), len(fixture['body']['webhooks']) * 2) + assert len(all_records) == len(fixture['body']['webhooks']) * 2 for record in all_records: - assert_is_instance(record, resources.Webhook) + assert isinstance(record, resources.Webhook) @@ -122,44 +100,42 @@ def test_webhooks_get(): response = helpers.client.webhooks.get(*fixture['url_params']) body = fixture['body']['webhooks'] - assert_is_instance(response, resources.Webhook) - assert_is_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal(response.created_at, body.get('created_at')) - assert_equal(response.id, body.get('id')) - assert_equal(response.is_test, body.get('is_test')) - assert_equal(response.request_body, body.get('request_body')) - assert_equal(response.request_headers, body.get('request_headers')) - assert_equal(response.response_body, body.get('response_body')) - assert_equal(response.response_body_truncated, body.get('response_body_truncated')) - assert_equal(response.response_code, body.get('response_code')) - assert_equal(response.response_headers, body.get('response_headers')) - assert_equal(response.response_headers_content_truncated, body.get('response_headers_content_truncated')) - assert_equal(response.response_headers_count_truncated, body.get('response_headers_count_truncated')) - assert_equal(response.successful, body.get('successful')) - assert_equal(response.url, body.get('url')) + assert isinstance(response, resources.Webhook) + assert responses.calls[-1].request.headers.get('Idempotency-Key') is None + assert response.created_at == body.get('created_at') + assert response.id == body.get('id') + assert response.is_test == body.get('is_test') + assert response.request_body == body.get('request_body') + assert response.request_headers == body.get('request_headers') + assert response.response_body == body.get('response_body') + assert response.response_body_truncated == body.get('response_body_truncated') + assert response.response_code == body.get('response_code') + assert response.response_headers == body.get('response_headers') + assert response.response_headers_content_truncated == body.get('response_headers_content_truncated') + assert response.response_headers_count_truncated == body.get('response_headers_count_truncated') + assert response.successful == body.get('successful') + assert response.url == body.get('url') @responses.activate def test_timeout_webhooks_get_retries(): fixture = helpers.load_fixture('webhooks')['get'] with helpers.stub_timeout_then_response(fixture) as rsps: response = helpers.client.webhooks.get(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['webhooks'] - assert_is_instance(response, resources.Webhook) + assert isinstance(response, resources.Webhook) def test_502_webhooks_get_retries(): fixture = helpers.load_fixture('webhooks')['get'] with helpers.stub_502_then_response(fixture) as rsps: response = helpers.client.webhooks.get(*fixture['url_params']) - assert_equal(2, len(rsps.calls)) - assert_equal(rsps.calls[0].request.headers.get('Idempotency-Key'), - rsps.calls[1].request.headers.get('Idempotency-Key')) + assert len(rsps.calls) == 2 + assert rsps.calls[0].request.headers.get('Idempotency-Key') == rsps.calls[1].request.headers.get('Idempotency-Key') body = fixture['body']['webhooks'] - assert_is_instance(response, resources.Webhook) + assert isinstance(response, resources.Webhook) @responses.activate @@ -169,33 +145,33 @@ def test_webhooks_retry(): response = helpers.client.webhooks.retry(*fixture['url_params']) body = fixture['body']['webhooks'] - assert_is_instance(response, resources.Webhook) - assert_is_not_none(responses.calls[-1].request.headers.get('Idempotency-Key')) - assert_equal(response.created_at, body.get('created_at')) - assert_equal(response.id, body.get('id')) - assert_equal(response.is_test, body.get('is_test')) - assert_equal(response.request_body, body.get('request_body')) - assert_equal(response.request_headers, body.get('request_headers')) - assert_equal(response.response_body, body.get('response_body')) - assert_equal(response.response_body_truncated, body.get('response_body_truncated')) - assert_equal(response.response_code, body.get('response_code')) - assert_equal(response.response_headers, body.get('response_headers')) - assert_equal(response.response_headers_content_truncated, body.get('response_headers_content_truncated')) - assert_equal(response.response_headers_count_truncated, body.get('response_headers_count_truncated')) - assert_equal(response.successful, body.get('successful')) - assert_equal(response.url, body.get('url')) + assert isinstance(response, resources.Webhook) + assert responses.calls[-1].request.headers.get('Idempotency-Key') is not None + assert response.created_at == body.get('created_at') + assert response.id == body.get('id') + assert response.is_test == body.get('is_test') + assert response.request_body == body.get('request_body') + assert response.request_headers == body.get('request_headers') + assert response.response_body == body.get('response_body') + assert response.response_body_truncated == body.get('response_body_truncated') + assert response.response_code == body.get('response_code') + assert response.response_headers == body.get('response_headers') + assert response.response_headers_content_truncated == body.get('response_headers_content_truncated') + assert response.response_headers_count_truncated == body.get('response_headers_count_truncated') + assert response.successful == body.get('successful') + assert response.url == body.get('url') def test_timeout_webhooks_retry_doesnt_retry(): fixture = helpers.load_fixture('webhooks')['retry'] with helpers.stub_timeout(fixture) as rsps: - with assert_raises(requests.ConnectTimeout): + with pytest.raises(requests.ConnectTimeout): response = helpers.client.webhooks.retry(*fixture['url_params']) - assert_equal(1, len(rsps.calls)) + assert len(rsps.calls) == 1 def test_502_webhooks_retry_doesnt_retry(): fixture = helpers.load_fixture('webhooks')['retry'] with helpers.stub_502(fixture) as rsps: - with assert_raises(MalformedResponseError): + with pytest.raises(MalformedResponseError): response = helpers.client.webhooks.retry(*fixture['url_params']) - assert_equal(1, len(rsps.calls)) + assert len(rsps.calls) == 1 diff --git a/tests/webhooks_test.py b/tests/webhooks_test.py new file mode 100644 index 00000000..eabfb0ac --- /dev/null +++ b/tests/webhooks_test.py @@ -0,0 +1,36 @@ +import os + +import pytest + +from gocardless_pro.webhooks import parse +from gocardless_pro.errors import InvalidSignatureError + +fixture = open( + os.path.join( + os.path.dirname(__file__), + 'fixtures', + 'webhook_body.json' + ) +).read().strip() + +fixture_signature = "2693754819d3e32d7e8fcb13c729631f316c6de8dc1cf634d6527f1c07276e7e" +key = "ED7D658C-D8EB-4941-948B-3973214F2D49" + +def test_it_parses_the_body(): + result = parse(fixture, key, fixture_signature) + assert len(result) == 2 + + first_event = result[0] + assert first_event.id == "EV00BD05S5VM2T" + +def test_it_parses_the_body_from_bytes(): + result = parse(bytearray(fixture, 'utf-8'), key, fixture_signature) + assert len(result) == 2 + + first_event = result[0] + assert first_event.id == "EV00BD05S5VM2T" + +def test_it_raises_with_invalid_signature(): + with pytest.raises(InvalidSignatureError): + wrong_key = "anotherkey" + parse(fixture, wrong_key, fixture_signature)