예제 #1
0
 def test_should_add_constraint_text_for_numeric_field_without_constraint(
         self):
     field = IntegerField(
         name="What's in the age?",
         code="nam",
         label="naam",
     )
     preview = helper.get_preview_for_field(field)
     self.assertEqual("", preview["constraints"])
예제 #2
0
 def test_should_add_constraint_text_for_numeric_field_with_min(self):
     constraint = NumericRangeConstraint(min=10)
     field = IntegerField(name="What's in the age?",
                          code="nam",
                          label="naam",
                          constraints=[constraint])
     preview = helper.get_preview_for_field(field)
     self.assertEqual("Minimum 10", preview["constraints"])
     self.assertEqual("integer", preview["type"])
예제 #3
0
 def test_should_add_constraint_text_for_numeric_field_without_constraint(
         self):
     type = DataDictType(Mock(DatabaseManager), name="age type")
     field = IntegerField(name="What's in the age?",
                          code="nam",
                          label="naam",
                          ddtype=type)
     preview = helper.get_preview_for_field(field)
     self.assertEqual("", preview["constraints"])
예제 #4
0
    def test_should_get_header_information_for_submission_excel(self):
        fields = [{
            "name": "first name",
            "code": 'q1',
            "label": 'What is your name',
            "type": "text"
        }, {
            "name": "age",
            "code": 'q2',
            "label": 'What is your age',
            "type": "integer",
            "constraints": [["range", {
                "max": "15",
                "min": "12"
            }]]
        }, {
            "name": "reporting date",
            "code": 'q3',
            "label": 'What is the reporting date',
            "date_format": "dd.mm.yyyy",
            "type": "date"
        }, {
            "name": "choices",
            "code": 'q5',
            "label": 'Your choices',
            "type": "select"
        }]
        form_model_fields = [
            TextField("first_name", "q1", "What is your name"),
            IntegerField("age", "q2", "What is your age"),
            DateField("reporting date", "q3", "What is the reporting date",
                      "dd.mm.yyyy")
        ]
        form_model = FormModel(Mock(spec=DatabaseManager),
                               name="some_name",
                               form_code="cli00_mp",
                               fields=form_model_fields)

        headers = get_submission_headers(fields, form_model)

        headers_text = self._get_header_component(headers, 0)
        self.assertEqual([
            "What is your name", "What is your age",
            "What is the reporting date", "Your choices"
        ], headers_text)

        header_instructions = self._get_header_component(headers, 1)
        self.assertEqual([
            "\n\nAnswer must be a word", "\n\nEnter a number between 12-15.",
            "\n\nAnswer must be a date in the following format: day.month.year",
            "\n\nEnter 1 or more answers from the list."
        ], header_instructions)

        header_examples = self._get_header_component(headers, 2)
        self.assertEqual([
            "\n\n", "\n\n", "\n\nExample: 25.12.2011", "\n\nExample: a or ab"
        ], header_examples)
예제 #5
0
 def test_should_return_error_for_wrong_type_for_integer(self):
     with self.assertRaises(AnswerWrongType) as e:
         field = IntegerField(
             name="Age",
             code="Q2",
             label="What is your age",
             constraints=[NumericRangeConstraint(min=15, max=120)])
         field.validate("asas")
     self.assertEqual(e.exception.message,
                      "Answer asas for question Q2 is of the wrong type.")
예제 #6
0
 def test_should_return_error_for_integer_range_validation(self):
     field = IntegerField(
         name="Age",
         code="Q2",
         label="What is your age",
         constraints=[NumericRangeConstraint(min=15, max=120)])
     valid_value = field.validate("120")
     self.assertEqual(valid_value, 120)
     valid_value = field.validate("25.5")
     self.assertEqual(valid_value, 25.5)
