本文整理汇总了Python中billy.models.company.CompanyModel.create方法的典型用法代码示例。如果您正苦于以下问题:Python CompanyModel.create方法的具体用法?Python CompanyModel.create怎么用?Python CompanyModel.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类billy.models.company.CompanyModel
的用法示例。
在下文中一共展示了CompanyModel.create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_subscription_of_other_company
# 需要导入模块: from billy.models.company import CompanyModel [as 别名]
# 或者: from billy.models.company.CompanyModel import create [as 别名]
def test_get_subscription_of_other_company(self):
from billy.models.company import CompanyModel
from billy.models.customer import CustomerModel
from billy.models.plan import PlanModel
company_model = CompanyModel(self.testapp.session)
customer_model = CustomerModel(self.testapp.session)
plan_model = PlanModel(self.testapp.session)
with db_transaction.manager:
other_company_guid = company_model.create(processor_key="MOCK_PROCESSOR_KEY")
other_customer_guid = customer_model.create(company_guid=other_company_guid)
other_plan_guid = plan_model.create(
company_guid=other_company_guid,
frequency=plan_model.FREQ_WEEKLY,
plan_type=plan_model.TYPE_CHARGE,
amount=10,
)
other_company = company_model.get(other_company_guid)
other_api_key = str(other_company.api_key)
res = self.testapp.post(
"/v1/subscriptions",
dict(customer_guid=other_customer_guid, plan_guid=other_plan_guid),
extra_environ=dict(REMOTE_USER=other_api_key),
status=200,
)
other_guid = res.json["guid"]
self.testapp.get(
"/v1/subscriptions/{}".format(other_guid), extra_environ=dict(REMOTE_USER=self.api_key), status=403
)
示例2: setUp
# 需要导入模块: from billy.models.company import CompanyModel [as 别名]
# 或者: from billy.models.company.CompanyModel import create [as 别名]
def setUp(self):
from billy.models.company import CompanyModel
from billy.models.customer import CustomerModel
from billy.models.plan import PlanModel
self.settings = {
'billy.processor_factory': DummyProcessor
}
super(TestSubscriptionViews, self).setUp()
company_model = CompanyModel(self.testapp.session)
customer_model = CustomerModel(self.testapp.session)
plan_model = PlanModel(self.testapp.session)
with db_transaction.manager:
self.company_guid = company_model.create(
processor_key='MOCK_PROCESSOR_KEY',
)
self.customer_guid = customer_model.create(
company_guid=self.company_guid
)
self.plan_guid = plan_model.create(
company_guid=self.company_guid,
frequency=plan_model.FREQ_WEEKLY,
plan_type=plan_model.TYPE_CHARGE,
amount=10,
)
company = company_model.get(self.company_guid)
self.api_key = str(company.api_key)
示例3: test_create_subscription_to_other_company_plan
# 需要导入模块: from billy.models.company import CompanyModel [as 别名]
# 或者: from billy.models.company.CompanyModel import create [as 别名]
def test_create_subscription_to_other_company_plan(self):
from billy.models.company import CompanyModel
from billy.models.plan import PlanModel
company_model = CompanyModel(self.testapp.session)
plan_model = PlanModel(self.testapp.session)
with db_transaction.manager:
other_company_guid = company_model.create(
processor_key='MOCK_PROCESSOR_KEY',
)
other_plan_guid = plan_model.create(
company_guid=other_company_guid,
frequency=plan_model.FREQ_WEEKLY,
plan_type=plan_model.TYPE_CHARGE,
amount=10,
)
self.testapp.post(
'/v1/subscriptions',
dict(
customer_guid=self.customer_guid,
plan_guid=other_plan_guid,
),
extra_environ=dict(REMOTE_USER=self.api_key),
status=403,
)
示例4: setUp
# 需要导入模块: from billy.models.company import CompanyModel [as 别名]
# 或者: from billy.models.company.CompanyModel import create [as 别名]
def setUp(self):
from billy.models.company import CompanyModel
super(TestPlanViews, self).setUp()
model = CompanyModel(self.testapp.session)
with db_transaction.manager:
self.company_guid = model.create(processor_key='MOCK_PROCESSOR_KEY')
company = model.get(self.company_guid)
self.api_key = str(company.api_key)
示例5: company_list_post
# 需要导入模块: from billy.models.company import CompanyModel [as 别名]
# 或者: from billy.models.company.CompanyModel import create [as 别名]
def company_list_post(request):
"""Create a new company
"""
form = validate_form(CompanyCreateForm, request)
processor_key = form.data['processor_key']
model = CompanyModel(request.session)
# TODO: do validation here
with db_transaction.manager:
guid = model.create(processor_key=processor_key)
company = model.get(guid)
return company
示例6: test_create_subscription_to_other_company_customer
# 需要导入模块: from billy.models.company import CompanyModel [as 别名]
# 或者: from billy.models.company.CompanyModel import create [as 别名]
def test_create_subscription_to_other_company_customer(self):
from billy.models.company import CompanyModel
from billy.models.customer import CustomerModel
company_model = CompanyModel(self.testapp.session)
customer_model = CustomerModel(self.testapp.session)
with db_transaction.manager:
other_company_guid = company_model.create(processor_key="MOCK_PROCESSOR_KEY")
other_customer_guid = customer_model.create(company_guid=other_company_guid)
self.testapp.post(
"/v1/subscriptions",
dict(customer_guid=other_customer_guid, plan_guid=self.plan_guid),
extra_environ=dict(REMOTE_USER=self.api_key),
status=403,
)
示例7: test_get_customer_of_other_company
# 需要导入模块: from billy.models.company import CompanyModel [as 别名]
# 或者: from billy.models.company.CompanyModel import create [as 别名]
def test_get_customer_of_other_company(self):
from billy.models.company import CompanyModel
model = CompanyModel(self.testapp.session)
with db_transaction.manager:
other_company_guid = model.create(processor_key='MOCK_PROCESSOR_KEY')
other_company = model.get(other_company_guid)
other_api_key = str(other_company.api_key)
res = self.testapp.post(
'/v1/customers',
extra_environ=dict(REMOTE_USER=other_api_key),
status=200,
)
guid = res.json['guid']
res = self.testapp.get(
'/v1/customers/{}'.format(guid),
extra_environ=dict(REMOTE_USER=self.api_key),
status=403,
)
示例8: test_cancel_subscription_to_other_company
# 需要导入模块: from billy.models.company import CompanyModel [as 别名]
# 或者: from billy.models.company.CompanyModel import create [as 别名]
def test_cancel_subscription_to_other_company(self):
from billy.models.subscription import SubscriptionModel
from billy.models.company import CompanyModel
subscription_model = SubscriptionModel(self.testapp.session)
company_model = CompanyModel(self.testapp.session)
with db_transaction.manager:
subscription_guid = subscription_model.create(customer_guid=self.customer_guid, plan_guid=self.plan_guid)
other_company_guid = company_model.create(processor_key="MOCK_PROCESSOR_KEY")
other_company = company_model.get(other_company_guid)
other_api_key = str(other_company.api_key)
self.testapp.post(
"/v1/subscriptions/{}/cancel".format(subscription_guid),
extra_environ=dict(REMOTE_USER=other_api_key),
status=403,
)
示例9: test_server_info_with_transaction
# 需要导入模块: from billy.models.company import CompanyModel [as 别名]
# 或者: from billy.models.company.CompanyModel import create [as 别名]
def test_server_info_with_transaction(self):
from billy.models.company import CompanyModel
from billy.models.customer import CustomerModel
from billy.models.plan import PlanModel
from billy.models.subscription import SubscriptionModel
from billy.models.transaction import TransactionModel
company_model = CompanyModel(self.testapp.session)
customer_model = CustomerModel(self.testapp.session)
plan_model = PlanModel(self.testapp.session)
subscription_model = SubscriptionModel(self.testapp.session)
transaction_model = TransactionModel(self.testapp.session)
with db_transaction.manager:
company_guid = company_model.create(
processor_key='MOCK_PROCESSOR_KEY',
)
customer_guid = customer_model.create(
company_guid=company_guid
)
plan_guid = plan_model.create(
company_guid=company_guid,
frequency=plan_model.FREQ_WEEKLY,
plan_type=plan_model.TYPE_CHARGE,
amount=10,
)
subscription_guid = subscription_model.create(
customer_guid=customer_guid,
plan_guid=plan_guid,
)
transaction_guid = transaction_model.create(
subscription_guid=subscription_guid,
transaction_type=transaction_model.TYPE_CHARGE,
amount=10,
payment_uri='/v1/cards/tester',
scheduled_at=datetime.datetime.utcnow(),
)
transaction = transaction_model.get(transaction_guid)
res = self.testapp.get('/', status=200)
self.assertEqual(res.json['last_transaction_created_at'],
transaction.created_at.isoformat())
示例10: test_get_transaction_of_other_company
# 需要导入模块: from billy.models.company import CompanyModel [as 别名]
# 或者: from billy.models.company.CompanyModel import create [as 别名]
def test_get_transaction_of_other_company(self):
from billy.models.company import CompanyModel
from billy.models.customer import CustomerModel
from billy.models.plan import PlanModel
from billy.models.subscription import SubscriptionModel
from billy.models.transaction import TransactionModel
company_model = CompanyModel(self.testapp.session)
customer_model = CustomerModel(self.testapp.session)
plan_model = PlanModel(self.testapp.session)
subscription_model = SubscriptionModel(self.testapp.session)
transaction_model = TransactionModel(self.testapp.session)
with db_transaction.manager:
other_company_guid = company_model.create(
processor_key='MOCK_PROCESSOR_KEY',
)
other_customer_guid = customer_model.create(
company_guid=other_company_guid
)
other_plan_guid = plan_model.create(
company_guid=other_company_guid,
frequency=plan_model.FREQ_WEEKLY,
plan_type=plan_model.TYPE_CHARGE,
amount=10,
)
other_subscription_guid = subscription_model.create(
customer_guid=other_customer_guid,
plan_guid=other_plan_guid,
)
other_transaction_guid = transaction_model.create(
subscription_guid=other_subscription_guid,
transaction_type=transaction_model.TYPE_CHARGE,
amount=10,
payment_uri='/v1/cards/tester',
scheduled_at=datetime.datetime.utcnow(),
)
self.testapp.get(
'/v1/transactions/{}'.format(other_transaction_guid),
extra_environ=dict(REMOTE_USER=self.api_key),
status=403,
)
示例11: setUp
# 需要导入模块: from billy.models.company import CompanyModel [as 别名]
# 或者: from billy.models.company.CompanyModel import create [as 别名]
def setUp(self):
from pyramid.testing import DummyRequest
from billy.models.company import CompanyModel
from billy.models.customer import CustomerModel
from billy.models.plan import PlanModel
from billy.models.subscription import SubscriptionModel
from billy.models.transaction import TransactionModel
super(TestRenderer, self).setUp()
company_model = CompanyModel(self.testapp.session)
customer_model = CustomerModel(self.testapp.session)
plan_model = PlanModel(self.testapp.session)
subscription_model = SubscriptionModel(self.testapp.session)
transaction_model = TransactionModel(self.testapp.session)
with db_transaction.manager:
self.company_guid = company_model.create(
processor_key='MOCK_PROCESSOR_KEY',
)
self.customer_guid = customer_model.create(
company_guid=self.company_guid
)
self.plan_guid = plan_model.create(
company_guid=self.company_guid,
frequency=plan_model.FREQ_WEEKLY,
plan_type=plan_model.TYPE_CHARGE,
amount=10,
)
self.subscription_guid = subscription_model.create(
customer_guid=self.customer_guid,
plan_guid=self.plan_guid,
)
self.transaction_guid = transaction_model.create(
subscription_guid=self.subscription_guid,
transaction_type=transaction_model.TYPE_CHARGE,
amount=10,
payment_uri='/v1/cards/tester',
scheduled_at=datetime.datetime.utcnow(),
)
self.dummy_request = DummyRequest()
示例12: test_get_plan_of_other_company
# 需要导入模块: from billy.models.company import CompanyModel [as 别名]
# 或者: from billy.models.company.CompanyModel import create [as 别名]
def test_get_plan_of_other_company(self):
from billy.models.company import CompanyModel
model = CompanyModel(self.testapp.session)
with db_transaction.manager:
other_company_guid = model.create(processor_key='MOCK_PROCESSOR_KEY')
other_company = model.get(other_company_guid)
other_api_key = str(other_company.api_key)
res = self.testapp.post(
'/v1/plans',
dict(
plan_type='charge',
amount='55.66',
frequency='weekly',
),
extra_environ=dict(REMOTE_USER=other_api_key),
status=200,
)
guid = res.json['guid']
res = self.testapp.get(
'/v1/plans/{}'.format(guid),
extra_environ=dict(REMOTE_USER=self.api_key),
status=403,
)
示例13: TestBalancedProcessorModel
# 需要导入模块: from billy.models.company import CompanyModel [as 别名]
# 或者: from billy.models.company.CompanyModel import create [as 别名]
class TestBalancedProcessorModel(ModelTestCase):
def setUp(self):
from billy.models.company import CompanyModel
from billy.models.customer import CustomerModel
from billy.models.plan import PlanModel
from billy.models.subscription import SubscriptionModel
from billy.models.transaction import TransactionModel
super(TestBalancedProcessorModel, self).setUp()
# build the basic scenario for transaction model
self.company_model = CompanyModel(self.session)
self.customer_model = CustomerModel(self.session)
self.plan_model = PlanModel(self.session)
self.subscription_model = SubscriptionModel(self.session)
self.transaction_model = TransactionModel(self.session)
with db_transaction.manager:
self.company_guid = self.company_model.create('my_secret_key')
self.plan_guid = self.plan_model.create(
company_guid=self.company_guid,
plan_type=self.plan_model.TYPE_CHARGE,
amount=10,
frequency=self.plan_model.FREQ_MONTHLY,
)
self.customer_guid = self.customer_model.create(
company_guid=self.company_guid,
)
self.subscription_guid = self.subscription_model.create(
customer_guid=self.customer_guid,
plan_guid=self.plan_guid,
payment_uri='/v1/credit_card/tester',
)
def make_one(self, *args, **kwargs):
from billy.models.processors.balanced_payments import BalancedProcessor
return BalancedProcessor(*args, **kwargs)
def test_create_customer(self):
import balanced
customer = self.customer_model.get(self.customer_guid)
# make sure API key is set correctly
(
flexmock(balanced)
.should_receive('configure')
.with_args('my_secret_key')
.once()
)
# mock balanced customer instance
mock_balanced_customer = (
flexmock(uri='MOCK_BALANCED_CUSTOMER_URI')
.should_receive('save')
.replace_with(lambda: mock_balanced_customer)
.once()
.mock()
)
class BalancedCustomer(object):
pass
flexmock(BalancedCustomer).new_instances(mock_balanced_customer)
processor = self.make_one(customer_cls=BalancedCustomer)
customer_id = processor.create_customer(customer)
self.assertEqual(customer_id, 'MOCK_BALANCED_CUSTOMER_URI')
def test_prepare_customer_with_card(self):
import balanced
with db_transaction.manager:
self.customer_model.update(
guid=self.customer_guid,
external_id='MOCK_BALANCED_CUSTOMER_URI',
)
customer = self.customer_model.get(self.customer_guid)
# make sure API key is set correctly
(
flexmock(balanced)
.should_receive('configure')
.with_args('my_secret_key')
.once()
)
# mock balanced.Customer instance
mock_balanced_customer = (
flexmock()
.should_receive('add_card')
.with_args('/v1/cards/my_card')
.once()
.mock()
)
# mock balanced.Customer class
class BalancedCustomer(object):
def find(self, uri):
pass
(
flexmock(BalancedCustomer)
.should_receive('find')
#.........这里部分代码省略.........
示例14: TestPlanModel
# 需要导入模块: from billy.models.company import CompanyModel [as 别名]
# 或者: from billy.models.company.CompanyModel import create [as 别名]
class TestPlanModel(ModelTestCase):
def setUp(self):
from billy.models.company import CompanyModel
super(TestPlanModel, self).setUp()
# build the basic scenario for plan model
self.company_model = CompanyModel(self.session)
with transaction.manager:
self.company_guid = self.company_model.create('my_secret_key')
def make_one(self, *args, **kwargs):
from billy.models.plan import PlanModel
return PlanModel(*args, **kwargs)
def test_get_plan(self):
model = self.make_one(self.session)
plan = model.get('PL_NON_EXIST')
self.assertEqual(plan, None)
with self.assertRaises(KeyError):
model.get('PL_NON_EXIST', raise_error=True)
with transaction.manager:
guid = model.create(
company_guid=self.company_guid,
plan_type=model.TYPE_CHARGE,
name='name',
amount=99.99,
frequency=model.FREQ_WEEKLY,
)
plan = model.get(guid)
self.assertEqual(plan.guid, guid)
def test_create(self):
model = self.make_one(self.session)
name = 'monthly billing to user John'
amount = decimal.Decimal('5566.77')
frequency = model.FREQ_MONTHLY
plan_type = model.TYPE_CHARGE
interval = 5
external_id = '5566_GOOD_BROTHERS'
description = 'This is a long description'
with transaction.manager:
guid = model.create(
company_guid=self.company_guid,
plan_type=plan_type,
name=name,
amount=amount,
frequency=frequency,
interval=interval,
external_id=external_id,
description=description,
)
now = datetime.datetime.utcnow()
plan = model.get(guid)
self.assertEqual(plan.guid, guid)
self.assert_(plan.guid.startswith('PL'))
self.assertEqual(plan.company_guid, self.company_guid)
self.assertEqual(plan.name, name)
self.assertEqual(plan.amount, amount)
self.assertEqual(plan.frequency, frequency)
self.assertEqual(plan.interval, interval)
self.assertEqual(plan.plan_type, plan_type)
self.assertEqual(plan.external_id, external_id)
self.assertEqual(plan.description, description)
self.assertEqual(plan.deleted, False)
self.assertEqual(plan.created_at, now)
self.assertEqual(plan.updated_at, now)
def test_create_different_created_updated_time(self):
from billy.models import tables
model = self.make_one(self.session)
results = [
datetime.datetime(2013, 8, 16, 1),
datetime.datetime(2013, 8, 16, 2),
]
def mock_utcnow():
return results.pop(0)
tables.set_now_func(mock_utcnow)
with transaction.manager:
guid = model.create(
company_guid=self.company_guid,
plan_type=model.TYPE_CHARGE,
amount=999,
frequency=model.FREQ_MONTHLY,
)
plan = model.get(guid)
self.assertEqual(plan.created_at, plan.updated_at)
def test_create_with_zero_interval(self):
#.........这里部分代码省略.........
示例15: TestSubscriptionModel
# 需要导入模块: from billy.models.company import CompanyModel [as 别名]
# 或者: from billy.models.company.CompanyModel import create [as 别名]
class TestSubscriptionModel(ModelTestCase):
def setUp(self):
from billy.models.company import CompanyModel
from billy.models.customer import CustomerModel
from billy.models.plan import PlanModel
super(TestSubscriptionModel, self).setUp()
# build the basic scenario for plan model
self.company_model = CompanyModel(self.session)
self.customer_model = CustomerModel(self.session)
self.plan_model = PlanModel(self.session)
with db_transaction.manager:
self.company_guid = self.company_model.create('my_secret_key')
self.daily_plan_guid = self.plan_model.create(
company_guid=self.company_guid,
plan_type=self.plan_model.TYPE_CHARGE,
amount=1000, # 10 dollars
frequency=self.plan_model.FREQ_DAILY,
)
self.weekly_plan_guid = self.plan_model.create(
company_guid=self.company_guid,
plan_type=self.plan_model.TYPE_CHARGE,
amount=1000,
frequency=self.plan_model.FREQ_WEEKLY,
)
self.monthly_plan_guid = self.plan_model.create(
company_guid=self.company_guid,
plan_type=self.plan_model.TYPE_CHARGE,
amount=1000,
frequency=self.plan_model.FREQ_MONTHLY,
)
self.customer_tom_guid = self.customer_model.create(
company_guid=self.company_guid,
)
def make_one(self, *args, **kwargs):
from billy.models.subscription import SubscriptionModel
return SubscriptionModel(*args, **kwargs)
def test_get_subscription(self):
model = self.make_one(self.session)
subscription = model.get('SU_NON_EXIST')
self.assertEqual(subscription, None)
with self.assertRaises(KeyError):
model.get('SU_NON_EXIST', raise_error=True)
with db_transaction.manager:
guid = model.create(
customer_guid=self.customer_tom_guid,
plan_guid=self.monthly_plan_guid,
)
subscription = model.get(guid, raise_error=True)
self.assertEqual(subscription.guid, guid)
def test_create(self):
model = self.make_one(self.session)
amount = 5566
external_id = '5566_GOOD_BROTHERS'
customer_guid = self.customer_tom_guid
plan_guid = self.monthly_plan_guid
payment_uri = '/v1/credit_cards/id'
with db_transaction.manager:
guid = model.create(
customer_guid=customer_guid,
plan_guid=plan_guid,
amount=amount,
external_id=external_id,
payment_uri=payment_uri,
)
now = datetime.datetime.utcnow()
subscription = model.get(guid)
self.assertEqual(subscription.guid, guid)
self.assert_(subscription.guid.startswith('SU'))
self.assertEqual(subscription.customer_guid, customer_guid)
self.assertEqual(subscription.plan_guid, plan_guid)
self.assertEqual(subscription.amount, amount)
self.assertEqual(subscription.external_id, external_id)
self.assertEqual(subscription.payment_uri, payment_uri)
self.assertEqual(subscription.period, 0)
self.assertEqual(subscription.canceled, False)
self.assertEqual(subscription.canceled_at, None)
self.assertEqual(subscription.started_at, now)
self.assertEqual(subscription.next_transaction_at, now)
self.assertEqual(subscription.created_at, now)
self.assertEqual(subscription.updated_at, now)
def test_create_different_created_updated_time(self):
from billy.models import tables
model = self.make_one(self.session)
results = [
datetime.datetime(2013, 8, 16, 1),
datetime.datetime(2013, 8, 16, 2),
]
#.........这里部分代码省略.........