def test_save(self): id = 'cus_39o4Fv82E1et5Xb' with HTTMock(helper.mock_api('/customers/' + id, 'customers/retrieve.txt')): customer = WebPay('test_key').customers.retrieve(id) old_card = customer.active_card expected = { 'email': '*****@*****.**', 'description': 'New description', 'card': { 'number': '4242-4242-4242-4242', 'exp_month': 12, 'exp_year': 2016, 'cvc': 123, 'name': 'YUUKO SHIONJI', }} customer.email = expected['email'] customer.description = expected['description'] customer.new_card = expected['card'] assert customer.email == '*****@*****.**' assert customer.active_card == old_card with HTTMock(helper.mock_api('/customers/' + id, 'customers/update.txt', data=expected)): new_customer = customer.save() assert customer.email == '*****@*****.**' assert customer.active_card.exp_year == 2016 assert new_customer == customer
def test_calling_save_twice_sends_nothing(self): id = 'cus_39o4Fv82E1et5Xb' with HTTMock(helper.mock_api('/customers/' + id, 'customers/retrieve.txt')): customer = WebPay('test_key').customers.retrieve(id) expected = { 'card': { 'number': '4242-4242-4242-4242', 'exp_month': 12, 'exp_year': 2016, 'cvc': 123, 'name': 'YUUKO SHIONJI', }, 'email': '*****@*****.**', 'description': 'New description', } customer.email = expected['email'] customer.description = expected['description'] customer.new_card = expected['card'] with HTTMock(helper.mock_api('/customers/' + id, 'customers/update.txt', data=expected)): customer.save() with HTTMock(helper.mock_api('/customers/' + id, 'customers/update.txt', data={})): customer.save()