Ejemplo n.º 1
0
    def test_invoice(self, post_method):
        api = self.make_one('MOCK_API_KEY', endpoint='http://localhost')
        customer = Customer(api, dict(guid='MOCK_CUSTOMER_GUID'))
        mock_invoice_data = dict(
            guid='MOCK_INVOICE_GUID',
        )
        mock_response = mock.Mock(
            json=lambda: mock_invoice_data,
            status_code=200,
        )
        post_method.return_value = mock_response

        invoice = customer.invoice(
            amount='5566',
            title='I want you bankrupt invoice',
            funding_instrument_uri='MOCK_INSTRUMENT_URI',
            appears_on_statement_as='hi there',
            items=[
                dict(name='foo', amount=1234),
                dict(type='debit', name='bar', amount=56, quantity=78, 
                     volume=90, unit='unit'),
            ],
            adjustments=[
                dict(amount=-100, reason='A Lannister always pays his debts!'),
                dict(amount=20, reason='you owe me'),
            ],
        )

        self.assertEqual(invoice.guid, 'MOCK_INVOICE_GUID')
        post_method.assert_called_once_with(
            'http://localhost/v1/invoices', 
            data=dict(
                customer_guid='MOCK_CUSTOMER_GUID',
                funding_instrument_uri='MOCK_INSTRUMENT_URI',
                title='I want you bankrupt invoice',
                appears_on_statement_as='hi there',
                amount='5566',
                # item1
                item_name0='foo',
                item_amount0='1234',
                # item2
                item_type1='debit',
                item_name1='bar',
                item_amount1='56',
                item_quantity1='78',
                item_volume1='90',
                item_unit1='unit',
                # adjustment1
                adjustment_amount0='-100',
                adjustment_reason0='A Lannister always pays his debts!',
                # adjustment2
                adjustment_amount1='20',
                adjustment_reason1='you owe me',
            ),
            auth=('MOCK_API_KEY', ''),
        )
Ejemplo n.º 2
0
    def test_invoice_with_duplicate_external_id(self, post_method):
        api = self.make_one('MOCK_API_KEY', endpoint='http://localhost')
        customer = Customer(api, dict(guid='MOCK_CUSTOMER_GUID'))
        mock_invoice_data = dict(
            guid='MOCK_INVOICE_GUID',
        )
        mock_response = mock.Mock(
            json=lambda: mock_invoice_data,
            status_code=409,
            content='Duplicate',
        )
        post_method.return_value = mock_response

        with self.assertRaises(DuplicateExternalIDError):
            customer.invoice(
                amount='5566',
                funding_instrument_uri='MOCK_URI',
                external_id='duplaite one',
            )