当前位置: 首页>>代码示例>>Python>>正文


Python Account.delete方法代码示例

本文整理汇总了Python中recurly.Account.delete方法的典型用法代码示例。如果您正苦于以下问题:Python Account.delete方法的具体用法?Python Account.delete怎么用?Python Account.delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在recurly.Account的用法示例。


在下文中一共展示了Account.delete方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_invoice

# 需要导入模块: from recurly import Account [as 别名]
# 或者: from recurly.Account import delete [as 别名]
    def test_invoice(self):
        account = Account(account_code='invoice%s' % self.test_id)
        with self.mock_request('invoice/account-created.xml'):
            account.save()

        try:
            with self.mock_request('invoice/account-has-no-invoices.xml'):
                invoices = account.invoices()
            self.assertEqual(invoices, [])

            with self.mock_request('invoice/error-no-charges.xml'):
                try:
                    account.invoice()
                except ValidationError as exc:
                    error = exc
                else:
                    self.fail("Invoicing an account with no charges did not raise a ValidationError")
            self.assertEqual(error.symbol, 'will_not_invoice')

            charge = Adjustment(unit_amount_in_cents=1000, currency='USD', description='test charge', type='charge')
            with self.mock_request('invoice/charged.xml'):
                account.charge(charge)

            with self.mock_request('invoice/invoiced.xml'):
                account.invoice()

            with self.mock_request('invoice/account-has-invoices.xml'):
                invoices = account.invoices()
            self.assertEqual(len(invoices), 1)
        finally:
            with self.mock_request('invoice/account-deleted.xml'):
                account.delete()
开发者ID:Captricity,项目名称:recurly-client-python,代码行数:34,代码来源:test_resources.py

示例2: test_account_notes

# 需要导入模块: from recurly import Account [as 别名]
# 或者: from recurly.Account import delete [as 别名]
    def test_account_notes(self):
        account1 = Account(account_code='note%s' % self.test_id)
        account2 = Account(account_code='note%s' % self.test_id)

        with self.mock_request('account-notes/account1-created.xml'):
            account1.save()
        with self.mock_request('account-notes/account2-created.xml'):
            account2.save()
        try:
            with self.mock_request('account-notes/account1-note-list.xml'):
                notes1 = account1.notes()
            with self.mock_request('account-notes/account2-note-list.xml'):
                notes2 = account2.notes()

            # assert accounts don't share notes
            self.assertNotEqual(notes1, notes2)

            # assert contains the proper notes
            self.assertEqual(notes1[0].message, "Python Madness")
            self.assertEqual(notes1[1].message, "Some message")
            self.assertEqual(notes2[0].message, "Foo Bar")
            self.assertEqual(notes2[1].message, "Baz Boo Bop")

        finally:
            with self.mock_request('account-notes/account1-deleted.xml'):
                account1.delete()
            with self.mock_request('account-notes/account2-deleted.xml'):
                account2.delete()
开发者ID:issuu,项目名称:recurly-client-python,代码行数:30,代码来源:test_resources.py

示例3: test_charge

# 需要导入模块: from recurly import Account [as 别名]
# 或者: from recurly.Account import delete [as 别名]
    def test_charge(self):
        account = Account(account_code='charge%s' % self.test_id)
        with self.mock_request('adjustment/account-created.xml'):
            account.save()

        try:
            with self.mock_request('adjustment/account-has-no-charges.xml'):
                charges = account.adjustments()
            self.assertEqual(charges, [])

            charge = Adjustment(unit_amount_in_cents=1000, currency='USD', description='test charge', type='charge')
            with self.mock_request('adjustment/charged.xml'):
                account.charge(charge)

            with self.mock_request('adjustment/account-has-adjustments.xml'):
                charges = account.adjustments()
            self.assertEqual(len(charges), 1)
            same_charge = charges[0]
            self.assertEqual(same_charge.unit_amount_in_cents, 1000)
            self.assertEqual(same_charge.currency, 'USD')
            self.assertEqual(same_charge.description, 'test charge')
            self.assertEqual(same_charge.type, 'charge')

            with self.mock_request('adjustment/account-has-charges.xml'):
                charges = account.adjustments(type='charge')
            self.assertEqual(len(charges), 1)

            with self.mock_request('adjustment/account-has-no-credits.xml'):
                credits = account.adjustments(type='credit')
            self.assertEqual(len(credits), 0)

        finally:
            with self.mock_request('adjustment/account-deleted.xml'):
                account.delete()
开发者ID:mbeale,项目名称:recurly-client-python,代码行数:36,代码来源:test_resources.py

示例4: test_charge