예제 #7
0
 def setUp(self):
     self.field1 = TextField('text', 'q1', 'Enter Text')
     self.field2 = IntegerField('integer', 'q2', 'Enter a Number')
     self.field3 = UniqueIdField('clinic', 'unique_id_field', 'q3', 'Which clinic are you reporting on')
     self.field4 = UniqueIdField('school', 'unique_id_field2', 'q4', 'Which school are you reporting on')
     self.repeat_field = FieldSet('repeat','repeat', 'repeat label', field_set=[self.field1, self.field4])
     self.form_model = MagicMock(spec=Project)
     self.form_model.id = 'form_model_id'
     self.patch_get_entity_type_info = patch('datawinners.entity.import_data.get_entity_type_info')
     self.get_entity_type_info_mock = self.patch_get_entity_type_info.start()
    def test_question_code_case_mismatch_gives_right_value(self):
        value_mock = PropertyMock(return_value={'Q4': '23'})
        type(self.survey_response).values = value_mock
        number_field = IntegerField('name', 'q4', 'age')

        builder = EnrichedSurveyResponseBuilder(None, self.survey_response, self.form_model, {})
        dictionary = builder._create_answer_dictionary(number_field)
        self.assertEquals('23', dictionary.get('answer'))
        self.assertEquals('age', dictionary.get('label'))
        self.assertEquals('integer', dictionary.get('type'))
예제 #9
0
 def test_should_add_constraint_text_for_numeric_field_with_max(self):
     type = DataDictType(Mock(DatabaseManager), name="age type")
     constraint = NumericRangeConstraint(max=100)
     field = IntegerField(name="What's in the age?",
                          code="nam",
                          label="naam",
                          ddtype=type,
                          constraints=[constraint])
     preview = helper.get_preview_for_field(field)
     self.assertEqual("Upto 100", preview["constraints"])
    def setUp(self):
        self.dbm = Mock(spec=DatabaseManager)
        self.datadict_patcher = patch(
            "mangrove.form_model.form_model.get_or_create_data_dict")
        self.datadict_mock = self.datadict_patcher.start()
        self.ddtype_mock = Mock(spec=DataDictType)
        self.datadict_mock.return_value = self.ddtype_mock

        q1 = TextField(name="entity_question",
                       code="ID",
                       label="What is associated entity",
                       language="eng",
                       entity_question_flag=True,
                       ddtype=self.ddtype_mock)
        q2 = TextField(name="question1_Name",
                       code="Q1",
                       label="What is your name",
                       defaultValue="some default value",
                       language="eng",
                       length=TextConstraint(5, 10),
                       ddtype=self.ddtype_mock)
        q3 = IntegerField(name="Father's age",
                          code="Q2",
                          label="What is your Father's Age",
                          range=NumericConstraint(min=15, max=120),
                          ddtype=self.ddtype_mock)
        q4 = SelectField(name="Color",
                         code="Q3",
                         label="What is your favourite color",
                         options=[("RED", 1), ("YELLOW", 2)],
                         ddtype=self.ddtype_mock)
        q5 = TextField(name="Desc",
                       code="Q4",
                       label="Description",
                       ddtype=self.ddtype_mock)

        self.form_model = FormModel(
            self.dbm,
            entity_type=["XYZ"],
            name="aids",
            label="Aids form_model",
            form_code="1",
            type='survey',
            fields=[  #        expected_short_code = "dog3"
                #        self.assertEqual(response.short_code, expected_short_code)
                #        b = get_by_short_code(self.dbm, expected_short_code, ["dog"])
                #        self.assertEqual(b.short_code, expected_short_code)
                q1,
                q2,
                q3,
                q4,
                q5
            ])
    def test_convert_survey_response_values_to_dict_format(self):
        survey_response_doc = SurveyResponseDocument(
            values={
                'q1': '23',
                'q2': 'sometext',
                'q3': 'a',
                'geo': '2.34,5.64',
                'date': '12.12.2012'
            })
        survey_response = SurveyResponse(Mock())
        survey_response._doc = survey_response_doc
        int_field = IntegerField(name='question one',
                                 code='q1',
                                 label='question one',
                                 ddtype=Mock(spec=DataDictType))
        text_field = TextField(name='question two',
                               code='q2',
                               label='question two',
                               ddtype=Mock(spec=DataDictType))
        single_choice_field = SelectField(name='question three',
                                          code='q3',
                                          label='question three',
                                          options=[("one", "a"), ("two", "b"),
                                                   ("three", "c"),
                                                   ("four", "d")],
                                          single_select_flag=True,
                                          ddtype=Mock(spec=DataDictType))
        geo_field = GeoCodeField(name='geo',
                                 code='GEO',
                                 label='geo',
                                 ddtype=Mock())
        date_field = DateField(name='date',
                               code='DATE',
                               label='date',
                               date_format='dd.mm.yyyy',
                               ddtype=Mock())
        questionnaire_form_model = Mock(spec=FormModel)
        questionnaire_form_model.form_code = 'test_form_code'
        questionnaire_form_model.fields = [
            int_field, text_field, single_choice_field, geo_field, date_field
        ]

        request_dict = construct_request_dict(survey_response,
                                              questionnaire_form_model)
        expected_dict = OrderedDict({
            'q1': '23',
            'q2': 'sometext',
            'q3': 'a',
            'GEO': '2.34,5.64',
            'DATE': '12.12.2012',
            'form_code': 'test_form_code'
        })
        self.assertEqual(expected_dict, request_dict)
