Skip to content
This repository has been archived by the owner on Aug 1, 2023. It is now read-only.

Commit

Permalink
Support for closing accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
yorinasub17 committed Aug 22, 2014
1 parent bd927bb commit bd3e023
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
4 changes: 4 additions & 0 deletions mocurly/endpoints.py
Expand Up @@ -111,6 +111,10 @@ def update(self, pk, update_info, format=BaseRecurlyEndpoint.XML):
del update_info['billing_info']
return super(AccountsEndpoint, self).update(pk, update_info, format=format)

def delete(self, pk):
AccountsEndpoint.backend.update_object(pk, {'state': 'closed'})
billing_info_backend.delete_object(pk)

def billing_info_uris(self, obj):
uri_out = {}
uri_out['account_uri'] = recurly.base_uri() + AccountsEndpoint.base_uri + '/' + obj['account']
Expand Down
42 changes: 42 additions & 0 deletions tests/test_account.py
Expand Up @@ -103,6 +103,22 @@ def test_simple_get_account(self):
else:
self.assertEqual(getattr(account, k), v)

def test_close(self):
self.base_account_data['hosted_login_token'] = 'abcd1234'
self.base_account_data['created_at'] = '2014-08-11'
mocurly.backend.accounts_backend.add_object(self.base_account_data['account_code'], self.base_account_data)
self.base_billing_info_data['account'] = self.base_account_data['account_code']
mocurly.backend.billing_info_backend.add_object(self.base_account_data['account_code'], self.base_billing_info_data)

account = recurly.Account.get(self.base_account_data['account_code'])
account.delete()

self.assertEqual(len(mocurly.backend.accounts_backend.datastore), 1) # only marks account as closed, but...
self.assertEqual(len(mocurly.backend.billing_info_backend.datastore), 0) # billing info should be deleted
account = mocurly.backend.accounts_backend.get_object(self.base_account_data['account_code'])
self.assertEqual(account['state'], 'closed')


def test_address_get_account(self):
self.base_account_data['hosted_login_token'] = 'abcd1234'
self.base_account_data['created_at'] = '2014-08-11'
Expand Down Expand Up @@ -145,6 +161,32 @@ def test_billing_info_get_account(self):
continue # skip
self.assertEqual(getattr(billing_info, k), v)

def test_update_billing_info(self):
self.base_account_data['hosted_login_token'] = 'abcd1234'
self.base_account_data['created_at'] = '2014-08-11'
mocurly.backend.accounts_backend.add_object(self.base_account_data['account_code'], self.base_account_data)
self.base_billing_info_data['account'] = self.base_account_data['account_code']
mocurly.backend.billing_info_backend.add_object(self.base_account_data['account_code'], self.base_billing_info_data)

account = recurly.Account.get(self.base_account_data['account_code'])
billing_info = account.billing_info
billing_info.first_name = 'Verena'
billing_info.last_name = 'Example'
billing_info.number = '4111-1111-1111-1111'
billing_info.verification_value = '123'
billing_info.month = 11
billing_info.year = 2015
billing_info.save()

self.assertEqual(len(mocurly.backend.billing_info_backend.datastore), 1)
billing_info_backed = mocurly.backend.billing_info_backend.get_object(self.base_account_data['account_code'])
self.assertEqual(billing_info_backed['first_name'], 'Verena')
self.assertEqual(billing_info_backed['last_name'], 'Example')
self.assertEqual(billing_info_backed['number'], '4111-1111-1111-1111')
self.assertEqual(billing_info_backed['verification_value'], '123')
self.assertEqual(billing_info_backed['month'], '11')
self.assertEqual(billing_info_backed['year'], '2015')

def test_list_account(self):
self.base_account_data['hosted_login_token'] = 'abcd1234'
self.base_account_data['created_at'] = '2014-08-11'
Expand Down

0 comments on commit bd3e023

Please sign in to comment.