You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

wishlists_tests.py 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. # -*- coding: utf-8 -*-
  2. from django.core.urlresolvers import reverse
  3. from django.db.models import get_model
  4. from oscar.test.factories import create_product
  5. from oscar.test.testcases import ClientTestCase
  6. WishList = get_model('wishlists', 'WishList')
  7. class TestProductDetailPage(ClientTestCase):
  8. def setUp(self):
  9. super(TestProductDetailPage, self).setUp()
  10. self.product = create_product()
  11. def test_contains_add_to_wishlist_url(self):
  12. resp = self.client.get(self.product.get_absolute_url())
  13. self.assertContains(resp, reverse('customer:wishlists-create',
  14. args=[self.product.pk]))
  15. def test_add_a_product_to_wishlist(self):
  16. resp = self.client.get(reverse('customer:wishlists-create',
  17. args=[self.product.pk]))
  18. self.assertIsOk(resp)
  19. self.assertEqual(WishList.objects.count(), 0)
  20. self.assertEqual(self.product.wishlists_lines.count(), 0)
  21. # not done here, need to submit the wishlist
  22. # and verify it can be deleted
  23. data = {'name': 'Shopping list for Santa Claus'}
  24. resp = self.client.post(reverse('customer:wishlists-create',
  25. args=[self.product.pk]), data)
  26. self.assertIsRedirect(resp)
  27. self.assertEqual(WishList.objects.count(), 1)
  28. self.assertEqual(self.product.wishlists_lines.count(), 1)
  29. wishlist = WishList.objects.all()[0]
  30. resp = self.client.post(reverse('customer:wishlists-delete',
  31. args=[wishlist.key, ]))
  32. self.assertIsRedirect(resp)
  33. self.assertEqual(WishList.objects.count(), 0)
  34. self.assertEqual(self.product.wishlists_lines.count(), 0)