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.

product_tests.py 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. from django.core.urlresolvers import reverse
  2. from django_dynamic_fixture import G
  3. from oscar.test import ClientTestCase
  4. from oscar.apps.catalogue.models import ProductClass, Category, Product
  5. class TestGatewayPage(ClientTestCase):
  6. is_staff = True
  7. def test_redirects_to_list_page_when_no_query_param(self):
  8. url = reverse('dashboard:catalogue-product-create')
  9. response = self.client.get(url)
  10. self.assertRedirectUrlName(response,
  11. 'dashboard:catalogue-product-list')
  12. def test_redirects_to_list_page_when_invalid_query_param(self):
  13. url = reverse('dashboard:catalogue-product-create')
  14. response = self.client.get(url + '?product_class=bad')
  15. self.assertRedirectUrlName(response,
  16. 'dashboard:catalogue-product-list')
  17. def test_redirects_to_form_page_when_valid_query_param(self):
  18. pclass = G(ProductClass)
  19. url = reverse('dashboard:catalogue-product-create')
  20. response = self.client.get(url + '?product_class=%d' % pclass.id)
  21. self.assertRedirectUrlName(response,
  22. 'dashboard:catalogue-product-create',
  23. {'product_class_id': pclass.id})
  24. class TestCreateGroupProduct(ClientTestCase):
  25. is_staff = True
  26. def setUp(self):
  27. self.pclass = G(ProductClass)
  28. super(TestCreateGroupProduct, self).setUp()
  29. def submit(self, **params):
  30. data = {'title': 'Nice T-Shirt',
  31. 'productcategory_set-TOTAL_FORMS': '1',
  32. 'productcategory_set-INITIAL_FORMS': '0',
  33. 'productcategory_set-MAX_NUM_FORMS': '',
  34. 'images-TOTAL_FORMS': '2',
  35. 'images-INITIAL_FORMS': '0',
  36. 'images-MAX_NUM_FORMS': '',
  37. }
  38. data.update(params)
  39. url = reverse('dashboard:catalogue-product-create',
  40. kwargs={'product_class_id': self.pclass.id})
  41. return self.client.post(url, data)
  42. def test_title_is_required(self):
  43. response = self.submit(title='')
  44. self.assertIsOk(response)
  45. def test_requires_a_category(self):
  46. response = self.submit()
  47. self.assertIsOk(response)
  48. def test_doesnt_smoke(self):
  49. category = G(Category)
  50. data = {
  51. 'productcategory_set-0-category': category.id,
  52. 'productcategory_set-0-id': '',
  53. 'productcategory_set-0-product': '',
  54. }
  55. response = self.submit(**data)
  56. self.assertRedirectUrlName(response, 'dashboard:catalogue-product-list')
  57. class TestCreateChildProduct(ClientTestCase):
  58. is_staff = True
  59. def setUp(self):
  60. self.pclass = G(ProductClass)
  61. self.parent = G(Product)
  62. super(TestCreateChildProduct, self).setUp()
  63. def submit(self, **params):
  64. data = {'title': 'Nice T-Shirt',
  65. 'productcategory_set-TOTAL_FORMS': '1',
  66. 'productcategory_set-INITIAL_FORMS': '0',
  67. 'productcategory_set-MAX_NUM_FORMS': '',
  68. 'images-TOTAL_FORMS': '2',
  69. 'images-INITIAL_FORMS': '0',
  70. 'images-MAX_NUM_FORMS': '',
  71. }
  72. data.update(params)
  73. url = reverse('dashboard:catalogue-product-create',
  74. kwargs={'product_class_id': self.pclass.id})
  75. return self.client.post(url, data)
  76. def test_categories_are_not_required(self):
  77. category = G(Category)
  78. data = {
  79. 'parent': self.parent.id,
  80. 'productcategory_set-0-category': category.id,
  81. 'productcategory_set-0-id': '',
  82. 'productcategory_set-0-product': '',
  83. }
  84. response = self.submit(**data)
  85. self.assertIsOk(response)