Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update forms.py #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/oscar/apps/dashboard/catalogue/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def __init__(self, product_class, user, *args, **kwargs):

# If not tracking stock, we hide the fields
if not product_class.track_stock:
for field_name in ['num_in_stock', 'low_stock_treshold']:
for field_name in ['num_in_stock', 'low_stock_threshold']:
if field_name in self.fields:
del self.fields[field_name]
else:
Expand Down
Empty file.
38 changes: 38 additions & 0 deletions tests/unit/dashboard/test_stockrecord.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from django.test import TestCase
import unittest.mock as mock
from oscar.apps.dashboard.catalogue.forms import StockRecordForm
from oscar.apps.catalogue.models import ProductClass


class StockRecordFormTextCase(TestCase):
def test_stockrecord_form_has_all_fields_when_tracking_stock(self):
product_with_stock_tracking = ProductClass()
henk = mock.Mock(is_staff=True)

form = StockRecordForm(product_with_stock_tracking, henk)
form_field_names = [f.name for f in form.visible_fields()]

self.assertIn(
'num_in_stock', form_field_names,
"num_in_stock should be a field in the form"
)
self.assertIn(
'low_stock_threshold', form_field_names,
"low_stock_threshold should be a field in the form"
)

def test_stockrecord_form_has_less_fields_when_not_tracking_stock(self):
product_with_no_stock_tracking = ProductClass(track_stock=False)
henk = mock.Mock(is_staff=True)

form = StockRecordForm(product_with_no_stock_tracking, henk)
form_field_names = [f.name for f in form.visible_fields()]

self.assertNotIn(
'num_in_stock', form_field_names,
"num_in_stock should NOT be a field in the form"
)
self.assertNotIn(
'low_stock_threshold', form_field_names,
"low_stock_threshold should NOT be a field in the form"
)