예제 #12
0
    def test_integer_field_for_min_number(self):
        int_field = IntegerField(
            "age",
            'age',
            'age',
            constraints=[NumericRangeConstraint(min='100')])

        field = FormField().create(int_field)
        self.assertTrue(isinstance(field.widget, TextInputForFloat))
        self.assertEquals(field.widget.attrs['watermark'], 'Minimum 100')
        self.assertEqual(field.min_value, 100)
        self.assertEqual(field.max_value, None)
예제 #13
0
 def test_should_return_error_for_integer_range_validation_for_min_value(
         self):
     with self.assertRaises(AnswerTooSmallException) as e:
         field = IntegerField(
             name="Age",
             code="Q2",
             label="What is your age",
             constraints=[NumericRangeConstraint(min=15, max=120)])
         valid_value = field.validate(11)
         self.assertFalse(valid_value)
     self.assertEqual(e.exception.message,
                      "Answer 11 for question Q2 is smaller than allowed.")
예제 #14
0
 def setUp(self):
     self.field1 = TextField('text', 'q1', 'Enter Text')
     self.field2 = IntegerField('integer', 'q2', 'Enter a Number')
     self.field3 = UniqueIdField('clinic', 'unique_id_field', 'q3',
                                 'Which clinic are you reporting on')
     self.field4 = UniqueIdField('school', 'unique_id_field2', 'q4',
                                 'Which school are you reporting on')
     self.repeat_field = FieldSet('repeat',
                                  'repeat',
                                  'repeat label',
                                  field_set=[self.field1, self.field4])
     self.form_model = MagicMock(spec=Project)
     self.form_model.id = 'form_model_id'
예제 #15
0
 def test_should_return_error_for_integer_range_validation_for_max_value(
         self):
     with self.assertRaises(AnswerTooBigException) as e:
         field = IntegerField(name="Age",
                              code="Q2",
                              label="What is your age",
                              language="eng",
                              range=NumericConstraint(min=15, max=120),
                              ddtype=self.ddtype)
         valid_value = field.validate(150)
         self.assertFalse(valid_value)
     self.assertEqual(
         e.exception.message,
         "Answer 150 for question Q2 is greater than allowed.")
