-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for
basket.VoucherAddView
and basket.VoucherRemoveView
This also fixes the `end_datetime` value set by the VoucherFactory
- Loading branch information
1 parent
11bbfbc
commit c6e7885
Showing
3 changed files
with
56 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
from django.db.models import F | ||
|
||
from oscar.apps.basket import signals | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
from django.contrib.messages import get_messages | ||
from django.test import RequestFactory, TestCase | ||
|
||
from oscar.apps.basket import views | ||
from oscar.test.factories import BasketFactory, VoucherFactory | ||
from oscar.test.utils import RequestFactory | ||
|
||
|
||
class TestVoucherAddView(TestCase): | ||
def test_get(self): | ||
request = RequestFactory().get('/') | ||
|
||
view = views.VoucherAddView.as_view() | ||
response = view(request) | ||
|
||
assert response.status_code == 302 | ||
|
||
def test_post_valid(self): | ||
basket = BasketFactory() | ||
voucher = VoucherFactory() | ||
assert voucher.is_active() | ||
|
||
data = { | ||
'code': voucher.code | ||
} | ||
request = RequestFactory().post('/', data=data, basket=basket) | ||
|
||
view = views.VoucherAddView.as_view() | ||
response = view(request) | ||
assert response.status_code == 302 | ||
|
||
voucher = voucher.__class__.objects.get(pk=voucher.pk) | ||
assert voucher.num_basket_additions == 1, ( | ||
[unicode(m.message) for m in get_messages(request)]) | ||
|
||
|
||
class TestVoucherRemoveView(TestCase): | ||
|
||
def test_post_valid(self): | ||
basket = BasketFactory() | ||
voucher = VoucherFactory() | ||
basket.vouchers.add(voucher) | ||
|
||
data = { | ||
'code': voucher.code | ||
} | ||
request = RequestFactory().post('/', data=data, basket=basket) | ||
|
||
view = views.VoucherRemoveView.as_view() | ||
response = view(request, pk=voucher.pk) | ||
assert response.status_code == 302 | ||
|
||
voucher = voucher.__class__.objects.get(pk=voucher.pk) | ||
assert voucher.num_basket_additions == -1 |