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.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import unittest
  2. from django.test import TestCase, Client
  3. from django.core.exceptions import ValidationError
  4. from django.core.urlresolvers import reverse
  5. from oscar.apps.product.models import Item, ItemClass
  6. from oscar.apps.partner.models import Partner, StockRecord
  7. class ItemTests(unittest.TestCase):
  8. def setUp(self):
  9. self.item_class,_ = ItemClass.objects.get_or_create(name='Clothing')
  10. class TopLevelItemTests(ItemTests):
  11. def test_top_level_products_must_have_titles(self):
  12. self.assertRaises(ValidationError, Item.objects.create, item_class=self.item_class)
  13. class VariantItemTests(ItemTests):
  14. def setUp(self):
  15. super(VariantItemTests, self).setUp()
  16. self.parent = Item.objects.create(title="Parent product", item_class=self.item_class)
  17. def test_variant_products_dont_need_titles(self):
  18. p = Item.objects.create(parent=self.parent, item_class=self.item_class)
  19. def test_variant_products_dont_need_a_product_class(self):
  20. p = Item.objects.create(parent=self.parent)
  21. def test_variant_products_inherit_parent_titles(self):
  22. p = Item.objects.create(parent=self.parent, item_class=self.item_class)
  23. self.assertEquals("Parent product", p.get_title())
  24. def test_variant_products_inherit_product_class(self):
  25. p = Item.objects.create(parent=self.parent)
  26. self.assertEquals("Clothing", p.get_item_class().name)
  27. class SingleProductViewTest(TestCase):
  28. fixtures = ['sample-products']
  29. def setUp(self):
  30. self.client = Client()
  31. def test_canonical_urls_are_enforced(self):
  32. p = Item.objects.get(id=1)
  33. args = {'item_class_slug': p.get_item_class().slug,
  34. 'item_slug': 'wrong-slug',
  35. 'item_id': p.id}
  36. wrong_url = reverse('oscar-product-item', kwargs=args)
  37. response = self.client.get(wrong_url)
  38. self.assertEquals(301, response.status_code)