예제 #16
0
    def test_should_save_submitted_sms_for_activity_report(self):
        question1 = TextField(name="entity_question",
                              code="EID",
                              label="What is associated entity",
                              language="eng",
                              entity_question_flag=True,
                              ddtype=self.entity_id_type)
        question2 = TextField(name="Name",
                              code="NAME",
                              label="Clinic Name",
                              defaultValue="some default value",
                              language="eng",
                              length=TextConstraint(4, 15),
                              ddtype=self.name_type)
        question3 = IntegerField(name="Arv stock",
                                 code="ARV",
                                 label="ARV Stock",
                                 range=NumericConstraint(min=15, max=120),
                                 ddtype=self.stock_type)
        activity_report = FormModel(self.dbm,
                                    entity_type=["reporter"],
                                    name="report",
                                    label="reporting form_model",
                                    form_code="acp",
                                    type='survey',
                                    fields=[question1, question2, question3])
        activity_report.save()

        text = "acp +name tester +ARV 50 "

        response = self.send_sms(text)

        self.assertTrue(response.success)
        self.assertEqual(u"Test_reporter",
                         response.reporters[0].get(NAME_FIELD))

        data_record_id = response.datarecord_id
        data_record = self.dbm._load_document(
            id=data_record_id, document_class=DataRecordDocument)
        self.assertEqual(self.name_type.slug,
                         data_record.data["Name"]["type"]["slug"])
        self.assertEqual(self.stock_type.slug,
                         data_record.data["Arv stock"]["type"]["slug"])
        self.assertEqual("acp", data_record.submission['form_code'])
        data = self.reporter.values({"Name": "latest", "Arv stock": "latest"})
        self.assertEquals(data["Arv stock"], 50)
        self.assertEquals(data["Name"], "tester")
        submission_log = self.dbm._load_document(response.submission_id,
                                                 SubmissionLogDocument)
        self.assertEquals(data_record_id, submission_log.data_record_id)
예제 #17
0
def _create_integer_question(post_dict, ddtype):
    max_range_from_post = post_dict.get("range_max")
    min_range_from_post = post_dict.get("range_min")
    max_range = max_range_from_post if not is_empty(
        max_range_from_post) else None
    min_range = min_range_from_post if not is_empty(
        min_range_from_post) else None
    range = NumericConstraint(min=min_range, max=max_range)
    return IntegerField(name=post_dict["title"],
                        code=post_dict["code"].strip(),
                        label="default",
                        range=range,
                        ddtype=ddtype,
                        instruction=post_dict.get("instruction"))
예제 #18
0
 def _create_integer_question(self, post_dict, code):
     max_range_from_post = post_dict.get("range_max")
     min_range_from_post = post_dict.get("range_min")
     max_range = max_range_from_post if not is_empty(max_range_from_post) else None
     min_range = min_range_from_post if not is_empty(min_range_from_post) else None
     range = NumericRangeConstraint(min=min_range, max=max_range)
     return IntegerField(name=self._get_name(post_dict, code), code=code, label=post_dict["title"],
                         constraints=[range], instruction=post_dict.get("instruction"),
                         required=post_dict.get("required"), parent_field_code=post_dict.get('parent_field_code'),
                         hint=post_dict.get('hint'), constraint_message=post_dict.get('constraint_message'),
                         appearance=post_dict.get('appearance'),
                         default=post_dict.get('default'),
                         xform_constraint=post_dict.get('xform_constraint'),
                         relevant=post_dict.get('relevant'))
예제 #19
0
 def _create_integer_question(self, post_dict, code):
     max_range_from_post = post_dict.get("range_max")
     min_range_from_post = post_dict.get("range_min")
     max_range = max_range_from_post if not is_empty(
         max_range_from_post) else None
     min_range = min_range_from_post if not is_empty(
         min_range_from_post) else None
     range = NumericRangeConstraint(min=min_range, max=max_range)
     return IntegerField(name=self._get_name(post_dict),
                         code=code,
                         label=post_dict["title"],
                         constraints=[range],
                         instruction=post_dict.get("instruction"),
                         required=post_dict.get("required"))