# 需要导入模块: from recurly import Account [as 别名]
# 或者: from recurly.Account import delete [as 别名]
    def test_charge(self):
        account = Account(account_code='charge%s' % self.test_id)
        with self.mock_request('adjustment/account-created.xml'):
            account.save()

        try:
            with self.mock_request('adjustment/account-has-no-charges.xml'):
                charges = account.adjustments()
            self.assertEqual(charges, [])

            charge = Adjustment(unit_amount_in_cents=1000, currency='USD', description='test charge', type='charge')
            with self.mock_request('adjustment/charged.xml'):
                account.charge(charge)

            with self.mock_request('adjustment/account-has-adjustments.xml'):
                charges = account.adjustments()
            self.assertEqual(len(charges), 1)
            same_charge = charges[0]
            self.assertEqual(same_charge.unit_amount_in_cents, 1000)
            self.assertEqual(same_charge.tax_in_cents, 5000)
            self.assertEqual(same_charge.currency, 'USD')
            self.assertEqual(same_charge.description, 'test charge')
            self.assertEqual(same_charge.type, 'charge')

            tax_details = same_charge.tax_details
            state, county = tax_details

            self.assertEqual(len(tax_details), 2)
            self.assertEqual(state.name, 'california')
            self.assertEqual(state.type, 'state')
            self.assertEqual(state.tax_rate, 0.065)
            self.assertEqual(state.tax_in_cents, 3000)

            self.assertEqual(county.name, 'san francisco')
            self.assertEqual(county.type, 'county')
            self.assertEqual(county.tax_rate, 0.02)
            self.assertEqual(county.tax_in_cents, 2000)

            with self.mock_request('adjustment/account-has-charges.xml'):
                charges = account.adjustments(type='charge')
            self.assertEqual(len(charges), 1)

            with self.mock_request('adjustment/account-has-no-credits.xml'):
                credits = account.adjustments(type='credit')
            self.assertEqual(len(credits), 0)

        finally:
            with self.mock_request('adjustment/account-deleted.xml'):
                account.delete()

        """Test taxed adjustments"""
        with self.mock_request('adjustment/show-taxed.xml'):
            charge = account.adjustments()[0]
            self.assertFalse(charge.tax_exempt)
开发者ID:issuu,项目名称:recurly-client-python,代码行数:56,代码来源:test_resources.py

示例5: test_pages

# 需要导入模块: from recurly import Account [as 别名]
# 或者: from recurly.Account import delete [as 别名]
    def test_pages(self):
        account_code = 'pages-%s-%%d' % self.test_id
        all_test_accounts = list()

        try:
            for i in range(1, 8):
                account = Account(account_code=account_code % i)
                all_test_accounts.append(account)
                with self.mock_request('pages/account-%d-created.xml' % i):
                    account.save()
                    self.mock_sleep(1)

            with self.mock_request('pages/list.xml'):
                accounts = Account.all(per_page=4)
            self.assertEqual(len(accounts), 4)
            self.assertTrue(isinstance(accounts[0], Account))
            self.assertRaises(IndexError, lambda: accounts[4])
            self.assertEqual(accounts[0].account_code, account_code % 7)
            self.assertEqual(accounts[3].account_code, account_code % 4)

            # Test errors, since the first page has no first page.
            self.assertRaises(PageError, lambda: accounts.first_page())
            # Make sure PageError is a ValueError.
            self.assertRaises(ValueError, lambda: accounts.first_page())

            with self.mock_request('pages/next-list.xml'):
                next_accounts = accounts.next_page()
            # We asked for all the accounts, which may include closed accounts
            # from previous tests or data, not just the three we created.
            self.assertTrue(3 <= len(next_accounts))
            self.assertTrue(len(next_accounts) <= 4)
            self.assertTrue(isinstance(next_accounts[0], Account))
            self.assertRaises(IndexError, lambda: next_accounts[4])
            self.assertEqual(next_accounts[0].account_code, account_code % 3)
            self.assertEqual(next_accounts[2].account_code, account_code % 1)

            with self.mock_request('pages/list.xml'):  # should be just like the first
                first_accounts = next_accounts.first_page()
            self.assertEqual(len(first_accounts), 4)
            self.assertTrue(isinstance(first_accounts[0], Account))
            self.assertEqual(first_accounts[0].account_code, account_code % 7)
            self.assertEqual(first_accounts[3].account_code, account_code % 4)

        finally:
            for i, account in enumerate(all_test_accounts, 1):
                with self.mock_request('pages/account-%d-deleted.xml' % i):
                    account.delete()
开发者ID:EnHatch,项目名称:recurly-client-python,代码行数:49,代码来源:test_resources.py

示例6: test_invoice

