Skip to content
Snippets Groups Projects
Commit ce86d35d authored by Alice Heaton's avatar Alice Heaton :speech_balloon:
Browse files

Add tests for AddEditItemForm

parent bdd7fbfc
No related branches found
No related tags found
2 merge requests!37Items can be edited when form is submitted,!36Edit item frontend
from mock import patch
from ..forms.item import AddEditItemForm
def test_form_does_not_have_category_field_if_not_defined():
item_type_category = {
'some-item-type': 'some-taxonomy'
}
with patch.dict('hid.forms.item.ITEM_TYPE_CATEGORY', item_type_category):
form = AddEditItemForm('another-item-type')
assert 'category' not in form.fields
def test_form_does_have_category_field_if_defined():
item_type_category = {
'some-item-type': 'some-taxonomy'
}
with patch.dict('hid.forms.item.ITEM_TYPE_CATEGORY', item_type_category):
with patch('hid.forms.item.transport.terms.list') as term_list:
term_list.return_value = []
form = AddEditItemForm('some-item-type')
assert 'category' in form.fields
def test_form_category_has_expected_choices():
item_type_category = {
'some-item-type': 'some-taxonomy'
}
with patch.dict('hid.forms.item.ITEM_TYPE_CATEGORY', item_type_category):
with patch('hid.forms.item.transport.terms.list') as term_list:
term_list.return_value = [
{
'taxonomy': 'some-taxonomy',
'name': 'name1',
'long_name': 'long name one'
},
{
'taxonomy': 'some-taxonomy',
'name': 'name2',
'long_name': 'long name two'
},
]
expected_choices = [
('', '-----'),
('name1', 'name1'),
('name2', 'name2')
]
form = AddEditItemForm('some-item-type')
assert 'category' in form.fields
assert form.fields['category'].choices == expected_choices
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment