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.

test_stockrecord.py 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import unittest.mock as mock
  2. from django.test import TestCase
  3. from oscar.apps.catalogue.models import ProductClass
  4. from oscar.apps.dashboard.catalogue.forms import StockRecordForm
  5. class StockRecordFormTextCase(TestCase):
  6. def test_stockrecord_form_has_all_fields_when_tracking_stock(self):
  7. product_with_stock_tracking = ProductClass()
  8. henk = mock.Mock(is_staff=True)
  9. form = StockRecordForm(product_with_stock_tracking, henk)
  10. form_field_names = [f.name for f in form.visible_fields()]
  11. self.assertIn(
  12. 'num_in_stock', form_field_names,
  13. "num_in_stock should be a field in the form"
  14. )
  15. self.assertIn(
  16. 'low_stock_threshold', form_field_names,
  17. "low_stock_threshold should be a field in the form"
  18. )
  19. def test_stockrecord_form_has_less_fields_when_not_tracking_stock(self):
  20. product_with_no_stock_tracking = ProductClass(track_stock=False)
  21. henk = mock.Mock(is_staff=True)
  22. form = StockRecordForm(product_with_no_stock_tracking, henk)
  23. form_field_names = [f.name for f in form.visible_fields()]
  24. self.assertNotIn(
  25. 'num_in_stock', form_field_names,
  26. "num_in_stock should NOT be a field in the form"
  27. )
  28. self.assertNotIn(
  29. 'low_stock_threshold', form_field_names,
  30. "low_stock_threshold should NOT be a field in the form"
  31. )