예제 #20
0
 def test_should_create_type_list(self):
     ddtype = Mock(spec=DataDictType)
     question1 = IntegerField(label="number_question", code="ID", name="How many beds",
                              language="eng", ddtype=ddtype)
     question2 = TextField(label="question1_Name", code="Q1", name="What is your name",
                           defaultValue="some default value", language="eng", ddtype=ddtype)
     question3 = SelectField(label="multiple_choice_question", code="Q2",
                             options=[("red", 1), ("yellow", 2), ('green', 3)], name="What is your favourite colour",
                             ddtype=ddtype)
     question4 = DateField("What is date", "Q4", "date_question", "mm.yyyy", ddtype)
     actual_list = helper.get_type_list([question1, question2, question3, question4])
     choice_type = copy(helper.MULTI_CHOICE_TYPE_OPTIONS)
     expected_list = [helper.NUMBER_TYPE_OPTIONS, helper.TEXT_TYPE_OPTIONS, choice_type, helper.DATE_TYPE_OPTIONS]
     self.assertListEqual(expected_list, actual_list)
예제 #21
0
    def test_integer_field_for_max_number(self):
        int_field = IntegerField(
            "age",
            'age',
            'age',
            "Answer must be a number. The maximum is 100.",
            constraints=[NumericRangeConstraint(max='100')])

        field = FormField().create(int_field)
        self.assertTrue(isinstance(field.widget, TextInputForFloat))
        self.assertEquals(field.widget.attrs['watermark'], 'Upto 100')
        self.assertEqual(field.max_value, 100)
        self.assertEqual(field.min_value, None)
        self.assertEqual(field.help_text,
                         "Answer must be a number. The maximum is 100.")
예제 #22
0
 def test_should_return_none_if_survey_response_questionnaire_is_different_from_form_model(self):
     survey_response_doc = SurveyResponseDocument(values={'q5': '23', 'q6': 'sometext', 'q7': 'ab'})
     survey_response = SurveyResponse(Mock())
     survey_response._doc = survey_response_doc
     int_field = IntegerField(name='question one', code='q1', label='question one')
     text_field = TextField(name='question two', code='q2', label='question two')
     choice_field = SelectField(name='question three', code='Q3', label='question three',
                                options=[("one", "a"), ("two", "b"), ("three", "c"), ("four", "d")],
                                single_select_flag=False)
     questionnaire_form_model = Mock(spec=FormModel)
     questionnaire_form_model.form_code = 'test_form_code'
     questionnaire_form_model.fields = [int_field, text_field, choice_field]
     result_dict = construct_request_dict(survey_response, questionnaire_form_model, 'id')
     expected_dict = {'q1': None, 'q2': None, 'Q3': None, 'form_code': 'test_form_code', 'dsid': 'id'}
     self.assertEqual(expected_dict, result_dict)
예제 #23
0
 def _create_sample_questionnaire(self):
     entity_type = []
     question3 = IntegerField(
         name="Father's age",
         code="Q2",
         label="What is your Father's Age",
         constraints=[NumericRangeConstraint(min=15, max=120)])
     form_model = FormModel(self.manager,
                            name='New survey',
                            label='Survey122',
                            form_code='S122',
                            fields=[question3],
                            is_registration_model=False)
     form_model_id = form_model.save()
     return form_model_id
예제 #24
0
    def setUp(self):
        self.dbm = Mock(spec=DatabaseManager)

        q1 = UniqueIdField('clinic',
                           name="entity_question",
                           code="ID",
                           label="What is associated entity")
        q2 = TextField(name="question1_Name",
                       code="Q1",
                       label="What is your name",
                       defaultValue="some default value",
                       constraints=[TextLengthConstraint(5, 10)],
                       required=False)
        q3 = IntegerField(
            name="Father's age",
            code="Q2",
            label="What is your Father's Age",
            constraints=[NumericRangeConstraint(min=15, max=120)],
            required=False)
        q4 = SelectField(name="Color",
                         code="Q3",
                         label="What is your favourite color",
                         options=[("RED", 'a'), ("YELLOW", 'b')],
                         required=False)
        q5 = TextField(name="Desc",
                       code="Q4",
                       label="Description",
                       required=False)
        self.event_time_field_code = "Q6"
        q6 = DateField(name="Event time",
                       code=self.event_time_field_code,
                       label="Event time field",
                       date_format="%m.%d.%Y",
                       required=False)
        q7 = GeoCodeField(name="My Location",
                          code="loc",
                          label="Geo Location Field",
                          required=False)
        self.form_model = FormModel(self.dbm,
                                    name="aids",
                                    label="Aids form_model",
                                    form_code="1",
                                    fields=[q1, q2, q3, q4, q5, q6, q7])

        self.form_model_patch = patch(
            'mangrove.form_model.form_model.FormModel')
        self.form_model_document_patch = patch(
            'mangrove.form_model.form_model.FormModelDocument')
 def form_model(self):
     question1 = UniqueIdField(
         unique_id_type='clinic',
         name="entity_question",
         code="q1",
         label="What is associated entity",
     )
     question2 = IntegerField(
         name="question1_Name",
         code="q2",
         label="What is your name",
         constraints=[NumericRangeConstraint(min=10, max=100)])
     return FormModel(self.dbm,
                      name="aids",
                      label="Aids form_model",
                      form_code="aids",
                      fields=[question1, question2])