# 需要导入模块: from recurly import Account [as 别名]
# 或者: from recurly.Account import delete [as 别名]
    def test_invoice(self):
        account = Account(account_code="invoice%s" % self.test_id)
        with self.mock_request("invoice/account-created.xml"):
            account.save()

        try:
            with self.mock_request("invoice/account-has-no-invoices.xml"):
                invoices = account.invoices()
            self.assertEqual(invoices, [])

            with self.mock_request("invoice/error-no-charges.xml"):
                try:
                    account.invoice()
                except ValidationError as exc:
                    error = exc
                else:
                    self.fail("Invoicing an account with no charges did not raise a ValidationError")
            self.assertEqual(error.symbol, "will_not_invoice")

            charge = Adjustment(unit_amount_in_cents=1000, currency="USD", description="test charge", type="charge")
            with self.mock_request("invoice/charged.xml"):
                account.charge(charge)

            with self.mock_request("invoice/invoiced.xml"):
                account.invoice()

            with self.mock_request("invoice/account-has-invoices.xml"):
                invoices = account.invoices()
            self.assertEqual(len(invoices), 1)
        finally:
            with self.mock_request("invoice/account-deleted.xml"):
                account.delete()

        """Test taxed invoice"""
        with self.mock_request("invoice/show-taxed.xml"):
            invoice = account.invoices()[0]
            self.assertEqual(invoice.tax_type, "usst")

        """Test invoice with prefix"""
        with self.mock_request("invoice/show-with-prefix.xml"):
            invoice = account.invoices()[0]
            self.assertEqual(invoice.invoice_number, 1001)
            self.assertEqual(invoice.invoice_number_prefix, "GB")
            self.assertEqual(invoice.invoice_number_with_prefix(), "GB1001")
开发者ID:tbartelmess,项目名称:recurly-client-python,代码行数:46,代码来源:test_resources.py

示例7: test_build_invoice

# 需要导入模块: from recurly import Account [as 别名]
# 或者: from recurly.Account import delete [as 别名]
    def test_build_invoice(self):
        account = Account(account_code="invoice%s" % self.test_id)
        with self.mock_request("invoice/account-created.xml"):
            account.save()

        try:
            with self.mock_request("invoice/preview-error-no-charges.xml"):
                try:
                    account.build_invoice()
                except ValidationError as exc:
                    error = exc
                else:
                    self.fail("Invoicing an account with no charges did not raise a ValidationError")
            self.assertEqual(error.symbol, "will_not_invoice")

            charge = Adjustment(unit_amount_in_cents=1000, currency="USD", description="test charge", type="charge")
            with self.mock_request("invoice/charged.xml"):
                account.charge(charge)

            with self.mock_request("invoice/preview-invoice.xml"):
                account.build_invoice()
        finally:
            with self.mock_request("invoice/account-deleted.xml"):
                account.delete()
开发者ID:tbartelmess,项目名称:recurly-client-python,代码行数:26,代码来源:test_resources.py

示例8: test_billing_info

# 需要导入模块: from recurly import Account [as 别名]
# 或者: from recurly.Account import delete [as 别名]
    def test_billing_info(self):
        logging.basicConfig(level=logging.DEBUG)  # make sure it's init'ed
        logger = logging.getLogger('recurly.http.request')
        logger.setLevel(logging.DEBUG)

        log_content = StringIO()
        log_handler = logging.StreamHandler(log_content)
        logger.addHandler(log_handler)

        account = Account(account_code='binfo%s' % self.test_id)
        with self.mock_request('billing-info/account-created.xml'):
            account.save()

        logger.removeHandler(log_handler)
        self.assertTrue('<account' in log_content.getvalue())

        try:

            # Billing info link won't be present at all yet.
            self.assertRaises(AttributeError, getattr, account, 'billing_info')

            log_content = StringIO()
            log_handler = logging.StreamHandler(log_content)
            logger.addHandler(log_handler)

            binfo = BillingInfo(
                first_name='Verena',
                last_name='Example',
                address1='123 Main St',
                city=u'San Jos\xe9',
                state='CA',
                zip='94105',
                country='US',
                type='credit_card',
                number='4111 1111 1111 1111',
                verification_value='7777',
                year='2015',
                month='12',
            )
            with self.mock_request('billing-info/created.xml'):
                account.update_billing_info(binfo)

            logger.removeHandler(log_handler)
            log_content = log_content.getvalue()
            self.assertTrue('<billing_info' in log_content)
            # See if we redacted our sensitive fields properly.
            self.assertTrue('4111' not in log_content)
            self.assertTrue('7777' not in log_content)

            with self.mock_request('billing-info/account-exists.xml'):
                same_account = Account.get('binfo%s' % self.test_id)
            with self.mock_request('billing-info/exists.xml'):
                same_binfo = same_account.billing_info
            self.assertEqual(same_binfo.first_name, 'Verena')
            self.assertEqual(same_binfo.city, u'San Jos\xe9')

            with self.mock_request('billing-info/deleted.xml'):
                binfo.delete()
        finally:
            with self.mock_request('billing-info/account-deleted.xml'):
                account.delete()

        log_content = StringIO()
        log_handler = logging.StreamHandler(log_content)
        logger.addHandler(log_handler)

        account = Account(account_code='binfo-%s-2' % self.test_id)
        account.billing_info = BillingInfo(
            first_name='Verena',
            last_name='Example',
            address1='123 Main St',
            city=u'San Jos\xe9',
            state='CA',
            zip='94105',
            country='US',
            type='credit_card',
            number='4111 1111 1111 1111',
            verification_value='7777',
            year='2015',
            month='12',
        )
        with self.mock_request('billing-info/account-embed-created.xml'):
            account.save()

        try:
            logger.removeHandler(log_handler)
            log_content = log_content.getvalue()
            self.assertTrue('<account' in log_content)
            self.assertTrue('<billing_info' in log_content)
            self.assertTrue('4111' not in log_content)
            self.assertTrue('7777' not in log_content)

            with self.mock_request('billing-info/account-embed-exists.xml'):
                same_account = Account.get('binfo-%s-2' % self.test_id)
            with self.mock_request('billing-info/embedded-exists.xml'):
                binfo = same_account.billing_info
            self.assertEqual(binfo.first_name, 'Verena')
        finally:
            with self.mock_request('billing-info/account-embed-deleted.xml'):
                account.delete()
