Ejemplo n.º 1
0
    def test_coupon_valid(self):

        print('Тестирование функции coupon_valid')
        self.assertEqual(coupon_valid(Coupon.objects.get(code="cpn_inactive")), False)
        self.assertEqual(coupon_valid(Coupon.objects.get(code="cpn_expire")), False)
        self.assertEqual(coupon_valid(Coupon.objects.get(code="cpn_not_expire")), True)
        self.assertEqual(coupon_valid(Coupon.objects.get(code="cpn_early")), False)
        self.assertEqual(coupon_valid(Coupon.objects.get(code="cpn_not_early")), True)
        self.assertEqual(coupon_valid(Coupon.objects.get(code="cpn_used_max_times")), False)
        self.assertEqual(coupon_valid(Coupon.objects.get(code="cpn_not_used_max_times")), True)
        self.assertEqual(coupon_valid(Coupon.objects.get(code="cpn_all_valid")), True)
Ejemplo n.º 2
0
def add_coupon(request):
    coupon = get_coupon(request)
    result = {}

    if coupon is None or not coupon_valid(coupon):
        result['error'] = 'Неверный код купона'
        return JsonResponse(result)

    cart, created = get_cart(request)
    coupon.carts.add(cart)
    result['html'] = render_to_string('coupons/cart_coupons_form.html',
                                      {'cart_coupons': Coupon.objects.filter(carts=cart)},
                                      context_instance=RequestContext(request))
    return JsonResponse(result)
Ejemplo n.º 3
0
def add_coupon(request):
    coupon = get_coupon(request)
    result = {}

    if coupon is None or not coupon_valid(coupon):
        result['error'] = 'Неверный код купона'
        return JsonResponse(result)

    cart, created = get_cart(request)
    coupon.carts.add(cart)
    result['html'] = render_to_string(
        'coupons/cart_coupons_form.html',
        {'cart_coupons': Coupon.objects.filter(carts=cart)},
        context_instance=RequestContext(request))
    return JsonResponse(result)
Ejemplo n.º 4
0
    def test_coupon_valid(self):

        print('Тестирование функции coupon_valid')
        self.assertEqual(coupon_valid(Coupon.objects.get(code="cpn_inactive")),
                         False)
        self.assertEqual(coupon_valid(Coupon.objects.get(code="cpn_expire")),
                         False)
        self.assertEqual(
            coupon_valid(Coupon.objects.get(code="cpn_not_expire")), True)
        self.assertEqual(coupon_valid(Coupon.objects.get(code="cpn_early")),
                         False)
        self.assertEqual(
            coupon_valid(Coupon.objects.get(code="cpn_not_early")), True)
        self.assertEqual(
            coupon_valid(Coupon.objects.get(code="cpn_used_max_times")), False)
        self.assertEqual(
            coupon_valid(Coupon.objects.get(code="cpn_not_used_max_times")),
            True)
        self.assertEqual(
            coupon_valid(Coupon.objects.get(code="cpn_all_valid")), True)