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.

tests.py 1.3KB

123456789101112131415161718192021222324252627282930
  1. from django.utils import unittest
  2. from django.test.client import Client
  3. from django.core.urlresolvers import reverse
  4. from django.http import HttpRequest
  5. from oscar.product.models import Item, ItemClass
  6. from oscar.customer.history_helpers import get_recently_viewed_product_ids
  7. class HistoryHelpersTest(unittest.TestCase):
  8. def setUp(self):
  9. self.client = Client()
  10. # Create a dummy product
  11. ic,_ = ItemClass.objects.get_or_create(name='Dummy class')
  12. self.dummy_product = Item.objects.create(title='Dummy product', item_class=ic)
  13. args = {'item_class_slug': self.dummy_product.get_item_class().slug,
  14. 'item_slug': self.dummy_product.slug,
  15. 'item_id': self.dummy_product.id}
  16. self.dummy_product_url = reverse('oscar-product-item', kwargs=args)
  17. def test_viewing_product_creates_cookie(self):
  18. response = self.client.get(self.dummy_product_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.dummy_product_url)
  22. request = HttpRequest()
  23. request.COOKIES['oscar_recently_viewed_products'] = response.cookies['oscar_recently_viewed_products'].value
  24. self.assertTrue(self.dummy_product.id in get_recently_viewed_product_ids(request))