开发者ID:mbeale,项目名称:recurly-client-python,代码行数:102,代码来源:test_resources.py

示例9: int

# 需要导入模块: from recurly import Account [as 别名]
# 或者: from recurly.Account import delete [as 别名]
                account.delete()

        # Make sure numeric account codes work.
        if self.test_id == 'mock':
            numeric_test_id = 58
        else:
            numeric_test_id = int(self.test_id)

        account = Account(account_code=numeric_test_id)
        with self.mock_request('account/numeric-created.xml'):
            account.save()
        try:
            self.assertEqual(account._url, urljoin(recurly.BASE_URI, 'accounts/%d' % numeric_test_id))
        finally:
            with self.mock_request('account/numeric-deleted.xml'):
                account.delete()

    def test_add_on(self):
        plan_code = 'plan%s' % self.test_id
        add_on_code = 'addon%s' % self.test_id

        plan = Plan(
            plan_code=plan_code,
            name='Mock Plan',
            setup_fee_in_cents=Money(0),
            unit_amount_in_cents=Money(1000),
        )
        with self.mock_request('add-on/plan-created.xml'):
            plan.save()

        try:
开发者ID:mbeale,项目名称:recurly-client-python,代码行数:33,代码来源:test_resources.py

示例10: test_subscribe

# 需要导入模块: from recurly import Account [as 别名]
# 或者: from recurly.Account import delete [as 别名]

#.........这里部分代码省略.........
                self.assertEqual(subs[0].uuid, sub.uuid)

                with self.mock_request('subscription/cancelled.xml'):
                    sub.cancel()
                with self.mock_request('subscription/reactivated.xml'):
                    sub.reactivate()

                # Try modifying the subscription.
                sub.timeframe = 'renewal'
                sub.unit_amount_in_cents = 800
                with self.mock_request('subscription/updated-at-renewal.xml'):
                    sub.save()
                pending_sub = sub.pending_subscription
                self.assertTrue(isinstance(pending_sub, Subscription))
                self.assertEqual(pending_sub.unit_amount_in_cents, 800)
                self.assertEqual(sub.unit_amount_in_cents, 1000)

                with self.mock_request('subscription/terminated.xml'):
                    sub.terminate(refund='none')

                log_content = StringIO()
                log_handler = logging.StreamHandler(log_content)
                logger.addHandler(log_handler)

                sub = Subscription(
                    plan_code='basicplan',
                    currency='USD',
                    account=Account(
                        account_code='subscribe%s' % self.test_id,
                        billing_info=BillingInfo(
                            first_name='Verena',
                            last_name='Example',
                            address1='123 Main St',
                            city=six.u('San Jos\xe9'),
                            state='CA',
                            zip='94105',
                            country='US',
                            type='credit_card',
                            number='4111 1111 1111 1111',
                            verification_value='7777',
                            year='2015',
                            month='12',
                        ),
                    ),
                )
                with self.mock_request('subscription/subscribed-billing-info.xml'):
                    account.subscribe(sub)

                logger.removeHandler(log_handler)
                log_content = log_content.getvalue()
                self.assertTrue('<subscription' in log_content)
                self.assertTrue('<billing_info' in log_content)
                # See if we redacted our sensitive fields properly.
                self.assertTrue('4111' not in log_content)
                self.assertTrue('7777' not in log_content)

            finally:
                with self.mock_request('subscription/account-deleted.xml'):
                    account.delete()

            account_code_2 = 'subscribe-%s-2' % self.test_id
            sub = Subscription(
                plan_code='basicplan',
                currency='USD',
                account=Account(
                    account_code=account_code_2,
                    billing_info=BillingInfo(
                        first_name='Verena',
                        last_name='Example',
                        address1='123 Main St',
                        city=six.u('San Jos\xe9'),
                        state='CA',
                        zip='94105',
                        country='US',
                        type='credit_card',
                        number='4111 1111 1111 1111',
                        verification_value='7777',
                        year='2015',
                        month='12',
                    ),
                ),
            )
            with self.mock_request('subscription/subscribe-embedded-account.xml'):
                sub.save()

            with self.mock_request('subscription/embedded-account-exists.xml'):
                acc = Account.get(account_code_2)
            self.assertEqual(acc.account_code, account_code_2)

            with self.mock_request('subscription/embedded-account-deleted.xml'):
                acc.delete()

        finally:
            with self.mock_request('subscription/plan-deleted.xml'):
                plan.delete()

        with self.mock_request('subscription/show.xml'):
            sub = Subscription.get('123456789012345678901234567890ab')
            self.assertEqual(sub.tax_in_cents, 0)
            self.assertEqual(sub.tax_type, 'usst')
