def test_should_save_questionnaire_from_post(self): post = [{"title": "q1", "code": "qc1", "type": "text", "choices": [], "is_entity_question": True, "min_length": 1, "max_length": ""}, {"title": "q2", "code": "qc2", "type": "integer", "choices": [], "is_entity_question": False, "range_min": 0, "range_max": 100}, {"title": "q3", "code": "qc3", "type": "select", "choices": [{"value": "c1"}, {"value": "c2"}], "is_entity_question": False} ] q1 = helper.create_question(post[0], self.dbm) form_model = FormModel(self.dbm, "test", "test", "test", [q1], ["test"], "test") questionnaire = helper.update_questionnaire_with_questions(form_model, post, self.dbm) self.assertEqual(3, len(questionnaire.fields))
def test_should_update_questionnaire(self): dbm = Mock(spec=DatabaseManager) ddtype = Mock(spec=DataDictType) question1 = TextField(label="name", code="na", name="What is your name", language="eng", ddtype=ddtype) question2 = TextField(label="address", code="add", name="What is your address", defaultValue="some default value", language="eng", ddtype=ddtype) post = {"title": "What is your age", "code": "age", "type": "integer", "choices": [], "is_entity_question": False, "range_min": 0, "range_max": 100} form_model = FormModel(dbm, name="test", label="test", form_code="fc", fields=[question1, question2], entity_type=["reporter"], type="survey") form_model2 = helper.update_questionnaire_with_questions(form_model, [post], dbm) self.assertEquals(2, len(form_model2.fields))