예제 #26
0
    def test_should_create_submission_form_with_appropriate_fields(self):
        fields = [
            IntegerField('field_name', 'integer_field_code', 'label', Mock),
            DateField('Date', 'date_field_code', 'date_label', 'dd.mm.yyyy',
                      Mock),
            GeoCodeField('', 'geo_field_code', '', Mock),
            TextField('', 'text_field_code', '')
        ]
        type(self.project).fields = PropertyMock(return_value=fields)

        submission_form_create = SurveyResponseForm(self.project, {})
        expected_field_keys = [
            'form_code', 'dsid', 'integer_field_code', 'date_field_code',
            'geo_field_code', 'text_field_code'
        ]
        self.assertListEqual(submission_form_create.fields.keys(),
                             expected_field_keys)
예제 #27
0
    def _create_form_model(self, form_code):
        try:
            form = get_form_model_by_code(self.manager, form_code)
            if form:
                form.delete()
        except FormModelDoesNotExistsException:
            pass
        question1 = UniqueIdField(unique_id_type='clinic',name="entity_question", code="ID", label="What is associated entity")
        question2 = TextField(name="question1_Name", code="Q1", label="What is your name",
                              defaultValue="some default value")
        question3 = IntegerField(name="Father's age", code="Q2", label="What is your Father's Age")
        question4 = SelectField(name="Color", code="Q3", label="What is your favourite color",
                                options=[("RED", 'a'), ("YELLOW", 'b')])

        self.form_model = FormModel(self.manager, name="aids", label="Aids form_model",
                                    form_code=form_code, fields=[
                question1, question2, question3, question4])
        self.form_model__id = self.form_model.save()
예제 #28
0
    def test_should_get_header_information_for_submission_excel_with_multiple_unique_id_questions(self):
        fields = [{"name": "first name", "code": 'q1', "label": 'What is your name',
                   "type": "text"},
                  {"name": "age", "code": 'q2', "label": 'What is your age', "type": "integer", "constraints": [
                      [
                          "range",
                          {
                              "max": "15",
                              "min": "12"
                          }
                      ]
                  ]},
                  {"name": "reporting date", "code": 'q3', "label": 'What is the reporting date',
                   "date_format": "dd.mm.yyyy", "type": "date"},
                  {"name": "choices", "code": 'q5', "label": 'Your choices', "type": "select"},
                  {"name": "What game are you reporting on?", "code": 'q6', "label": 'What game are you reporting on?',
                    "unique_id_type": "game", "type": "unique_id"},
                  {"name": "What waterpoint are you reporting on?", "code": 'q7', "label": 'What waterpoint are you reporting on?',
                    "unique_id_type": "waterpoint", "type": "unique_id"}]
        form_model_fields = [TextField("first_name","q1","What is your name"),
                             IntegerField("age","q2","What is your age"),
                             DateField("reporting date","q3","What is the reporting date","dd.mm.yyyy"),
                             UniqueIdField("game","What game are you reporting on?","q6","What game are you reporting on?"),
                             UniqueIdField("waterpoint","What waterpoint are you reporting on?","q7","What waterpoint are you reporting on?")]
        form_model = FormModel(Mock(spec=DatabaseManager), name="some_name", form_code="cli00_mp", fields=form_model_fields)

        headers = get_submission_headers(fields, form_model)

        headers_text = self._get_header_component(headers, 0)
        self.assertEqual(
            ["What is your name", "What is your age", "What is the reporting date",
             "Your choices", "What game are you reporting on?", "What waterpoint are you reporting on?"], headers_text)

        header_instructions = self._get_header_component(headers, 1)
        self.assertEqual(
            ["\n\nAnswer must be a word", "\n\nEnter a number between 12-15.",
             "\n\nAnswer must be a date in the following format: day.month.year",
             "\n\nEnter 1 or more answers from the list.", '\n\nEnter the unique ID for each game.\nYou can find the game List on the My Identification Numbers page.',
             '\n\nEnter the unique ID for each waterpoint.\nYou can find the waterpoint List on the My Identification Numbers page.'], header_instructions)

        header_examples = self._get_header_component(headers, 2)
        self.assertEqual(
            ["\n\n", "\n\n", "\n\nExample: 25.12.2011",
             "\n\nExample: a or ab", "\n\nExample: cli01", "\n\nExample: cli01"], header_examples)
