예제 #1
0
 def test_check_deprecated_hash_verification(self):
     order = OrderFactory(number='100001')
     # Check that check_deprecated_verification_hash validates the hash
     self.assertTrue(
         order.check_deprecated_verification_hash('3efd0339e8c789447469f37851cbaaaf')
     )
     # Check that check_verification_hash calls it correctly
     self.assertTrue(order.check_verification_hash('3efd0339e8c789447469f37851cbaaaf'))
예제 #2
0
    def test_num_orders(self):
        voucherset = VoucherSetFactory()
        assert voucherset.num_orders == 0

        order = OrderFactory()
        user, order = UserFactory(), OrderFactory()
        voucher = voucherset.vouchers.first()
        voucher.record_usage(order, user)
        assert voucherset.num_orders == 1
예제 #3
0
    def test_shipping_status(self):
        order = OrderFactory()

        line_1 = OrderLineFactory(
            order=order, partner_sku='SKU1234', quantity=2)
        line_2 = OrderLineFactory(
            order=order, partner_sku='SKU5678', quantity=1)
        self.assertEqual(order.shipping_status, '')

        event_1 = ShippingEventFactory(order=order, event_type__name='Shipped')
        event_2 = ShippingEventFactory(order=order, event_type__name='Returned')

        # Default status
        self.assertEqual(order.shipping_status, _('In progress'))

        # Set first line to shipped
        event_1.line_quantities.create(line=line_1, quantity=2)
        self.assertEqual(order.shipping_status, _('In progress'))

        # Set first line to returned
        event_2.line_quantities.create(line=line_1, quantity=2)
        self.assertEqual(order.shipping_status, _('In progress'))

        # Set second line to shipped
        event_1.line_quantities.create(line=line_2, quantity=1)
        self.assertEqual(order.shipping_status, _('Shipped'))

        # Set second line to returned
        event_2.line_quantities.create(line=line_2, quantity=1)
        self.assertEqual(order.shipping_status, _('Returned'))
예제 #4
0
    def test_is_available_to_a_user_once(self):
        user, order = UserFactory(), OrderFactory()
        is_voucher_available_to_user, __ = self.voucher.is_available_to_user(user=user)
        self.assertTrue(is_voucher_available_to_user)

        self.voucher.record_usage(order, user)
        is_voucher_available_to_user, __ = self.voucher.is_available_to_user(user=user)
        self.assertFalse(is_voucher_available_to_user)
예제 #5
0
    def test_is_available_to_different_users(self):
        users, order = [UserFactory(), UserFactory()], OrderFactory()
        for user in users:
            is_voucher_available_to_user, __ = self.voucher.is_available_to_user(user=user)
            self.assertTrue(is_voucher_available_to_user)

            self.voucher.record_usage(order, user)
            is_voucher_available_to_user, __ = self.voucher.is_available_to_user(user=user)
            self.assertFalse(is_voucher_available_to_user)
예제 #6
0
    def test_analytics_event_triggered_only_on_first_view(self):
        order = OrderFactory()
        session = self.client.session
        # Put the order ID in the session, mimicking a completed order,
        # so that we can reach the thank you page.
        session['checkout_order_id'] = order.pk
        session.save()

        r1 = self.client.get(reverse('checkout:thank-you'), follow=True)
        self.assertTrue(r1.context['send_analytics_event'])

        # Request the view a second time
        r2 = self.client.get(reverse('checkout:thank-you'), follow=True)
        self.assertFalse(r2.context['send_analytics_event'])
예제 #7
0
 def test_check_deprecated_hash_verification_old_key_matches_new(self):
     order = OrderFactory(number='100001')
     # IZI_DEPRECATED_ORDER_VERIFY_KEY must not be equal to SECRET_KEY.
     with self.assertRaises(ImproperlyConfigured):
         order.check_deprecated_verification_hash('3efd0339e8c789447469f37851cbaaaf')
예제 #8
0
 def test_check_deprecated_hash_verification_without_old_key(self):
     order = OrderFactory(number='100001')
     # Check that check_deprecated_verification_hash validates the hash
     self.assertFalse(
         order.check_deprecated_verification_hash('3efd0339e8c789447469f37851cbaaaf')
     )
예제 #9
0
 def test_check_verification_hash_valid_signature_but_wrong_number(self):
     order = OrderFactory(number='111000')
     # Hash is valid, but it is for a different order number
     self.assertFalse(order.check_verification_hash('222000:knvoMB1KAiJu8meWtGce00Y88j4'))
예제 #10
0
 def test_check_verification_hash_invalid_signature(self):
     order = OrderFactory(number='111000')
     self.assertFalse(order.check_verification_hash('111000:HKDZWNPLsq7589517c3v1Q6DHKD'))
예제 #11
0
 def test_check_verification_hash_valid(self):
     order = OrderFactory(number='111000')
     self.assertTrue(order.check_verification_hash('111000:UJrZWNPLsq7zf1r17c3v1Q6DUmE'))
예제 #12
0
 def test_verification_hash_generation(self):
     order = OrderFactory(number='111000')
     self.assertEqual(order.verification_hash(), '111000:UJrZWNPLsq7zf1r17c3v1Q6DUmE')
예제 #13
0
 def test_is_available_to_same_user_multiple_times(self):
     user, order = UserFactory(), OrderFactory()
     for i in range(10):
         self.voucher.record_usage(order, user)
         is_voucher_available_to_user, __ = self.voucher.is_available_to_user(user=user)
         self.assertTrue(is_voucher_available_to_user)