开发者ID:issuu,项目名称:recurly-client-python,代码行数:104,代码来源:test_resources.py

示例11: test_account

# 需要导入模块: from recurly import Account [as 别名]
# 或者: from recurly.Account import delete [as 别名]
    def test_account(self):
        account_code = 'test%s' % self.test_id
        with self.mock_request('account/does-not-exist.xml'):
            self.assertRaises(NotFoundError, Account.get, account_code)

        account = Account(account_code=account_code)
        account.vat_number = '444444-UK'
        with self.mock_request('account/created.xml'):
            account.save()
        self.assertEqual(account._url, urljoin(recurly.base_uri(), 'accounts/%s' % account_code))
        self.assertEqual(account.vat_number, '444444-UK')

        with self.mock_request('account/list-active.xml'):
            active = Account.all_active()
        self.assertTrue(len(active) >= 1)
        self.assertEqual(active[0].account_code, account_code)

        with self.mock_request('account/exists.xml'):
            same_account = Account.get(account_code)
        self.assertTrue(isinstance(same_account, Account))
        self.assertTrue(same_account is not account)
        self.assertEqual(same_account.account_code, account_code)
        self.assertTrue(same_account.first_name is None)
        self.assertTrue(same_account.entity_use_code == 'I')
        self.assertEqual(same_account._url, urljoin(recurly.base_uri(), 'accounts/%s' % account_code))

        account.username = 'shmohawk58'
        account.email = 'larry.david'
        account.first_name = six.u('L\xe4rry')
        account.last_name = 'David'
        account.company_name = 'Home Box Office'
        account.accept_language = 'en-US'
        with self.mock_request('account/update-bad-email.xml'):
            try:
                account.save()
            except ValidationError as exc:
                self.assertTrue(isinstance(exc.errors, collections.Mapping))
                self.assertTrue('account.email' in exc.errors)
                suberror = exc.errors['account.email']
                self.assertEqual(suberror.symbol, 'invalid_email')
                self.assertTrue(suberror.message)
                self.assertEqual(suberror.message, suberror.message)
            else:
                self.fail("Updating account with invalid email address did not raise a ValidationError")

        account.email = '[email protected]'
        with self.mock_request('account/updated.xml'):
            account.save()

        with self.mock_request('account/deleted.xml'):
            account.delete()

        with self.mock_request('account/list-closed.xml'):
            closed = Account.all_closed()
        self.assertTrue(len(closed) >= 1)
        self.assertEqual(closed[0].account_code, account_code)

        with self.mock_request('account/list-active-when-closed.xml'):
            active = Account.all_active()
        self.assertTrue(len(active) < 1 or active[0].account_code != account_code)

        # Make sure we can reopen a closed account.
        with self.mock_request('account/reopened.xml'):
            account.reopen()
        try:
            with self.mock_request('account/list-active.xml'):
                active = Account.all_active()
            self.assertTrue(len(active) >= 1)
            self.assertEqual(active[0].account_code, account_code)
        finally:
            with self.mock_request('account/deleted.xml'):
                account.delete()

        # Make sure numeric account codes work.
        if self.test_id == 'mock':
            numeric_test_id = 58
        else:
            numeric_test_id = int(self.test_id)

        account = Account(account_code=numeric_test_id)
        with self.mock_request('account/numeric-created.xml'):
            account.save()
        try:
            self.assertEqual(account._url, urljoin(recurly.base_uri(), 'accounts/%d' % numeric_test_id))
        finally:
            with self.mock_request('account/numeric-deleted.xml'):
                account.delete()

        """Create an account with an account level address"""
        account = Account(account_code=account_code)
        account.address.address1 = '123 Main St'
        account.address.city = 'San Francisco'
        account.address.zip = '94105'
        account.address.state = 'CA'
        account.address.country = 'US'
        account.address.phone = '8015559876'
        with self.mock_request('account/created-with-address.xml'):
            account.save()
        self.assertEqual(account.address.address1, '123 Main St')
        self.assertEqual(account.address.city, 'San Francisco')
