Add test to check adding/removing of a voucher
@@ -4,7 +4,9 @@ from django.urls import reverse
from oscar.apps.basket import views
from oscar.test import factories
+from oscar.test.testcases import WebTestCase
from tests.fixtures import RequestFactory
+from tests.functional.checkout import CheckoutMixin
class TestVoucherAddView(TestCase):
@@ -109,3 +111,36 @@ class TestBasketSummaryView(TestCase):
request = RequestFactory().get(self.url)
view = views.BasketView(request=request)
self.assertIsNone(view.get_default_shipping_address())
+
+
+class TestVoucherViews(CheckoutMixin, WebTestCase):
+ csrf_checks = False
+
+ def setUp(self):
+ self.voucher = factories.create_voucher()
+ super().setUp()
+
+ def test_add_voucher(self):
+ """
+ Checks that voucher can be added to basket through appropriate view.
+ """
+ self.add_product_to_basket()
+
+ assert self.voucher.basket_set.count() == 0
+
+ response = self.post(reverse('basket:vouchers-add'), params={'code': self.voucher.code})
+ self.assertRedirectsTo(response, 'basket:summary')
+ assert self.voucher.basket_set.count() == 1
+
+ def test_remove_voucher(self):
+ """
+ Checks that voucher can be removed from basket through appropriate view.
+ """
+ self.add_product_to_basket()
+ self.add_voucher_to_basket(voucher=self.voucher)
+
+ assert self.voucher.basket_set.count() == 1
+
+ response = self.post(reverse('basket:vouchers-remove', kwargs={'pk': self.voucher.id}))
+ self.assertRedirectsTo(response, 'basket:summary')
+ assert self.voucher.basket_set.count() == 0
