Skip to content

Commit

Permalink
Merge pull request #87 from gocardless/template-changes
Browse files Browse the repository at this point in the history
Changes generated by 69082df64fd97438839e8a0a8e855f389d359d50
  • Loading branch information
hjheath authored Sep 19, 2023
2 parents 69e6896 + 624a345 commit 47c8ee0
Show file tree
Hide file tree
Showing 62 changed files with 3,361 additions and 4,525 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
<!-- @format -->

# 1.46.2

- Remove nose in favour of pytest
- Remove inaccessible MandateRequestConstraints resource

# 1.46.1

- Fix throwing error on empty 204 responses
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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``.

Expand Down
2 changes: 1 addition & 1 deletion gocardless_pro/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

from .client import Client

__version__ = '1.46.1'
__version__ = '1.46.2'

4 changes: 2 additions & 2 deletions gocardless_pro/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}
Expand All @@ -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()),
Expand Down
3 changes: 1 addition & 2 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -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
pytest
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
53 changes: 25 additions & 28 deletions tests/api_client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -26,119 +26,116 @@ 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():
fixture = helpers.load_fixture('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():
fixture = helpers.load_fixture('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():
fixture = helpers.load_fixture('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():
fixture = helpers.idempotent_creation_conflict_body('PM00001078ZJJN')
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():
fixture = helpers.load_fixture('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'})
116 changes: 116 additions & 0 deletions tests/client_test.py
Original file line number Diff line number Diff line change
@@ -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)

61 changes: 61 additions & 0 deletions tests/error_test.py
Original file line number Diff line number Diff line change
@@ -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"
Loading

0 comments on commit 47c8ee0

Please sign in to comment.