Skip to content
Snippets Groups Projects
Commit be7db0fd authored by Piotr Gawron's avatar Piotr Gawron
Browse files

test checking if rendered inital value of the custom field is valid

parent bb264c09
No related branches found
No related tags found
1 merge request!265Resolve "configurable study fields"
Pipeline #34100 failed
......@@ -63,7 +63,7 @@ def create_field_for_custom_study_subject_field(study_subject_field: CustomStudy
required=study_subject_field.obligatory, disabled=study_subject_field.readonly,
widget=forms.DateInput(DATEPICKER_DATE_ATTRS, "%Y-%m-%d"))
elif study_subject_field.type == CUSTOM_FIELD_TYPE_SELECT_LIST:
initial = None
initial = '0'
for v, k in get_custom_select_choices(study_subject_field.possible_values):
if k == val:
initial = v
......
......@@ -5,7 +5,7 @@ from parameterized import parameterized
from web.forms import StudySubjectEditForm
from web.models import StudySubject
from web.models.constants import CUSTOM_FIELD_TYPE_TEXT, CUSTOM_FIELD_TYPE_BOOLEAN, CUSTOM_FIELD_TYPE_INTEGER, \
CUSTOM_FIELD_TYPE_DOUBLE, CUSTOM_FIELD_TYPE_DATE, CUSTOM_FIELD_TYPE_SELECT_LIST
CUSTOM_FIELD_TYPE_DOUBLE, CUSTOM_FIELD_TYPE_DATE, CUSTOM_FIELD_TYPE_SELECT_LIST, CUSTOM_FIELD_TYPE_FILE
from web.models.custom_data import CustomStudySubjectField
from web.models.custom_data.custom_study_subject_field import get_study_subject_field_id
from web.tests import LoggedInWithWorkerTestCase
......@@ -82,6 +82,24 @@ class StudySubjectEditFormTests(LoggedInWithWorkerTestCase):
self.assertEqual(expected_serialized_value, subject.get_custom_data_value(field).value)
@parameterized.expand([
('text', CUSTOM_FIELD_TYPE_TEXT, 'bla', 'bla'),
('bool', CUSTOM_FIELD_TYPE_BOOLEAN, True, 'True'),
('int', CUSTOM_FIELD_TYPE_INTEGER, 10, '10'),
('double', CUSTOM_FIELD_TYPE_DOUBLE, 30.5, '30.5'),
('date', CUSTOM_FIELD_TYPE_DATE, '2020-11-05', '2020-11-05'),
('select list', CUSTOM_FIELD_TYPE_SELECT_LIST, '1', 'BLA', 'BLA;BLA-BLA'),
('select list empty value', CUSTOM_FIELD_TYPE_SELECT_LIST, '0', '', 'BLA;BLA-BLA'),
('file', CUSTOM_FIELD_TYPE_FILE, 'bla.txt', 'bla.txt'),
])
def test_initial_edit_with_custom_field(self, _, field_type, expected_initial_value, value, possible_values=''):
field = CustomStudySubjectField.objects.create(study=get_test_study(), default_value=value,
type=field_type, possible_values=possible_values)
form = StudySubjectEditForm(instance=self.study_subject)
self.assertTrue(form[get_study_subject_field_id(field)].initial, expected_initial_value)
def test_invalid_mpower_id_edit(self):
self.study_subject.mpower_id = "mpower_002"
self.study_subject.nd_number = "ND0002"
......
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