예제 #1
0
파일: test_core.py 프로젝트: 15five/mocurly
    def test_timeout_successful_post(self):
        mocurly_ = mocurly.mocurly()
        mocurly_.start()

        # Only timeout on creating transactions
        def timeout_filter(request):
            return request.path.endswith('transactions')
        mocurly_.start_timeout_successful_post(timeout_filter=timeout_filter)

        self.assertFalse(mocurly.backend.accounts_backend.has_object(self.base_account_data['account_code']))
        new_account = recurly.Account(**self.base_account_data)
        new_account.billing_info = recurly.BillingInfo(**self.base_billing_info_data)
        new_account.save()
        self.assertTrue(mocurly.backend.accounts_backend.has_object(self.base_account_data['account_code']))

        self.assertEqual(len(mocurly.backend.transactions_backend.datastore), 0)
        new_transaction = recurly.Transaction(account=new_account, amount_in_cents=20, currency='USD')
        self.assertRaises(recurly.errors.BadGatewayError, new_transaction.save)
        self.assertEqual(len(mocurly.backend.transactions_backend.datastore), 1)

        mocurly_.stop_timeout_successful_post()

        recurly.Transaction(account=new_account, amount_in_cents=20, currency='USD').save()
        self.assertEqual(len(mocurly.backend.transactions_backend.datastore), 2)

        mocurly_.stop()
예제 #2
0
    def test_simple_transaction_creation(self):
        self.assertEqual(len(mocurly.backend.transactions_backend.datastore),
                         0)
        self.assertEqual(len(mocurly.backend.invoices_backend.datastore), 0)

        self.base_transaction_data['account'] = recurly.Account(
            account_code=self.base_account_data['uuid'])
        new_transaction = recurly.Transaction(**self.base_transaction_data)
        new_transaction.save()

        self.assertEqual(len(mocurly.backend.transactions_backend.datastore),
                         1)
        self.assertEqual(len(mocurly.backend.invoices_backend.datastore), 1)
        new_transaction_backed = mocurly.backend.transactions_backend.get_object(
            new_transaction.uuid)
        for k, v in self.base_transaction_data.items():
            if k == 'account':
                self.assertEqual(new_transaction_backed[k], v.account_code)
            else:
                self.assertEqual(new_transaction_backed[k], str(v))
        self.assertTrue('created_at' in new_transaction_backed)
        self.assertTrue(new_transaction_backed['test'])
        self.assertTrue(new_transaction_backed['voidable'])
        self.assertTrue(new_transaction_backed['refundable'])
        self.assertEqual(new_transaction_backed['tax_in_cents'], 0)
        self.assertEqual(new_transaction_backed['action'], 'purchase')
        self.assertEqual(new_transaction_backed['status'], 'success')

        new_invoice = new_transaction.invoice()
        new_invoice_backed = mocurly.backend.invoices_backend.get_object(
            str(new_invoice.invoice_number))
        self.assertEqual(len(new_invoice_backed['transactions']), 1)
        self.assertEqual(new_invoice_backed['transactions'][0],
                         new_transaction.uuid)
        self.assertEqual(new_invoice_backed['state'], 'collected')
        self.assertEqual(new_invoice_backed['subtotal_in_cents'],
                         self.base_transaction_data['amount_in_cents'])
        self.assertEqual(new_invoice_backed['total_in_cents'],
                         self.base_transaction_data['amount_in_cents'])
        self.assertEqual(new_invoice_backed['currency'],
                         self.base_transaction_data['currency'])
        self.assertEqual(new_invoice_backed['tax_in_cents'], 0)
        self.assertEqual(new_invoice_backed['tax_type'], 'usst')
        self.assertEqual(new_invoice_backed['tax_rate'], 0)
        self.assertEqual(new_invoice_backed['net_terms'], 0)

        line_items = new_invoice.line_items
        self.assertEqual(len(line_items), 1)
        new_line_item_backed = mocurly.backend.adjustments_backend.get_object(
            line_items[0].uuid)
        self.assertEqual(new_line_item_backed['description'],
                         self.base_transaction_data['description'])
        self.assertEqual(new_line_item_backed['unit_amount_in_cents'],
                         self.base_transaction_data['amount_in_cents'])
        self.assertEqual(new_line_item_backed['total_in_cents'],
                         self.base_transaction_data['amount_in_cents'])
        self.assertEqual(new_line_item_backed['currency'],
                         self.base_transaction_data['currency'])
        self.assertEqual(new_line_item_backed['type'], 'charge')
        self.assertEqual(new_line_item_backed['tax_in_cents'], 0)
예제 #3
0
    def test_transaction_failure(self):
        self.assertEqual(len(mocurly.backend.transactions_backend.datastore),
                         0)
        self.assertEqual(len(mocurly.backend.invoices_backend.datastore), 0)

        self.mocurly_.register_transaction_failure(
            self.base_account_data['uuid'],
            mocurly.errors.TRANSACTION_DECLINED)
        self.base_transaction_data['account'] = recurly.Account(
            account_code=self.base_account_data['uuid'])
        new_transaction = recurly.Transaction(**self.base_transaction_data)
        try:
            new_transaction.save()
            self.fail('No exception raised')
        except recurly.ValidationError as exc:
            self.assertEqual(
                exc.error, mocurly.errors.TRANSACTION_ERRORS[
                    mocurly.errors.TRANSACTION_DECLINED]['customer'])

        self.assertEqual(len(mocurly.backend.transactions_backend.datastore),
                         1)
        self.assertEqual(len(mocurly.backend.invoices_backend.datastore), 0)
예제 #4
0
    def create(cls, account, amount, currency, description):
        recurly_account = account.recurly_account
        recurly_transaction = recurly.Transaction(account=recurly_account,
                                                  amount_in_cents=int(amount *
                                                                      100),
                                                  currency=currency,
                                                  description=description)
        recurly_transaction.save()

        try:
            subscription = Subscription.objects.get(
                uuid=recurly_transaction.subscription().uuid)
        except AttributeError:
            subscription = None
        except ObjectDoesNotExist:
            subscription = None

        try:
            invoice = Invoice.objects.get(
                uuid=recurly_transaction.invoice().uuid)
        except AttributeError:
            invoice = None
        except ObjectDoesNotExist:
            invoice = Invoice._create_local(
                account,
                recurly_transaction.invoice().uuid,
                recurly_transaction.invoice().state,
                recurly_transaction.invoice().invoice_number,
                recurly_transaction.invoice().po_number,
                recurly_transaction.invoice().vat_number,
                recurly_transaction.invoice().subtotal_in_cents / 100.0,
                recurly_transaction.invoice().tax_in_cents / 100.0,
                recurly_transaction.invoice().total_in_cents / 100.0,
                recurly_transaction.invoice().currency,
                recurly_transaction.invoice().created_at)

        return cls._create_local(
            account, invoice, subscription, recurly_transaction.uuid,
            recurly_transaction.action, recurly_transaction.amount_in_cents /
            100.0, recurly_transaction.tax_in_cents / 100.0,
            recurly_transaction.currency, recurly_transaction.status,
            recurly_transaction.source, recurly_transaction.reference,
            recurly_transaction.test, recurly_transaction.voidable,
            recurly_transaction.refundable, recurly_transaction.cvv_result,
            recurly_transaction.avs_result,
            recurly_transaction.avs_result_street,
            recurly_transaction.avs_result_postal,
            recurly_transaction.created_at,
            recurly_transaction.account().account_code,
            recurly_transaction.account().first_name,
            recurly_transaction.account().last_name,
            recurly_transaction.account().company_name,
            recurly_transaction.account().billing_info.first_name,
            recurly_transaction.account().billing_info.last_name,
            recurly_transaction.account().billing_info.address1,
            recurly_transaction.account().billing_info.address2,
            recurly_transaction.account().billing_info.city,
            recurly_transaction.account().billing_info.state,
            recurly_transaction.account().billing_info.zip,
            recurly_transaction.account().billing_info.country,
            recurly_transaction.account().billing_info.phone,
            recurly_transaction.account().billing_info.vat_number,
            recurly_transaction.account().billing_info.card_type,
            recurly_transaction.account().billing_info.year,
            recurly_transaction.account().billing_info.month,
            recurly_transaction.account().billing_info.first_six,
            recurly_transaction.account().billing_info.last_four)