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 )
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)
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)
def setUp(self): from billy.models.company import CompanyModel super(TestCustomerViews, 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)
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
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
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)
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
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, )
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, )
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, )
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, )
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)
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, )
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(TestTransactionViews, 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(), ) company = company_model.get(self.company_guid) self.api_key = str(company.api_key)
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, )
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, )