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.

wishlist_tests.py 1.3KB

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