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()
def test_delete(self): id = 'cus_39o4Fv82E1et5Xb' with HTTMock(helper.mock_api('/customers/' + id, 'customers/retrieve.txt')): customer = WebPay('test_key').customers.retrieve(id) with HTTMock(helper.mock_api('/customers/' + id, 'customers/delete.txt')): assert customer.delete()
def test_refund_without_amount(self): id = 'ch_bWp5EG9smcCYeEx' with HTTMock(helper.mock_api('/charges/' + id, 'charges/retrieve.txt')): charge = WebPay('test_key').charges.retrieve(id) with HTTMock(helper.mock_api('/charges/%s/refund' % id, 'charges/refund.txt')): charge.refund() assert charge.refunded assert charge.amount_refunded == 400
def test_message_post(self): chatwork = pyChatWork('test_key') with HTTMock(helper.mock_api('/rooms', 'room/list.txt')): rooms = chatwork.room.list() assert len(rooms) == 2 assert rooms[0].room_id == 123 assert rooms[1].room_id == 124 with HTTMock(helper.mock_api('/rooms', 'room/message_post.txt')): msg = chatwork.room.message(rooms[0], "Test") assert msg.message_id == 1234
def test_save_only_updated_fields(self): id = 'cus_39o4Fv82E1et5Xb' with HTTMock(helper.mock_api('/customers/' + id, 'customers/retrieve.txt')): customer = WebPay('test_key').customers.retrieve(id) customer.email = '*****@*****.**' with HTTMock(helper.mock_api('/customers/' + id, 'customers/update.txt', data={'email': '*****@*****.**'})): customer.save() assert customer.email == '*****@*****.**'
def test_capture(self): id = 'ch_2X01NDedxdrRcA3' with HTTMock(helper.mock_api('/charges/' + id, 'charges/retrieve_not_captured.txt')): charge = WebPay('test_key').charges.retrieve(id) with HTTMock(helper.mock_api('/charges/%s/capture' % id, 'charges/capture.txt')): charge.capture(1000) assert charge.captured assert charge.paid assert charge.amount == 1000
def test_retrieve(self): id = 'tok_3dw2T20rzekM1Kf' with HTTMock(helper.mock_api('/tokens/' + id, 'tokens/retrieve.txt')): token = WebPay('test_key').tokens.retrieve(id) assert token.id == id assert token.card.name == 'YUUKO SHIONJI'
def test_retrieve(self): with HTTMock(helper.mock_api('/me', 'account/retrieve.txt')): account = pyChatWork('test_key').account.retrieve() assert account.chatwork_id == 'tarochatworkid' assert account.mail == '*****@*****.**' assert account.avatar_image_url == 'https://example.com/abc.png'
def test_retrieve(self): with HTTMock(helper.mock_api('/account', 'account/retrieve.txt')): account = WebPay('test_key').account.retrieve() assert account.id == 'acct_2Cmdexb7J2r78rz' assert account.email == '*****@*****.**' assert account.currencies_supported == ['jpy']
def test_retrieve(self): id = 'evt_39o9oUevb5NCeM1' with HTTMock(helper.mock_api('/events/' + id, 'events/retrieve.txt')): event = WebPay('test_key').events.retrieve(id) assert event.id == id assert event.data.object.email == '*****@*****.**'
def test_create_without_card_key(self): with HTTMock(helper.mock_api('/tokens', 'tokens/create.txt', data={'card': self._card_data})): token = WebPay('test_key').tokens.create(**self._card_data) assert token.id == 'tok_3dw2T20rzekM1Kf'
def test_retrieve_deleted_customer(self): id = 'cus_7GafGMbML8R28Io' with HTTMock(helper.mock_api('/customers/' + id, 'customers/retrieve_deleted.txt')): customer = WebPay('test_key').customers.retrieve(id) assert customer.id == id assert customer.is_deleted()
def test_create(self): with HTTMock(helper.mock_api('/tokens', 'tokens/create.txt', data={'card': self._card_data})): token = WebPay('test_key').tokens.create(card=self._card_data) assert token.id == 'tok_3dw2T20rzekM1Kf' assert not token.used assert token.card.name == 'YUUKO SHIONJI'
def test_response_json_is_broken(self): with pytest.raises(errors.ApiConnectionError) as excinfo: with HTTMock(helper.mock_api('/charges', 'errors/broken_json.txt')): WebPay('test_key').charges.all() exc = excinfo.value assert 'Error while parsing response JSON' in exc.__str__() assert exc.error_info is None assert exc.status is None
def test_server_not_found(self): with pytest.raises(errors.ApiConnectionError) as excinfo: with HTTMock(helper.mock_api('/charges', 'errors/not_found.txt')): WebPay('test_key', 'http://localhost:123').charges.all() exc = excinfo.value assert 'Error while requesting API' in exc.__str__() assert exc.error_info is None assert exc.status is None
def test_request_raises_not_found_without_params(self): with pytest.raises(errors.InvalidRequestError) as excinfo: with HTTMock(helper.mock_api('/charges', 'errors/not_found_url.txt')): WebPay('test_key').charges.all() exc = excinfo.value assert exc.__str__() == 'Unrecognized request URL.' assert exc.type == 'invalid_request_error' assert exc.status == 404
def test_request_raises_unauthorized(self): with pytest.raises(errors.AuthenticationError) as excinfo: with HTTMock(helper.mock_api('/charges', 'errors/unauthorized.txt')): WebPay('test_key').charges.all() exc = excinfo.value assert exc.__str__() == \ 'Invalid API key provided. Check your API key is correct.' assert exc.status == 401
def test_all(self): with HTTMock(helper.mock_api('/charges', 'charges/all.txt')): charges = WebPay('test_api').charges \ .all(count=3, offset=0, created={'gt': 1378000000}) assert charges.url == '/v1/charges' assert charges.data[0].description == 'Test Charge from Java' assert charges.data[0].card.name == 'KEI KUBO' assert charges._client == charges.data[0]._client
def test_retrieve(self): id = 'cus_39o4Fv82E1et5Xb' with HTTMock(helper.mock_api('/customers/' + id, 'customers/retrieve.txt')): customer = WebPay('test_key').customers.retrieve(id) assert customer.id == id assert not customer.is_deleted() assert customer.active_card.name == 'YUUKO SHIONJI'
def test_retrieve_no_card_customer(self): id = 'cus_eS6dGfa8BeUlbSQ' with HTTMock(helper.mock_api('/customers/' + id, 'customers/retrieve_no_card.txt')): customer = WebPay('test_key').customers.retrieve(id) assert customer.id == id assert not customer.is_deleted() assert customer.active_card is None
def test_request_raises_api_exception(self): with pytest.raises(errors.ApiError) as excinfo: with HTTMock(helper.mock_api('/charges', 'errors/unknown_api_error.txt')): WebPay('test_key').charges.all() exc = excinfo.value assert exc.__str__() == 'Unknown error occurred' assert exc.type == 'api_error' assert exc.status == 500
def test_all(self): conds = {'count': 3, 'offset': 0, 'created': {'gt': 1378000000}} with HTTMock(helper.mock_api('/customers', 'customers/all.txt', data=conds)): customers = WebPay('test_api').customers.all(**conds) assert customers.url == '/v1/customers' assert customers.data[0].description == 'Test Customer from Java' assert customers.data[0].active_card.name == 'YUUKO SHIONJI'
def test_request_raises_invalid_request(self): with pytest.raises(errors.InvalidRequestError) as excinfo: with HTTMock(helper.mock_api('/charges', 'errors/bad_request.txt')): WebPay('test_key').charges.all() exc = excinfo.value assert exc.__str__() == 'Missing required param: currency' assert exc.type == 'invalid_request_error' assert exc.param == 'currency' assert exc.status == 400
def test_all(self): conds = {'type': '*.created'} with HTTMock(helper.mock_api('/events', 'events/all_with_type.txt', data=conds)): events = WebPay('test_api').events.all(**conds) assert events.url == '/v1/events' assert events.data[0].type == 'customer.created' assert events.data[0].data.object.active_card.name == 'YUUKO SHIONJI'
def test_request_raises_not_found(self): with pytest.raises(errors.InvalidRequestError) as excinfo: with HTTMock(helper.mock_api('/charges', 'errors/not_found.txt')): WebPay('test_key').charges.all() exc = excinfo.value assert exc.__str__() == 'No such charge: foo' assert exc.type == 'invalid_request_error' assert exc.param == 'id' assert exc.status == 404
def test_request_raises_card_error_without_param(self): with pytest.raises(errors.CardError) as excinfo: with HTTMock(helper.mock_api('/charges', 'errors/card_error_declined.txt')): WebPay('test_key').charges.all() exc = excinfo.value assert exc.__str__() == 'This card cannot be used.' assert exc.type == 'card_error' assert exc.code == 'card_declined' assert exc.param is None assert exc.status == 402
def test_request_raises_card_error(self): with pytest.raises(errors.CardError) as excinfo: with HTTMock(helper.mock_api('/charges', 'errors/card_error.txt')): WebPay('test_key').charges.all() exc = excinfo.value assert exc.__str__() == 'Your card number is incorrect' assert exc.type == 'card_error' assert exc.code == 'incorrect_number' assert exc.param == 'number' assert exc.status == 402
def test_retrieve(self): id = 'ch_bWp5EG9smcCYeEx' with HTTMock(helper.mock_api('/charges/' + id, 'charges/retrieve.txt')): charge = WebPay('test_key').charges.retrieve(id) assert charge.id == id # アイテムの購入 assert charge.description.encode('utf-8') == \ b'\xe3\x82\xa2\xe3\x82\xa4\xe3\x83\x86\xe3\x83\xa0\xe3\x81\xae' + \ b'\xe8\xb3\xbc\xe5\x85\xa5' assert charge.card.name == 'KEI KUBO'
def test_create(self): with HTTMock(helper.mock_api('/customers', 'customers/create.txt')): customer = WebPay('test_key').customers.create( description='Test Customer from Java', email='*****@*****.**', card={ 'number': '4242-4242-4242-4242', 'exp_month': 12, 'exp_year': 2015, 'cvc': 123, 'name': 'YUUKO SHIONJI' }, ) assert customer.id == 'cus_39o4Fv82E1et5Xb' assert customer.description == 'Test Customer from Java' assert customer.active_card.name == 'YUUKO SHIONJI'
def test_create(self): with HTTMock(helper.mock_api('/charges', 'charges/create.txt')): charge = WebPay('test_key').charges.create( amount=1000, currecy='jpy', card={ 'number': '4242-4242-4242-4242', 'exp_month': 12, 'exp_year': 2015, 'cvc': 123, 'name': 'YUUKO SHIONJI' }, description='Test Charge from Java', ) assert charge.id == 'ch_2SS17Oh1r8d2djE' assert charge.description == 'Test Charge from Java' assert charge.card.name == 'YUUKO SHIONJI'
def test_rooms(self): with HTTMock(helper.mock_api('/rooms', 'room/list.txt')): rooms = pyChatWork('test_key').room.list() assert len(rooms) == 2 assert rooms[0].room_id == 123 assert rooms[1].room_id == 124
def test_delete_data(self): with HTTMock(helper.mock_api('/account/data', 'account/delete.txt')): assert WebPay('test_key').account.delete_data()