#.........这里部分代码省略.........
开发者ID:issuu,项目名称:recurly-client-python,代码行数:103,代码来源:test_resources.py

示例12: test_charge

# 需要导入模块: from recurly import Account [as 别名]
# 或者: from recurly.Account import delete [as 别名]
    def test_charge(self):
        account = Account(account_code="charge%s" % self.test_id)
        with self.mock_request("adjustment/account-created.xml"):
            account.save()

        try:
            with self.mock_request("adjustment/account-has-no-charges.xml"):
                charges = account.adjustments()
            self.assertEqual(charges, [])

            charge = Adjustment(unit_amount_in_cents=1000, currency="USD", description="test charge", type="charge")
            with self.mock_request("adjustment/charged.xml"):
                account.charge(charge)

            with self.mock_request("adjustment/account-has-adjustments.xml"):
                charges = account.adjustments()
            self.assertEqual(len(charges), 1)
            same_charge = charges[0]
            self.assertEqual(same_charge.unit_amount_in_cents, 1000)
            self.assertEqual(same_charge.tax_in_cents, 5000)
            self.assertEqual(same_charge.tax_type, "usst")
            self.assertEqual(same_charge.tax_rate, 0.0875)
            self.assertEqual(same_charge.tax_region, "CA")
            self.assertEqual(same_charge.currency, "USD")
            self.assertEqual(same_charge.description, "test charge")
            self.assertEqual(same_charge.type, "charge")

            tax_details = same_charge.tax_details
            state, county = tax_details

            self.assertEqual(len(tax_details), 2)
            self.assertEqual(state.name, "california")
            self.assertEqual(state.type, "state")
            self.assertEqual(state.tax_rate, 0.065)
            self.assertEqual(state.tax_in_cents, 3000)

            self.assertEqual(county.name, "san francisco")
            self.assertEqual(county.type, "county")
            self.assertEqual(county.tax_rate, 0.02)
            self.assertEqual(county.tax_in_cents, 2000)

            with self.mock_request("adjustment/account-has-charges.xml"):
                charges = account.adjustments(type="charge")
            self.assertEqual(len(charges), 1)

            with self.mock_request("adjustment/account-has-no-credits.xml"):
                credits = account.adjustments(type="credit")
            self.assertEqual(len(credits), 0)

        finally:
            with self.mock_request("adjustment/account-deleted.xml"):
                account.delete()

        """Test taxed adjustments"""
        with self.mock_request("adjustment/show-taxed.xml"):
            charge = account.adjustments()[0]
            self.assertFalse(charge.tax_exempt)

        """Test original adjustment"""
        with self.mock_request("adjustment/original-adjustment.xml"):
            charge = Adjustment.get("2c06b94abe047189b225d94dd0adb71f")

            with self.mock_request("adjustment/original-adjustment-lookup.xml"):
                original_charge = charge.original_adjustment()

            self.assertEqual(original_charge.total_in_cents, -charge.total_in_cents)

        """Test original adjustment lookup by UUID"""
        with self.mock_request("adjustment/original-adjustment-uuid.xml"):
            charge = Adjustment.get("2c06b94abe047189b225d94dd0adb71f")

            with self.mock_request("adjustment/original-adjustment-lookup.xml"):
                original_charge = charge.original_adjustment()

            self.assertEqual(original_charge.total_in_cents, -charge.total_in_cents)
开发者ID:tbartelmess,项目名称:recurly-client-python,代码行数:77,代码来源:test_resources.py

示例13: test_transaction_with_balance

