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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import httplib
  2. from decimal import Decimal as D
  3. from django.test.client import Client
  4. from django.test import TestCase
  5. from django.http import HttpRequest
  6. from django.core.urlresolvers import reverse
  7. from oscar.apps.customer.models import CommunicationEventType
  8. from oscar.apps.basket.models import Basket
  9. from oscar.apps.customer.history_helpers import get_recently_viewed_product_ids
  10. from oscar.test.helpers import create_product, create_order
  11. class HistoryHelpersTest(TestCase):
  12. def setUp(self):
  13. self.client = Client()
  14. self.product = create_product()
  15. def test_viewing_product_creates_cookie(self):
  16. response = self.client.get(self.product.get_absolute_url())
  17. self.assertTrue('oscar_recently_viewed_products' in response.cookies)
  18. def test_id_gets_added_to_cookie(self):
  19. response = self.client.get(self.product.get_absolute_url())
  20. request = HttpRequest()
  21. request.COOKIES['oscar_recently_viewed_products'] = response.cookies['oscar_recently_viewed_products'].value
  22. self.assertTrue(self.product.id in get_recently_viewed_product_ids(request))
  23. class CommunicationTypeTest(TestCase):
  24. keys = ('body', 'html', 'sms', 'subject')
  25. def test_no_templates_returns_empty_string(self):
  26. et = CommunicationEventType()
  27. messages = et.get_messages()
  28. for key in self.keys:
  29. self.assertEqual('', messages[key])
  30. def test_field_template_render(self):
  31. et = CommunicationEventType(email_subject_template='Hello {{ name }}')
  32. ctx = {'name': 'world'}
  33. messages = et.get_messages(ctx)
  34. self.assertEqual('Hello world', messages['subject'])
  35. class AnonOrderDetail(TestCase):
  36. def setUp(self):
  37. self.client = Client()
  38. def test_404_received_for_unknown_order(self):
  39. response = self.client.get(reverse('customer:anon-order', kwargs={'order_number': 1000,
  40. 'hash': '1231231232'}))
  41. self.assertEqual(httplib.NOT_FOUND, response.status_code)
  42. def test_200_received_for_order_with_correct_hash(self):
  43. order = create_order()
  44. response = self.client.get(reverse('customer:anon-order', kwargs={'order_number': order.number,
  45. 'hash': order.verification_hash()}))
  46. self.assertEqual(httplib.OK, response.status_code)
  47. def test_404_received_for_order_with_incorrect_hash(self):
  48. order = create_order()
  49. response = self.client.get(reverse('customer:anon-order', kwargs={'order_number': order.number,
  50. 'hash': 'bad'}))
  51. self.assertEqual(httplib.NOT_FOUND, response.status_code)