本文整理汇总了Python中recurly.Account.save方法的典型用法代码示例。如果您正苦于以下问题:Python Account.save方法的具体用法?Python Account.save怎么用?Python Account.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类recurly.Account
的用法示例。
在下文中一共展示了Account.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_account_notes
# 需要导入模块: from recurly import Account [as 别名]
# 或者: from recurly.Account import save [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()
示例2: test_invoice
# 需要导入模块: from recurly import Account [as 别名]
# 或者: from recurly.Account import save [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()
示例3: test_charge
# 需要导入模块: from recurly import Account [as 别名]
# 或者: from recurly.Account import save [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()
示例4: test_subscribe
# 需要导入模块: from recurly import Account [as 别名]
# 或者: from recurly.Account import save [as 别名]
def test_subscribe(self):
logging.basicConfig(level=logging.DEBUG) # make sure it's init'ed
logger = logging.getLogger('recurly.http.request')
logger.setLevel(logging.DEBUG)
plan = Plan(
plan_code='basicplan',
name='Basic Plan',
setup_fee_in_cents=Money(0),
unit_amount_in_cents=Money(1000),
)
with self.mock_request('subscription/plan-created.xml'):
plan.save()
try:
account = Account(account_code='subscribe%s' % self.test_id)
with self.mock_request('subscription/account-created.xml'):
account.save()
try:
sub = Subscription(
plan_code='basicplan',
currency='USD',
unit_amount_in_cents=1000,
)
with self.mock_request('subscription/error-no-billing-info.xml'):
try:
account.subscribe(sub)
except BadRequestError, exc:
error = exc
else:
self.fail("Subscribing with no billing info did not raise a BadRequestError")
示例5: test_invoice_refund_amount
# 需要导入模块: from recurly import Account [as 别名]
# 或者: from recurly.Account import save [as 别名]
def test_invoice_refund_amount(self):
account = Account(account_code="invoice%s" % self.test_id)
with self.mock_request("invoice/account-created.xml"):
account.save()
with self.mock_request("invoice/invoiced.xml"):
invoice = account.invoice()
with self.mock_request("invoice/refunded.xml"):
refund_invoice = invoice.refund_amount(1000)
self.assertEqual(refund_invoice.subtotal_in_cents, -1000)
示例6: test_charge
# 需要导入模块: from recurly import Account [as 别名]
# 或者: from recurly.Account import save [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)
示例7: test_invoice_with_optionals
# 需要导入模块: from recurly import Account [as 别名]
# 或者: from recurly.Account import save [as 别名]
def test_invoice_with_optionals(self):
account = Account(account_code='invoice%s' % self.test_id)
with self.mock_request('invoice/account-created.xml'):
account.save()
with self.mock_request('invoice/invoiced-with-optionals.xml'):
invoice = account.invoice(terms_and_conditions='Some Terms and Conditions',
customer_notes='Some Customer Notes')
self.assertEqual(type(invoice), recurly.Invoice)
self.assertEqual(invoice.terms_and_conditions, 'Some Terms and Conditions')
self.assertEqual(invoice.customer_notes, 'Some Customer Notes')
示例8: test_invoice_refund
# 需要导入模块: from recurly import Account [as 别名]
# 或者: from recurly.Account import save [as 别名]
def test_invoice_refund(self):
account = Account(account_code="invoice%s" % self.test_id)
with self.mock_request("invoice/account-created.xml"):
account.save()
with self.mock_request("invoice/invoiced-line-items.xml"):
invoice = account.invoice()
with self.mock_request("invoice/line-item-refunded.xml"):
line_items = [{"adjustment": invoice.line_items[0], "quantity": 1, "prorate": False}]
refund_invoice = invoice.refund(line_items)
self.assertEqual(refund_invoice.subtotal_in_cents, -1000)
示例9: test_invoice_refund
# 需要导入模块: from recurly import Account [as 别名]
# 或者: from recurly.Account import save [as 别名]
def test_invoice_refund(self):
account = Account(account_code='invoice%s' % self.test_id)
with self.mock_request('invoice/account-created.xml'):
account.save()
with self.mock_request('invoice/invoiced-line-items.xml'):
invoice = account.invoice()
with self.mock_request('invoice/line-item-refunded.xml'):
line_items = [{ 'adjustment': invoice.line_items[0], 'quantity': 1,
'prorate': False }]
refund_invoice = invoice.refund(line_items)
self.assertEqual(refund_invoice.subtotal_in_cents, -1000)
示例10: test_invoice
# 需要导入模块: from recurly import Account [as 别名]
# 或者: from recurly.Account import save [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, exc:
error = exc
else:
示例11: test_pages
# 需要导入模块: from recurly import Account [as 别名]
# 或者: from recurly.Account import save [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()
示例12: test_invoice
# 需要导入模块: from recurly import Account [as 别名]
# 或者: from recurly.Account import save [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")
示例13: test_account
# 需要导入模块: from recurly import Account [as 别名]
# 或者: from recurly.Account import save [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)
with self.mock_request('account/created.xml'):
account.save()
self.assertEqual(account._url, urljoin(recurly.BASE_URI, 'accounts/%s' % account_code))
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.assertEqual(same_account._url, urljoin(recurly.BASE_URI, 'accounts/%s' % account_code))
account.username = 'shmohawk58'
account.email = 'larry.david'
account.first_name = 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, 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, str(suberror))
else:
示例14: test_build_invoice
# 需要导入模块: from recurly import Account [as 别名]
# 或者: from recurly.Account import save [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()
示例15: test_coupon
# 需要导入模块: from recurly import Account [as 别名]
# 或者: from recurly.Account import save [as 别名]
def test_coupon(self):
# Check that a coupon may not exist.
coupon_code = 'coupon%s' % self.test_id
with self.mock_request('coupon/does-not-exist.xml'):
self.assertRaises(NotFoundError, Coupon.get, coupon_code)
# Create a coupon?
coupon = Coupon(
coupon_code=coupon_code,
name='Nice Coupon',
discount_in_cents=Money(1000),
)
with self.mock_request('coupon/created.xml'):
coupon.save()
self.assertTrue(coupon._url)
try:
with self.mock_request('coupon/exists.xml'):
same_coupon = Coupon.get(coupon_code)
self.assertEqual(same_coupon.coupon_code, coupon_code)
self.assertEqual(same_coupon.name, 'Nice Coupon')
discount = same_coupon.discount_in_cents
self.assertEqual(discount['USD'], 1000)
self.assertTrue('USD' in discount)
account_code = 'coupon%s' % self.test_id
account = Account(account_code=account_code)
with self.mock_request('coupon/account-created.xml'):
account.save()
try:
redemption = Redemption(
account_code=account_code,
currency='USD',
)
with self.mock_request('coupon/redeemed.xml'):
real_redemption = coupon.redeem(redemption)
self.assertTrue(isinstance(real_redemption, Redemption))
self.assertEqual(real_redemption.currency, 'USD')
with self.mock_request('coupon/account-with-redemption.xml'):
account = Account.get(account_code)
with self.mock_request('coupon/redemption-exists.xml'):
same_redemption = account.redemption()
self.assertEqual(same_redemption._url, real_redemption._url)
with self.mock_request('coupon/unredeemed.xml'):
real_redemption.delete()
finally:
with self.mock_request('coupon/account-deleted.xml'):
account.delete()
plan = Plan(
plan_code='basicplan',
name='Basic Plan',
setup_fee_in_cents=Money(0),
unit_amount_in_cents=Money(1000),
)
with self.mock_request('coupon/plan-created.xml'):
plan.save()
try:
account_code_2 = 'coupon-%s-2' % self.test_id
sub = Subscription(
plan_code='basicplan',
coupon_code='coupon%s' % self.test_id,
currency='USD',
account=Account(
account_code=account_code_2,
billing_info=BillingInfo(
first_name='Verena',
last_name='Example',
number='4111 1111 1111 1111',
address1='123 Main St',
city='San Francisco',
state='CA',
zip='94105',
country='US',
verification_value='7777',
year='2015',
month='12',
),
),
)
with self.mock_request('coupon/subscribed.xml'):
sub.save()
with self.mock_request('coupon/second-account-exists.xml'):
account_2 = Account.get(account_code_2)
try:
with self.mock_request('coupon/second-account-redemption.xml'):
redemption_2 = account_2.redemption()
self.assertTrue(isinstance(redemption_2, Redemption))
self.assertEqual(redemption_2.currency, 'USD')
#.........这里部分代码省略.........