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 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. # -*- coding: utf-8 -*-
  2. from django.core.urlresolvers import reverse_lazy
  3. from oscar.core.loading import get_model
  4. from oscar.test.factories import create_product, WishListFactory
  5. from oscar.test.testcases import WebTestCase
  6. WishList = get_model('wishlists', 'WishList')
  7. class WishListTestMixin(object):
  8. is_anonymous = False
  9. def setUp(self):
  10. super(WishListTestMixin, self).setUp()
  11. self.product = create_product()
  12. class TestProductDetailPage(WishListTestMixin, WebTestCase):
  13. def test_allows_a_product_to_be_added_to_wishlist(self):
  14. # Click add to wishlist button
  15. detail_page = self.get(self.product.get_absolute_url())
  16. form = detail_page.forms['add_to_wishlist_form']
  17. response = form.submit()
  18. self.assertIsRedirect(response)
  19. # Check a wishlist has been created
  20. wishlists = self.user.wishlists.all()
  21. self.assertEqual(1, len(wishlists))
  22. lines = wishlists[0].lines.all()
  23. self.assertEqual(1, len(lines))
  24. self.assertEqual(self.product, lines[0].product)
  25. class TestMoveProductToAnotherWishList(WishListTestMixin, WebTestCase):
  26. def setUp(self):
  27. super(TestMoveProductToAnotherWishList, self).setUp()
  28. self.wishlist1 = WishListFactory(owner=self.user)
  29. self.wishlist2 = WishListFactory(owner=self.user)
  30. def test_move_product_to_another_wishlist_already_containing_it(self):
  31. self.wishlist1.add(self.product)
  32. line1 = self.wishlist1.lines.get(product=self.product)
  33. self.wishlist2.add(self.product)
  34. url = reverse_lazy('customer:wishlists-move-product-to-another', kwargs={'key': self.wishlist1.key,
  35. 'line_pk': line1.pk,
  36. 'to_key': self.wishlist2.key})
  37. self.get(url)
  38. self.assertEqual(self.wishlist1.lines.filter(product=self.product).count(), 1)
  39. self.assertEqual(self.wishlist2.lines.filter(product=self.product).count(), 1)
  40. def test_move_product_to_another_wishlist(self):
  41. self.wishlist1.add(self.product)
  42. line1 = self.wishlist1.lines.get(product=self.product)
  43. url = reverse_lazy('customer:wishlists-move-product-to-another', kwargs={'key': self.wishlist1.key,
  44. 'line_pk': line1.pk,
  45. 'to_key': self.wishlist2.key})
  46. self.get(url)
  47. self.assertEqual(self.wishlist1.lines.filter(product=self.product).count(), 0)
  48. self.assertEqual(self.wishlist2.lines.filter(product=self.product).count(), 1)