本文整理汇总了Python中billy.models.company.CompanyModel类的典型用法代码示例。如果您正苦于以下问题:Python CompanyModel类的具体用法?Python CompanyModel怎么用?Python CompanyModel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CompanyModel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
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)
示例2: test_get_subscription_of_other_company
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
)
示例3: test_create_subscription_to_other_company_plan
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
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: auth_api_key
def auth_api_key(request):
"""Authenticate API KEY and return corresponding company
"""
model = CompanyModel(request.session)
company = model.get_by_api_key(unicode(request.remote_user))
if company is None:
raise HTTPForbidden('Invalid API key {}'.format(request.remote_user))
return company
示例6: company_list_post
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
示例7: company_get
def company_get(request):
"""Get and return a company
"""
api_company = auth_api_key(request)
model = CompanyModel(request.session)
guid = request.matchdict['company_guid']
company = model.get(guid)
if company is None:
return HTTPNotFound('No such company {}'.format(guid))
if guid != api_company.guid:
return HTTPForbidden('You have no premission to access company {}'.format(guid))
return company
示例8: test_company
def test_company(self):
from billy.models.company import CompanyModel
from billy.renderers import company_adapter
company_model = CompanyModel(self.testapp.session)
company = company_model.get(self.company_guid)
json_data = company_adapter(company, self.dummy_request)
expected = dict(
guid=company.guid,
api_key=company.api_key,
created_at=company.created_at.isoformat(),
updated_at=company.updated_at.isoformat(),
)
self.assertEqual(json_data, expected)
示例9: setUp
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',
)
示例10: test_create_subscription_to_other_company_customer
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,
)
示例11: setUp
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')
示例12: setUp
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,
)
示例13: test_cancel_subscription_to_other_company
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,
)
示例14: test_get_customer_of_other_company
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,
)
示例15: test_server_info_with_transaction
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())