def test_plans_parsing(self): responses.add(responses.POST, Plan.build_url('/plans/get'), body=self.read_fixture('plans.xml'), content_type='application/xml') plans = Plan.all() assert len(plans) == 2 plan = plans[0] assert plan.id == '6b0d13f4-6bef-102e-b098-40402145ee8b' assert plan.code == 'FREE_MONTHLY' assert plan.recurring_charge_amount == 0.0 assert plan.name == 'Free Monthly' assert plan.billing_frequency == 'monthly' assert plan.billing_frequency_quantity == 1 assert plan.setup_charge_code == None assert plan.is_active == 1 assert plan.is_free == 1 assert plan.billing_frequency_unit == 'months' assert plan.initial_bill_count_unit == 'months' assert plan.setup_charge_amount == 0.0 assert plan.billing_frequency_per == 'month' assert plan.trial_days == 0 assert plan.created_datetime == \ arrow.get('2011-01-07T20:46:43+00:00').datetime assert plan.recurring_charge_code == 'FREE_MONTHLY_RECURRING' assert plan.initial_bill_count == 1 assert plan.description == 'A free monthly plan' plan = plans[1] assert plan.id == '11af9cfc-6bf2-102e-b098-40402145ee8b' assert plan.code == 'PAID_MONTHLY' assert plan.recurring_charge_amount == 20.0 assert plan.name == 'Paid Monthly' assert plan.billing_frequency == 'monthly' assert plan.billing_frequency_quantity == 1 assert plan.setup_charge_code == None assert plan.is_active == 1 assert plan.is_free == 0 assert plan.billing_frequency_unit == 'months' assert plan.initial_bill_count_unit == 'months' assert plan.setup_charge_amount == 0.0 assert plan.billing_frequency_per == 'month' assert plan.trial_days == 0 assert plan.created_datetime == \ arrow.get('2011-01-07T21:05:42+00:00').datetime assert plan.recurring_charge_code == 'PAID_MONTHLY_RECURRING' assert plan.initial_bill_count == 1 assert plan.description == None
def test_update_customer_subscription(self): # Response for customer query responses.add(responses.POST, Customer.build_url('/customers/get'), body=self.read_fixture('customers_without_items.xml'), content_type='application/xml') # Response for query to new plan when plan code for subscription is # changed responses.add(responses.POST, Plan.build_url('/plans/get', code='PAID_MONTHLY'), body=self.read_fixture('plan_paid_monthly.xml'), content_type='application/xml') customers = Customer.all() assert len(customers) == 1 customer = customers[0] # Response for edit request responses.add(responses.POST, Customer.build_url('/customers/edit', code=customer.code), status=200, body='<xml></xml>', content_type='application/xml') customer.subscription.plan_code = 'PAID_MONTHLY' customer.save() assert len(responses.calls) == 3 edit_request = responses.calls[2].request body = urlparse.parse_qs(edit_request.body) assert body['subscription[planCode]'] == ['PAID_MONTHLY']
def get_items_by_customer_code(): """Helper method that uses the /customer/list API of endpoint to get a dictionary of the items available to each customer keyed by code.""" plans = {plan.code: plan for plan in Plan.all()} customers = Customer.list() items = {} for customer in customers: # Grab the items for each customer from the plan of the subscription items[int(customer.code)] = {item.name: item.quantity_included \ for item in plans[customer.subscription.plan.code].items} return items
def test_create_customer_with_subscription(self): responses.add(responses.POST, Customer.build_url('/customers/new', is_new=True), status=200, body='<xml></xml>', content_type='application/xml') responses.add(responses.POST, Plan.build_url('/plans/get', code='FREE_MONTHLY'), body=self.read_fixture('plan_free_monthly.xml'), content_type='application/xml') customer = Customer() customer.code = '1' customer.first_name = 'Test' customer.last_name = 'User' customer.email = 'Email' customer.subscription.plan_code = 'FREE_MONTHLY' customer.subscription.cc_number = '1234123412341234' customer.subscription.cc_first_name = 'First' customer.subscription.cc_last_name = 'Last' customer.subscription.cc_expiration = '20/2020' customer.subscription.cc_card_code = '123' customer.save() # There should be 2 calls, one to fetch the plan information then one # to create the customer with the subscription assert len(responses.calls) == 2 assert responses.calls[0].request.method == 'POST' request = responses.calls[1].request assert request.method == 'POST' body = urlparse.parse_qs(request.body) assert body['code'] == ['1'] assert body['firstName'] == ['Test'] assert body['lastName'] == ['User'] assert body['email'] == ['Email'] assert body['subscription[planCode]'] == ['FREE_MONTHLY'] assert body['subscription[ccNumber]'] == ['1234123412341234'] assert body['subscription[ccFirstName]'] == ['First'] assert body['subscription[ccLastName]'] == ['Last'] assert body['subscription[ccExpiration]'] == ['20/2020'] assert body['subscription[ccCardCode]'] == ['123'] # This should not result in an additional call because nothing has been # changed since the last save customer.save() assert len(responses.calls) == 2
def test_plan_with_items_parsing(self): responses.add(responses.POST, Plan.build_url('/plans/get'), body=self.read_fixture('plans_with_items.xml'), content_type='application/xml') plans = Plan.all() assert len(plans) == 3 plan = plans[0] assert plan.id == '6b0d13f4-6bef-102e-b098-40402145ee8b' assert plan.code == 'FREE_MONTHLY' assert plan.recurring_charge_amount == 0.0 assert plan.name == 'Free Monthly' assert plan.billing_frequency == 'monthly' assert plan.billing_frequency_quantity == 1 assert plan.setup_charge_code == None assert plan.is_active == 1 assert plan.is_free == 1 assert plan.billing_frequency_unit == 'months' assert plan.initial_bill_count_unit == 'months' assert plan.setup_charge_amount == 0.0 assert plan.billing_frequency_per == 'month' assert plan.trial_days == 0 assert plan.created_datetime == \ arrow.get('2011-01-07T20:46:43+00:00').datetime assert plan.recurring_charge_code == 'FREE_MONTHLY_RECURRING' assert plan.initial_bill_count == 1 assert plan.description == 'A free monthly plan' item = plan.items[0] assert item.id == 'd19b4970-6e5a-102e-b098-40402145ee8b' assert item.code == 'MONTHLY_ITEM' assert item.quantity_included == 0 assert item.is_periodic == 0 assert item.overage_amount == 0.00 assert item.created_datetime == \ arrow.get('2011-01-10T22:40:34+00:00').datetime item = plan.items[1] assert item.id == 'd19ef2f0-6e5a-102e-b098-40402145ee8b' assert item.code == 'ONCE_ITEM' assert item.quantity_included == 0 assert item.is_periodic == 0 assert item.overage_amount == 0.00 assert item.created_datetime == \ arrow.get('2011-01-10T22:40:34+00:00').datetime plan = plans[1] assert plan.id == 'd19974a6-6e5a-102e-b098-40402145ee8b' assert plan.code == 'TRACKED_MONTHLY' assert plan.recurring_charge_amount == 10.0 assert plan.name == 'Tracked Monthly' assert plan.billing_frequency == 'monthly' assert plan.billing_frequency_quantity == 1 assert plan.setup_charge_code == None assert plan.is_active == 1 assert plan.is_free == 0 assert plan.billing_frequency_unit == 'months' assert plan.initial_bill_count_unit == 'months' assert plan.setup_charge_amount == 0.0 assert plan.billing_frequency_per == 'month' assert plan.trial_days == 0 assert plan.created_datetime == \ arrow.get('2011-01-10T22:40:34+00:00').datetime assert plan.recurring_charge_code == 'TRACKED_MONTHLY_RECURRING' assert plan.initial_bill_count == 1 assert plan.description == None assert len(plan.items) == 2 item = plan.items[0] assert item.id == 'd19b4970-6e5a-102e-b098-40402145ee8b' assert item.code == 'MONTHLY_ITEM' assert item.quantity_included == 2 assert item.is_periodic == 1 assert item.overage_amount == 10.00 assert item.created_datetime == \ arrow.get('2011-01-10T22:40:34+00:00').datetime item = plan.items[1] assert item.id == 'd19ef2f0-6e5a-102e-b098-40402145ee8b' assert item.code == 'ONCE_ITEM' assert item.quantity_included == 0 assert item.is_periodic == 0 assert item.overage_amount == 10.00 assert item.created_datetime == \ arrow.get('2011-01-10T22:40:34+00:00').datetime plan = plans[2] assert plan.id == '11af9cfc-6bf2-102e-b098-40402145ee8b' assert plan.code == 'PAID_MONTHLY' assert plan.recurring_charge_amount == 20.0 assert plan.name == 'Paid Monthly' assert plan.billing_frequency == 'monthly' assert plan.billing_frequency_quantity == 1 assert plan.setup_charge_code == None assert plan.is_active == 1 assert plan.is_free == 0 assert plan.billing_frequency_unit == 'months' assert plan.initial_bill_count_unit == 'months' assert plan.setup_charge_amount == 0.0 assert plan.billing_frequency_per == 'month' assert plan.trial_days == 0 assert plan.created_datetime == \ arrow.get('2011-01-07T21:05:42+00:00').datetime assert plan.recurring_charge_code == 'PAID_MONTHLY_RECURRING' assert plan.initial_bill_count == 1 assert plan.description == None assert len(plan.items) == 2 item = plan.items[0] assert item.id == 'd19b4970-6e5a-102e-b098-40402145ee8b' assert item.code == 'MONTHLY_ITEM' assert item.quantity_included == 0 assert item.is_periodic == 0 assert item.overage_amount == 0.00 assert item.created_datetime == \ arrow.get('2011-01-10T22:40:34+00:00').datetime item = plan.items[1] assert item.id == 'd19ef2f0-6e5a-102e-b098-40402145ee8b' assert item.code == 'ONCE_ITEM' assert item.quantity_included == 0 assert item.is_periodic == 0 assert item.overage_amount == 0.00 assert item.created_datetime == \ arrow.get('2011-01-10T22:40:34+00:00').datetime