# 需要导入模块: from recurly import Account [as 别名]
# 或者: from recurly.Account import delete [as 别名]
    def test_transaction_with_balance(self):
        transaction = Transaction(
            amount_in_cents=1000,
            currency='USD',
            account=Account(),
        )
        error = None
        with self.mock_request('transaction-balance/transaction-no-account.xml'):
            try:
                transaction.save()
            except ValidationError as _error:
                error = _error
            else:
                self.fail("Posting a transaction without an account code did not raise a ValidationError")
        # Make sure there really were errors.
        self.assertTrue(len(error.errors) > 0)

        account_code = 'transbalance%s' % self.test_id
        account = Account(account_code=account_code)
        with self.mock_request('transaction-balance/account-created.xml'):
            account.save()

        try:
            # Try to charge without billing info, should break.
            transaction = Transaction(
                amount_in_cents=1000,
                currency='USD',
                account=account,
            )
            error = None
            with self.mock_request('transaction-balance/transaction-no-billing-fails.xml'):
                try:
                    transaction.save()
                except ValidationError as _error:
                    error = _error
                else:
                    self.fail("Posting a transaction without billing info did not raise a ValidationError")
            # Make sure there really were errors.
            self.assertTrue(len(error.errors) > 0)

            binfo = BillingInfo(
                first_name='Verena',
                last_name='Example',
                address1='123 Main St',
                city=six.u('San Jos\xe9'),
                state='CA',
                zip='94105',
                country='US',
                type='credit_card',
                number='4111 1111 1111 1111',
                verification_value='7777',
                year='2015',
                month='12',
            )
            with self.mock_request('transaction-balance/set-billing-info.xml'):
                account.update_billing_info(binfo)

            # Try to charge now, should be okay.
            transaction = Transaction(
                amount_in_cents=1000,
                currency='USD',
                account=account,
            )
            with self.mock_request('transaction-balance/transacted.xml'):
                transaction.save()

            # Give the account a credit.
            credit = Adjustment(unit_amount_in_cents=-2000, currency='USD', description='transaction test credit')
            with self.mock_request('transaction-balance/credited.xml'):
                # TODO: maybe this should be adjust()?
                account.charge(credit)

            # Try to charge less than the account balance, which should fail (not a CC transaction).
            transaction = Transaction(
                amount_in_cents=500,
                currency='USD',
                account=account,
            )
            with self.mock_request('transaction-balance/transacted-2.xml'):
                transaction.save()
            # The transaction doesn't actually save.
            self.assertTrue(transaction._url is None)

            # Try to charge more than the account balance, which should work.
            transaction = Transaction(
                amount_in_cents=3000,
                currency='USD',
                account=account,
            )
            with self.mock_request('transaction-balance/transacted-3.xml'):
                transaction.save()
            # This transaction should be recorded.
            self.assertTrue(transaction._url is not None)

        finally:
            with self.mock_request('transaction-balance/account-deleted.xml'):
                account.delete()
开发者ID:issuu,项目名称:recurly-client-python,代码行数:99,代码来源:test_resources.py

示例14: test_subscribe

# 需要导入模块: from recurly import Account [as 别名]
# 或者: from recurly.Account import delete [as 别名]

#.........这里部分代码省略.........
                    sub.cancel()
                with self.mock_request("subscription/reactivated.xml"):
                    sub.reactivate()

                # Try modifying the subscription.
                sub.timeframe = "renewal"
                sub.unit_amount_in_cents = 800
                with self.mock_request("subscription/updated-at-renewal.xml"):
                    sub.save()
                pending_sub = sub.pending_subscription
                self.assertTrue(isinstance(pending_sub, Subscription))
                self.assertEqual(pending_sub.unit_amount_in_cents, 800)
                self.assertEqual(sub.unit_amount_in_cents, 1000)

                with self.mock_request("subscription/terminated.xml"):
                    sub.terminate(refund="none")

                log_content = StringIO()
                log_handler = logging.StreamHandler(log_content)
                logger.addHandler(log_handler)

                sub = Subscription(
                    plan_code="basicplan",
                    currency="USD",
                    account=Account(
                        account_code="subscribe%s" % self.test_id,
                        billing_info=BillingInfo(
                            first_name="Verena",
                            last_name="Example",
                            address1="123 Main St",
                            city=six.u("San Jos\xe9"),
                            state="CA",
                            zip="94105",
                            country="US",
                            type="credit_card",
                            number="4111 1111 1111 1111",
                            verification_value="7777",
                            year="2015",
                            month="12",
                        ),
                    ),
                )
                with self.mock_request("subscription/subscribed-billing-info.xml"):
                    account.subscribe(sub)

                logger.removeHandler(log_handler)
                log_content = log_content.getvalue()
                self.assertTrue("<subscription" in log_content)
                self.assertTrue("<billing_info" in log_content)
                # See if we redacted our sensitive fields properly.
                self.assertTrue("4111" not in log_content)
                self.assertTrue("7777" not in log_content)

            finally:
                with self.mock_request("subscription/account-deleted.xml"):
                    account.delete()

            account_code_2 = "subscribe-%s-2" % self.test_id
            sub = Subscription(
                plan_code="basicplan",
                currency="USD",
                account=Account(
                    account_code=account_code_2,
                    billing_info=BillingInfo(
                        first_name="Verena",
                        last_name="Example",
                        address1="123 Main St",
                        city=six.u("San Jos\xe9"),
                        state="CA",
                        zip="94105",
                        country="US",
                        type="credit_card",
                        number="4111 1111 1111 1111",
                        verification_value="7777",
                        year="2015",
                        month="12",
                    ),
                ),
            )
            with self.mock_request("subscription/subscribe-embedded-account.xml"):
                sub.save()

            with self.mock_request("subscription/embedded-account-exists.xml"):
                acc = Account.get(account_code_2)
            self.assertEqual(acc.account_code, account_code_2)

            with self.mock_request("subscription/embedded-account-deleted.xml"):
                acc.delete()

        finally:
            with self.mock_request("subscription/plan-deleted.xml"):
                plan.delete()

        with self.mock_request("subscription/show.xml"):
            sub = Subscription.get("123456789012345678901234567890ab")
            self.assertEqual(sub.tax_in_cents, 0)
            self.assertEqual(sub.tax_type, "usst")

            with self.mock_request("subscription/redemptions.xml"):
                self.assertEqual(type(sub.redemptions()), recurly.resource.Page)
