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.

history_tests.py 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. from django.test.client import Client
  2. from django.contrib.auth.models import User
  3. from django.core.urlresolvers import reverse
  4. from django.test import TestCase
  5. from oscar_testsupport.factories import create_product
  6. from oscar.apps.customer.history_helpers import get_recently_viewed_product_ids
  7. from django.http import HttpRequest
  8. class HistoryHelpersTest(TestCase):
  9. def setUp(self):
  10. self.client = Client()
  11. self.product = create_product()
  12. def test_viewing_product_creates_cookie(self):
  13. response = self.client.get(self.product.get_absolute_url())
  14. self.assertTrue('oscar_recently_viewed_products' in response.cookies)
  15. def test_id_gets_added_to_cookie(self):
  16. response = self.client.get(self.product.get_absolute_url())
  17. request = HttpRequest()
  18. request.COOKIES['oscar_recently_viewed_products'] = response.cookies['oscar_recently_viewed_products'].value
  19. self.assertTrue(self.product.id in get_recently_viewed_product_ids(request))
  20. class TestAUserWhoLogsOut(TestCase):
  21. username = 'customer'
  22. password = 'cheeseshop'
  23. email = 'customer@example.com'
  24. def setUp(self):
  25. self.client = Client()
  26. self.product = create_product()
  27. User.objects.create_user(username=self.username,
  28. email=self.email, password=self.password)
  29. self.client.login(username=self.username, password=self.password)
  30. def test_has_their_cookies_deleted_on_logout(self):
  31. response = self.client.get(self.product.get_absolute_url())
  32. self.assertTrue('oscar_recently_viewed_products' in response.cookies)
  33. response = self.client.get(reverse('customer:logout'))
  34. self.assertTrue(('oscar_recently_viewed_products' not in response.cookies)
  35. or not
  36. self.client.cookies['oscar_recently_viewed_products'].coded_value)