def edit_my_subject(request, entity_type, entity_id, project_id=None): manager = get_database_manager(request.user) subject = get_by_short_code(manager, entity_id, [entity_type.lower()]) subject_request = SubjectWebQuestionnaireRequest(request, project_id) form_model = subject_request.form_model if request.method == 'GET': initialize_values(form_model, subject) return subject_request.response_for_get_request(is_update=True) elif request.method == 'POST': return subject_request.post(is_update=True)
def test_should_set_field_initial_value_as_none_if_not_populated(self): empty_field = TextField(name="text", code="code", label="what is ur name") empty_field.value = None form_model = FormModel(Mock(spec=DatabaseManager)) form_model.add_field(empty_field) mock_subject = Mock(spec=Entity) type(mock_subject).data = PropertyMock(return_value={}) initialize_values(form_model, mock_subject) self.assertEquals(None, empty_field.value)
def test_should_convert_field_value_to_unicode_when_field_value_present( self): empty_field = TextField(name="text", code="code", label="what is ur name") empty_field.value = "FirstName" form_model = FormModel(Mock(spec=DatabaseManager)) form_model.add_field(empty_field) mock_subject = Mock(spec=Entity) type(mock_subject).data = PropertyMock( return_value={"text": { "value": "SomeValue" }}) initialize_values(form_model, mock_subject) self.assertIsInstance(empty_field.value, unicode) self.assertEquals(u"SomeValue", empty_field.value)