def test_create_customer_without_subscription(self): responses.add(responses.POST, Customer.build_url('/customers/new', is_new=True), status=200, body='<xml></xml>', content_type='application/xml') customer = Customer() customer.code = 1 customer.first_name = 'Test' customer.last_name = 'User' customer.email = 'Email' customer.update_metadata('address', '123 Test street') customer.save() request = responses.calls[0].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['metaData[address]'] == ['123 Test street']
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