Ejemplo n.º 1
0
    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
Ejemplo n.º 2
0
    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()
Ejemplo n.º 3
0
    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
Ejemplo n.º 4
0
    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()
Ejemplo n.º 5
0
    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'
Ejemplo n.º 6
0
    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
Ejemplo n.º 7
0
    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 == '*****@*****.**'
Ejemplo n.º 8
0
    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
Ejemplo n.º 9
0
    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()
Ejemplo n.º 10
0
    def test_request_raises_not_found_with_ja_language(self):
        webpay = WebPay('test_key')
        webpay.accept_language('ja')

        @urlmatch(scheme='https', netloc='api.webpay.jp', path='/v1/customers/cus_eS6dGfa8BeUlbS')
        def mock(url, request):
            assert request.headers['Accept-Language'] == 'ja'
            return helper.response_from_file('errors/not_found_ja.txt', request)

        with pytest.raises(errors.InvalidRequestError) as excinfo:
            with HTTMock(mock):
                webpay.customers.retrieve('cus_eS6dGfa8BeUlbS')
        exc = excinfo.value
        assert exc.args[0].encode('utf-8') == \
            b'\xe8\xa9\xb2\xe5\xbd\x93\xe3\x81\x99\xe3\x82\x8b\xe9\xa1\xa7\xe5\xae\xa2\xe3\x81' + \
            b'\x8c\xe3\x81\x82\xe3\x82\x8a\xe3\x81\xbe\xe3\x81\x9b\xe3\x82\x93: cus_eS6dGfa8BeUlbS'