def test_customer_redirects_to_payment(self): """Because there is no postage required, any attempt to access postage redirects to the payment page""" # no customer the postage redirects and so does the payment request = self.rf.get(reverse('cccheckout:postage')) request.session['cccheckout'] = self.checkout r = postage(request) self.assertEqual(302, r.status_code) # payment redirects request = self.rf.get(reverse('cccheckout:payment')) request.session['cccheckout'] = self.checkout r = payment(request) self.assertEqual(302, r.status_code) # add a customer and it is now only postage redirects self.checkout.customer = Customer() self.checkout.customer.save() self.checkout.save() # get the views again and postage is still 302 request = self.rf.get(reverse('cccheckout:postage')) request.session['cccheckout'] = self.checkout r = postage(request) self.assertEqual(302, r.status_code) # payment redirects request = self.rf.get(reverse('cccheckout:payment')) request.session['cccheckout'] = self.checkout r = payment(request) self.assertEqual(200, r.status_code)
def test_postage_200(self): """If a basket is not empty then the checkout reponds with 200""" request = self.rf.get(reverse('cccheckout:postage')) request.session['cccheckout'] = self.checkout request.session.save() response = postage(request) # request = self.rf.get(reverse('cccheckout:postage')) # add a rudimentray customer self.checkout.customer = Customer() self.checkout.customer.save() request.session['cccheckout'] = self.checkout request.session.save() response = postage(request) self.assertEqual(200, response.status_code)
def test_decorator_200_if_postage_view(self): """If the postage view is being called then there are no validations""" request = self.rf.get(reverse('cccheckout:postage')) request.session['cccheckout'] = self.checkout request.session.save() response = postage(request) self.assertEqual(200, response.status_code)
def test_is_false(self): """ if CCCHECKOUT_ALLOW_GUEST == `True`: checkout flow proceeds without a redirect to settings.LOGIN_URL """ # set to False settings.CCCHECKOUT_ALLOW_GUEST = False # customer request = self.rf.get(reverse('cccheckout:customer')) request.session['cccheckout'] = self.checkout request.session.save() response = customer(request) self.assertEqual(302, response.status_code) # postage request = self.rf.get(reverse('cccheckout:postage')) request.session['cccheckout'] = self.checkout request.session.save() response = postage(request) self.assertEqual(302, response.status_code) # payment request = self.rf.get(reverse('cccheckout:payment')) request.session['cccheckout'] = self.checkout request.session.save() response = payment(request) self.assertEqual(302, response.status_code)
def test_postage_redirects_to_payment(self): """Any attempt to acccess the postage view redirect to the payment view""" checkout = deepcopy(self.checkout) request = self.rf.get(reverse('cccheckout:postage')) request.session['cccheckout'] = checkout r = postage(request) self.assertEqual(302, r.status_code) self.assertEqual(r['Location'], reverse('cccheckout:payment'))
def test_postage_decorator_not_required(self): """If there is no postage models in the settings then the postage view redirects""" settings.CCCHECKOUT_POSTAGE_MODELS = [] reload(c_settings) request = self.rf.get(reverse('cccheckout:postage')) request.session['cccheckout'] = self.checkout request.session.save() response = postage(request) self.assertEqual(302, response.status_code) self.assertEqual(response['Location'], reverse('cccheckout:payment'))
def test_invalid_postage_is_200(self): """Invalid postage data will result the user not being forwarded to the next step and they're returned to the postage page""" value = '20:20|30:30' data = {'available_methods': value} request = self.rf.post(reverse('cccheckout:postage'), data) request.session['cccheckout'] = self.checkout request.session.save() response = postage(request) # postage and postage_tier have not been saved onto the checkout checkout = request.session['cccheckout'] self.assertEqual(checkout.postage, None) self.assertEqual(checkout.postage_tier, None) # and the status was 200 self.assertEqual(200, response.status_code)
def test_valid_postage_saved(self): """if valid postage information is sent to the view the resulting postage and tier is saved onto the checkout""" value = '%s:%s|%s:%s' % ( self.line_ct.pk, self.line1.pk, self.tier_ct.pk, self.tier1.pk) data = {'available_methods': value} request = self.rf.post(reverse('cccheckout:postage'), data) request.session['cccheckout'] = self.checkout request.session.save() response = postage(request) # postage and postage_tier have been saved onto the checkout checkout = request.session['cccheckout'] self.assertEqual(checkout.postage, self.line1) self.assertEqual(checkout.postage_tier, self.tier1) self.assertEqual(checkout.postage_form_value, value)
def test_postage_redirects_empty(self): """If a basket is empty then the checkout redirects to the basket""" request = self.rf.get(reverse('cccheckout:postage')) response = postage(request) self.assertEqual(302, response.status_code)