开发者ID:tbartelmess,项目名称:recurly-client-python,代码行数:104,代码来源:test_resources.py

示例15: test_account

# 需要导入模块: from recurly import Account [as 别名]
# 或者: from recurly.Account import delete [as 别名]
    def test_account(self):
        account_code = "test%s" % self.test_id
        with self.mock_request("account/does-not-exist.xml"):
            self.assertRaises(NotFoundError, Account.get, account_code)

        account = Account(account_code=account_code)
        account.vat_number = "444444-UK"
        with self.mock_request("account/created.xml"):
            account.save()
        self.assertEqual(account._url, urljoin(recurly.base_uri(), "accounts/%s" % account_code))
        self.assertEqual(account.vat_number, "444444-UK")
        self.assertEqual(account.vat_location_enabled, True)

        with self.mock_request("account/list-active.xml"):
            active = Account.all_active()
        self.assertTrue(len(active) >= 1)
        self.assertEqual(active[0].account_code, account_code)

        with self.mock_request("account/exists.xml"):
            same_account = Account.get(account_code)
        self.assertTrue(isinstance(same_account, Account))
        self.assertTrue(same_account is not account)
        self.assertEqual(same_account.account_code, account_code)
        self.assertTrue(same_account.first_name is None)
        self.assertTrue(same_account.entity_use_code == "I")
        self.assertEqual(same_account._url, urljoin(recurly.base_uri(), "accounts/%s" % account_code))

        account.username = "shmohawk58"
        account.email = "larry.david"
        account.first_name = six.u("L\xe4rry")
        account.last_name = "David"
        account.company_name = "Home Box Office"
        account.accept_language = "en-US"
        with self.mock_request("account/update-bad-email.xml"):
            try:
                account.save()
            except ValidationError as exc:
                self.assertTrue(isinstance(exc.errors, collections.Mapping))
                self.assertTrue("account.email" in exc.errors)
                suberror = exc.errors["account.email"]
                self.assertEqual(suberror.symbol, "invalid_email")
                self.assertTrue(suberror.message)
                self.assertEqual(suberror.message, suberror.message)
            else:
                self.fail("Updating account with invalid email address did not raise a ValidationError")

        account.email = "[email protected]"
        with self.mock_request("account/updated.xml"):
            account.save()

        with self.mock_request("account/deleted.xml"):
            account.delete()

        with self.mock_request("account/list-closed.xml"):
            closed = Account.all_closed()
        self.assertTrue(len(closed) >= 1)
        self.assertEqual(closed[0].account_code, account_code)

        with self.mock_request("account/list-active-when-closed.xml"):
            active = Account.all_active()
        self.assertTrue(len(active) < 1 or active[0].account_code != account_code)

        # Make sure we can reopen a closed account.
        with self.mock_request("account/reopened.xml"):
            account.reopen()
        try:
            with self.mock_request("account/list-active.xml"):
                active = Account.all_active()
            self.assertTrue(len(active) >= 1)
            self.assertEqual(active[0].account_code, account_code)
        finally:
            with self.mock_request("account/deleted.xml"):
                account.delete()

        # Make sure numeric account codes work.
        if self.test_id == "mock":
            numeric_test_id = 58
        else:
            numeric_test_id = int(self.test_id)

        account = Account(account_code=numeric_test_id)
        with self.mock_request("account/numeric-created.xml"):
            account.save()
        try:
            self.assertEqual(account._url, urljoin(recurly.base_uri(), "accounts/%d" % numeric_test_id))
        finally:
            with self.mock_request("account/numeric-deleted.xml"):
                account.delete()

        """Create an account with an account level address"""
        account = Account(account_code=account_code)
        account.address.address1 = "123 Main St"
        account.address.city = "San Francisco"
        account.address.zip = "94105"
        account.address.state = "CA"
        account.address.country = "US"
        account.address.phone = "8015559876"
        with self.mock_request("account/created-with-address.xml"):
            account.save()
        self.assertEqual(account.address.address1, "123 Main St")
#.........这里部分代码省略.........
开发者ID:tbartelmess,项目名称:recurly-client-python,代码行数:103,代码来源:test_resources.py


注:本文中的recurly.Account.delete方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。