@@ -0,0 +1,2024 @@
+from django.utils import timezone%0A%0Afrom oscar.core.loading import get_model%0A%0Afrom oscarapi.tests.utils import APITest%0A%0A%0ABasket = get_model('basket', 'Basket')%0AConditionalOffer = get_model('offer', 'ConditionalOffer')%0AVoucher = get_model('voucher', 'Voucher')%0A%0A%0Aclass VoucherTest(APITest):%0A    fixtures = %5B%0A        'product', 'productcategory', 'productattribute', 'productclass',%0A        'productattributevalue', 'category', 'attributeoptiongroup',%0A        'attributeoption', 'stockrecord', 'partner', 'voucher'%0A    %5D%0A%0A    def setUp(self):%0A        # Adjust offer dates so it's valid%0A        offer = ConditionalOffer.objects.get(%0A            name=%22Offer for voucher 'testvoucher'%22)%0A        offer.start_datetime = timezone.now()%0A        offer.end_datetime = timezone.now() + timezone.timedelta(days=1)%0A        offer.save()%0A%0A        # adjust voucher dates for testing the view%0A        voucher = Voucher.objects.get(name=%22testvoucher%22)%0A        voucher.start_datetime = timezone.now()%0A        voucher.end_datetime = timezone.now() + timezone.timedelta(days=1)%0A        voucher.save()%0A%0A        super(VoucherTest, self).setUp()%0A%0A    def test_basket_add_voucher(self):%0A        %22%22%22Check if we can add a voucher with the add-voucher api call%22%22%22%0A        # first add two products to our basket%0A        self.response = self.post(%0A            'api-basket-add-product',%0A            url=%22http://testserver/api/products/1/%22,%0A            quantity=2)%0A        self.response.assertStatusEqual(200)%0A%0A        # total should be 20%0A        self.response = self.get('api-basket')%0A        self.response.assertValueEqual('total_incl_tax', '20.00')%0A%0A        # add a voucher and see if the voucher is added correctly%0A        self.response = self.post(%0A            'api-basket-add-voucher',%0A            vouchercode='TESTVOUCHER')%0A        self.response.assertStatusEqual(200)%0A%0A        # see if the discount of 5.00 from the voucher was applied%0A        self.response = self.get('api-basket')%0A        self.response.assertValueEqual('total_incl_tax', '15.00')%0A

Add a test for the api-basket-add-voucher view