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.

test_wishlist.py 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. from django.test import TestCase
  2. from oscar.apps.wishlists.models import WishList
  3. from oscar.core.compat import get_user_model
  4. User = get_user_model()
  5. class TestAWishlist(TestCase):
  6. def test_can_generate_a_random_key(self):
  7. key = WishList.random_key(6)
  8. self.assertTrue(len(key) == 6)
  9. class TestAPublicWishList(TestCase):
  10. def setUp(self):
  11. self.wishlist = WishList(visibility=WishList.PUBLIC)
  12. def test_is_visible_to_anyone(self):
  13. user = User()
  14. self.assertTrue(self.wishlist.is_allowed_to_see(user))
  15. class TestASharedWishList(TestCase):
  16. def setUp(self):
  17. self.wishlist = WishList(visibility=WishList.SHARED)
  18. def test_is_visible_to_anyone(self):
  19. user = User()
  20. self.assertTrue(self.wishlist.is_allowed_to_see(user))
  21. class TestAPrivateWishList(TestCase):
  22. def setUp(self):
  23. self.owner = User(id=1)
  24. self.another_user = User(id=2)
  25. self.wishlist = WishList(owner=self.owner)
  26. def test_is_visible_only_to_its_owner(self):
  27. self.assertTrue(self.wishlist.is_allowed_to_see(self.owner))
  28. self.assertFalse(self.wishlist.is_allowed_to_see(self.another_user))
  29. def test_can_only_be_edited_by_its_owner(self):
  30. self.assertTrue(self.wishlist.is_allowed_to_edit(self.owner))
  31. self.assertFalse(self.wishlist.is_allowed_to_edit(self.another_user))