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

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