예제 #29
0
    def test_should_accept_submission_with_repeat_fields(self):
        submission_data = u'''
        <hindimai-055>
            <familyname>singh</familyname>
            <family>
                <name>नाम asd</name>
                <age>12</age>
            </family>
            <family>
                <name>tommy</name>
                <age>15</age>
            </family>
            <form_code>055</form_code>
        </hindimai-055>
        '''
        expected_values = {
            'familyname':
            'singh',
            'family': [{
                'name': u'नाम asd',
                'age': '12'
            }, {
                'name': 'tommy',
                'age': '15'
            }]
        }
        with patch("mangrove.transport.player.parser.get_form_model_by_code"
                   ) as mock_get_form_model:
            mock_form_model = Mock()
            mock_form_model.fields = [
                TextField('', 'familyname', ''),
                FieldSet('',
                         'family',
                         '',
                         field_set=[
                             TextField('', 'name', ''),
                             IntegerField('', 'age', '')
                         ])
            ]
            mock_get_form_model.return_value = mock_form_model

            self.assertEquals(self.parser.parse(submission_data),
                              ('055', expected_values))
    def create_test_fields_and_survey_for_all_fields_type(self):
        name = TextField('name', 'name' ,'What is your name?')
        degree = TextField('degree', 'degree' ,'Degree name')
        completed_on = DateField('completed_on', 'completed_on','Degree completion year', 'dd.mm.yyyy')
        education = FieldSet('education', 'education', 'Education', field_set=[degree,completed_on])
        age = IntegerField('age', 'age' ,'What is your age?')
        opt_fav_col = [('red','Red'), ('blue','Blue'),('c','Green')]
        fav_col = SelectField('fav_color', 'fav_color', 'Which colors you like?', opt_fav_col)
        opt_pizza_col = [('yes', 'Yes'),('no','No')]
        pizza_fan = SelectField('pizza_fan', 'pizza_fan', 'Do you like pizza?', opt_pizza_col)
        other = TextField('other', 'other' ,'What else you like?')
        pizza_type = TextField('pizza_type', 'pizza_type' ,'Which pizza type you like?')
        location = GeoCodeField('location', 'location' ,'Your location?')

        form_fields = [name, education, age, fav_col, pizza_fan, other, pizza_type, location]

        # todo how required will be handled
        survey_response_values = {'name': 'Santa', 'pizza_type': None, 'age': '30', 'other': 'Samosa', 'location': '4.9158,11.9531', 'education': [{'completed_on': u'10.02.2014', 'degree': 'SantaSSC'}], 'pizza_fan': 'yes', 'fav_color': 'red blue'}
        return form_fields, survey_response_values