def test_specify_other(self): survey = utils.create_survey_from_fixture("specify_other", filetype=FIXTURE_FILETYPE) expected_dict = { u'name': 'specify_other', u'type': u'survey', u'children': [ { u'name': u'sex', u'label': {u'English': u'What sex are you?'}, u'type': u'select one', u'children': [ { u'name': u'male', u'label': {u'English': u'Male'} }, { u'name': u'female', u'label': {u'English': u'Female'} }, { u'name': u'other', u'label': u'Other' } ] }, { u'name': u'sex_other', u'bind': {u'relevant': u"selected(../sex, 'other')"}, u'label': u'Specify other.', u'type': u'text'} ] } self.assertEqual(survey.to_dict(), expected_dict)
def test_select_one_question_with_identical_choice_name(self): """ testing to make sure that select ones whose choice names are the same as the name of the select one get compiled. """ survey = utils.create_survey_from_fixture("choice_name_same_as_select_name", filetype=FIXTURE_FILETYPE) expected_dict = { u'name': u'choice_name_same_as_select_name', u'title': u'choice_name_same_as_select_name', u'default_language': u'default', u'id_string': u'choice_name_same_as_select_name', u'type': u'survey', u'children': [ { u'children': [ { u'name': u'zone', u'label': u'Zone' } ], u'type': u'select one', u'name': u'zone', u'label': u'Zone' } ] } self.maxDiff = None self.assertEqual(survey.to_json_dict(), expected_dict)
def test_include(self): survey = utils.create_survey_from_fixture("include", filetype=FIXTURE_FILETYPE, include_directory=True) expected_dict = { u'name': 'include', u'type': u'survey', u'children': [ { u'name': u'name', u'label': {u'English': u"What's your name?"}, u'type': u'text' }, { u'name': u'good_day', u'label': {u'english': u'have you had a good day today?'}, u'type': u'select one', u'children': [ { u'name': u'yes', u'label': {u'english': u'yes'} }, { u'name': u'no', u'label': {u'english': u'no'} } ]}]} self.assertEqual(survey.to_dict(), expected_dict)
def test_select_one_question_with_identical_choice_name(self): """ testing to make sure that select ones whose choice names are the same as the name of the select one get compiled. """ survey = utils.create_survey_from_fixture( "choice_name_same_as_select_name", filetype=FIXTURE_FILETYPE) expected_dict = { u'name': u'choice_name_same_as_select_name', u'title': u'choice_name_same_as_select_name', u'default_language': u'default', u'id_string': u'choice_name_same_as_select_name', u'type': u'survey', u'children': [{ u'children': [{ u'name': u'zone', u'label': u'Zone' }], u'type': u'select one', u'name': u'zone', u'label': u'Zone' }] } self.maxDiff = None self.assertEqual(survey.to_json_dict(), expected_dict)
def test_specify_other(self): survey = utils.create_survey_from_fixture("specify_other", filetype=FIXTURE_FILETYPE) expected_dict = { u'name': u'specify_other', u'type': u'survey', u'title': u'specify_other', u'default_language': u'default', u'id_string': u'specify_other', u'sms_keyword': u'specify_other', u'children': [ { u'name': u'sex', u'label': {u'English': u'What sex are you?'}, u'type': u'select one', u'children': [ # TODO Change to choices (there is stuff in the # json2xform half that will need to change) { u'name': u'male', u'label': {u'English': u'Male'} }, { u'name': u'female', u'label': {u'English': u'Female'} }, { u'name': u'other', u'label': u'Other' } ] }, { u'name': u'sex_other', u'bind': {u'relevant': u"selected(../sex, 'other')"}, u'label': u'Specify other.', u'type': u'text'}, { u'children': [ { u'bind': { 'calculate': "concat('uuid:', uuid())", 'readonly': 'true()' }, u'name': 'instanceID', u'type': 'calculate' } ], u'control': { 'bodyless': True }, u'name': 'meta', u'type': u'group' } ] } self.maxDiff = None self.assertEqual(survey.to_json_dict(), expected_dict)
def test_specify_other(self): survey = utils.create_survey_from_fixture("specify_other", filetype=FIXTURE_FILETYPE) expected_dict = { u'name': u'specify_other', u'type': u'survey', u'title': u'specify_other', u'default_language': u'default', u'id_string': u'specify_other', u'children': [ { u'name': u'sex', u'label': { u'English': u'What sex are you?' }, u'type': u'select one', u'children': [ #TODO Change to choices (there is stuff in the json2xform half that will need to change) { u'name': u'male', u'label': { u'English': u'Male' } }, { u'name': u'female', u'label': { u'English': u'Female' } }, { u'name': u'other', u'label': u'Other' } ] }, { u'name': u'sex_other', u'bind': { u'relevant': u"selected(../sex, 'other')" }, u'label': u'Specify other.', u'type': u'text' } ] } self.maxDiff = None #import json #print json.dumps(survey, indent=4, ensure_ascii=False) self.assertEqual(survey.to_json_dict(), expected_dict)
def test_style_added_to_body_if_present(self): survey = utils.create_survey_from_fixture( "style_settings", filetype=FIXTURE_FILETYPE) xml = survey.to_xml() # find the body tag root_elm = etree.fromstring(xml) body_elms = filter( lambda e: self.STRIP_NS_FROM_TAG_RE.sub('', e.tag) == 'body', [c for c in root_elm.getchildren()]) self.assertEqual(len(body_elms), 1) self.assertEqual(body_elms[0].get('class'), 'ltr')
def test_style_added_to_body_if_present(self): survey = utils.create_survey_from_fixture("style_settings", filetype=FIXTURE_FILETYPE) xml = survey.to_xml() # find the body tag root_elm = etree.fromstring(xml) body_elms = filter( lambda e: self.STRIP_NS_FROM_TAG_RE.sub('', e.tag) == 'body', [c for c in root_elm.getchildren()]) self.assertEqual(len(body_elms), 1) self.assertEqual(body_elms[0].get('class'), 'ltr')
def test_style_column(self): survey = utils.create_survey_from_fixture("style_settings", filetype=FIXTURE_FILETYPE) expected_dict = { u'children': [{ u'label': { u'english': u'What is your name?' }, u'name': u'your_name', u'type': u'text' }, { u'label': { u'english': u'How many years old are you?' }, u'name': u'your_age', u'type': u'integer' }, { u'children': [{ u'bind': { 'calculate': "concat('uuid:', uuid())", 'readonly': 'true()' }, u'name': 'instanceID', u'type': 'calculate' }], u'control': { 'bodyless': True }, u'name': 'meta', u'type': u'group' }], u'default_language': u'default', u'id_string': u'new_id', u'name': u'style_settings', u'sms_keyword': u'new_id', u'style': u'ltr', u'title': u'My Survey', u'type': u'survey', } self.assertEqual(survey.to_json_dict(), expected_dict)
def test_select_one_question_with_identical_choice_name(self): """ testing to make sure that select ones whose choice names are the same as the name of the select one get compiled. """ survey = utils.create_survey_from_fixture( "choice_name_same_as_select_name", filetype=FIXTURE_FILETYPE) expected_dict = { u'name': u'choice_name_same_as_select_name', u'title': u'choice_name_same_as_select_name', u'sms_keyword': u'choice_name_same_as_select_name', u'default_language': u'default', u'id_string': u'choice_name_same_as_select_name', u'type': u'survey', u'children': [{ u'children': [{ u'name': u'zone', u'label': u'Zone' }], u'type': u'select one', u'name': u'zone', u'label': u'Zone', }, { u'children': [{ u'bind': { 'calculate': "concat('uuid:', uuid())", 'readonly': 'true()' }, u'name': 'instanceID', u'type': 'calculate' }], u'control': { 'bodyless': True }, u'name': 'meta', u'type': u'group' }] } self.maxDiff = None self.assertEqual(survey.to_json_dict(), expected_dict)
def test_select_one_question_with_identical_choice_name(self): """ testing to make sure that select ones whose choice names are the same as the name of the select one get compiled. """ survey = utils.create_survey_from_fixture( "choice_name_same_as_select_name", filetype=FIXTURE_FILETYPE) expected_dict = { u'name': u'choice_name_same_as_select_name', u'title': u'choice_name_same_as_select_name', u'sms_keyword': u'choice_name_same_as_select_name', u'default_language': u'default', u'id_string': u'choice_name_same_as_select_name', u'type': u'survey', u'children': [ { u'children': [ { u'name': u'zone', u'label': u'Zone' } ], u'type': u'select one', u'name': u'zone', u'label': u'Zone', }, {u'children': [ { u'bind': { 'calculate': "concat('uuid:', uuid())", 'readonly': 'true()' }, u'name': 'instanceID', u'type': 'calculate' } ], u'control': { 'bodyless': True }, u'name': 'meta', u'type': u'group' } ] } self.maxDiff = None self.assertEqual(survey.to_json_dict(), expected_dict)
def test_include(self): survey = utils.create_survey_from_fixture(u"include", filetype=FIXTURE_FILETYPE, include_directory=True) expected_dict = { u'name': u'include', u'title': u'include', u'id_string': u'include', u'default_language': u'default', u'type': u'survey', u'children': [{ u'name': u'name', u'label': { u'English': u"What's your name?" }, u'type': u'text' }, { u'name': u'good_day', u'label': { u'english': u'have you had a good day today?' }, u'type': u'select one', u'children': [{ u'name': u'yes', u'label': { u'english': u'yes' } }, { u'name': u'no', u'label': { u'english': u'no' } }] }] } self.assertEqual(survey.to_json_dict(), expected_dict)
def test_specify_other(self): survey = utils.create_survey_from_fixture("specify_other", filetype=FIXTURE_FILETYPE) expected_dict = { u"name": u"specify_other", u"type": u"survey", u"title": u"specify_other", u"default_language": u"default", u"id_string": u"specify_other", u"sms_keyword": u"specify_other", u"children": [ { u"name": u"sex", u"label": {u"English": u"What sex are you?"}, u"type": u"select one", u"children": [ # TODO Change to choices (there is stuff in the json2xform half that will need to change) {u"name": u"male", u"label": {u"English": u"Male"}}, {u"name": u"female", u"label": {u"English": u"Female"}}, {u"name": u"other", u"label": u"Other"}, ], }, { u"name": u"sex_other", u"bind": {u"relevant": u"selected(../sex, 'other')"}, u"label": u"Specify other.", u"type": u"text", }, { u"children": [ { u"bind": {"calculate": "concat('uuid:', uuid())", "readonly": "true()"}, u"name": "instanceID", u"type": "calculate", } ], u"control": {"bodyless": True}, u"name": "meta", u"type": u"group", }, ], } self.maxDiff = None self.assertEqual(survey.to_json_dict(), expected_dict)
def test_include_json(self): survey_in = utils.create_survey_from_fixture( u"include_json", filetype=FIXTURE_FILETYPE, include_directory=True ) expected_dict = { u'name': u'include_json', u'title': u'include_json', u'default_language': u'default', u'id_string': u'include_json', u'type': u'survey', u'children': [ { u'label': u'How old are you?', u'name': u'age', u'type': u'integer' } ], } self.assertEquals(survey_in.to_json_dict(), expected_dict)
def test_style_column(self): survey = utils.create_survey_from_fixture( "style_settings", filetype=FIXTURE_FILETYPE) expected_dict = { u'children': [ { u'label': {u'english': u'What is your name?'}, u'name': u'your_name', u'type': u'text' }, { u'label': {u'english': u'How many years old are you?'}, u'name': u'your_age', u'type': u'integer' }, { u'children': [ { u'bind': { 'calculate': "concat('uuid:', uuid())", 'readonly': 'true()' }, u'name': 'instanceID', u'type': 'calculate' } ], u'control': {'bodyless': True}, u'name': 'meta', u'type': u'group' } ], u'default_language': u'default', u'id_string': u'new_id', u'name': u'style_settings', u'sms_keyword': u'new_id', u'style': u'ltr', u'title': u'My Survey', u'type': u'survey', } self.assertEqual(survey.to_json_dict(), expected_dict)
def test_include_json(self): survey_in = utils.create_survey_from_fixture(u"include_json", filetype=FIXTURE_FILETYPE, include_directory=True) expected_dict = { u'name': u'include_json', u'title': u'include_json', u'default_language': u'default', u'id_string': u'include_json', u'type': u'survey', u'children': [{ u'label': u'How old are you?', u'name': u'age', u'type': u'integer' }], } self.assertEquals(survey_in.to_json_dict(), expected_dict)
def test_specify_other(self): survey = utils.create_survey_from_fixture("specify_other", filetype=FIXTURE_FILETYPE) expected_dict = { u'name': u'specify_other', u'type': u'survey', u'title': u'specify_other', u'default_language': u'default', u'id_string': u'specify_other', u'children': [ { u'name': u'sex', u'label': {u'English': u'What sex are you?'}, u'type': u'select one', u'children': [ #TODO Change to choices (there is stuff in the json2xform half that will need to change) { u'name': u'male', u'label': {u'English': u'Male'} }, { u'name': u'female', u'label': {u'English': u'Female'} }, { u'name': u'other', u'label': u'Other' } ] }, { u'name': u'sex_other', u'bind': {u'relevant': u"selected(../sex, 'other')"}, u'label': u'Specify other.', u'type': u'text'} ] } self.maxDiff = None #import json #print json.dumps(survey, indent=4, ensure_ascii=False) self.assertEqual(survey.to_json_dict(), expected_dict)
def test_select_one_question_with_identical_choice_name(self): """ testing to make sure that select ones whose choice names are the same as the name of the select one get compiled. """ survey = utils.create_survey_from_fixture("choice_name_same_as_select_name", filetype=FIXTURE_FILETYPE) expected_dict = { u"name": u"choice_name_same_as_select_name", u"title": u"choice_name_same_as_select_name", u"sms_keyword": u"choice_name_same_as_select_name", u"default_language": u"default", u"id_string": u"choice_name_same_as_select_name", u"type": u"survey", u"children": [ { u"children": [{u"name": u"zone", u"label": u"Zone"}], u"type": u"select one", u"name": u"zone", u"label": u"Zone", }, { u"children": [ { u"bind": {"calculate": "concat('uuid:', uuid())", "readonly": "true()"}, u"name": "instanceID", u"type": "calculate", } ], u"control": {"bodyless": True}, u"name": "meta", u"type": u"group", }, ], } self.maxDiff = None self.assertEqual(survey.to_json_dict(), expected_dict)
def test_sms_columns(self): survey = utils.create_survey_from_fixture( "sms_info", filetype=FIXTURE_FILETYPE) expected_dict = { u'children': [{ u'children': [ { u'label': u'How old are you?', u'name': u'age', u'sms_field': u'q1', u'type': u'integer' }, { u'children': [ { u'label': u'no', u'name': u'0', u'sms_option': u'n' }, { u'label': u'yes', u'name': u'1', u'sms_option': u'y' }], u'label': u'Do you have any children?', u'name': u'has_children', u'sms_field': u'q2', u'type': u'select one' }, { u'label': u"What's your birth day?", u'name': u'bday', u'sms_field': u'q3', u'type': u'date' }, { u'label': u'What is your name?', u'name': u'name', u'sms_field': u'q4', u'type': u'text' } ], u'name': u'section1', u'sms_field': u'a', u'type': u'group' }, { u'children': [ { u'label': u'May I take your picture?', u'name': u'picture', u'type': u'photo' }, { u'label': u'Record your GPS coordinates.', u'name': u'gps', u'type': u'geopoint' } ], u'name': u'medias', u'sms_field': u'c', u'type': u'group' }, { u'children': [ { u'children': [{ u'label': u'Mozilla Firefox', u'name': u'firefox', u'sms_option': u'ff' }, { u'label': u'Google Chrome', u'name': u'chrome', u'sms_option': u'gc' }, { u'label': u'Internet Explorer', u'name': u'ie', u'sms_option': u'ie' }, { u'label': u'Safari', u'name': u'safari', u'sms_option': u'saf' } ], u'label': u'What web browsers do you use?', u'name': u'web_browsers', u'sms_field': u'q5', u'type': u'select all that apply' } ], u'name': u'browsers', u'sms_field': u'b', u'type': u'group' }, { u'children': [{ u'label': u'Phone Number', u'name': u'phone', u'type': u'phonenumber' }, { u'label': u'Start DT', u'name': u'start', u'type': u'start' }, { u'label': u'End DT', u'name': u'end', u'type': u'end' }, { u'label': u'Send Day', u'name': u'today', u'type': u'today' }, { u'label': u'IMEI', u'name': u'imei', u'type': u'deviceid' }, { u'label': u'Hey!', u'name': u'nope', u'type': u'note' }], u'name': u'metadata', u'sms_field': u'meta', u'type': u'group' }, { u'children': [{ u'bind': { 'calculate': "concat('uuid:', uuid())", 'readonly': 'true()' }, u'name': 'instanceID', u'type': 'calculate' }], u'control': {'bodyless': True}, u'name': 'meta', u'type': u'group' }], u'default_language': u'default', u'id_string': u'sms_info_form', u'name': u'sms_info', u'sms_allow_media': u'TRUE', u'sms_date_format': u'%Y-%m-%d', u'sms_datetime_format': u'%Y-%m-%d-%H:%M', u'sms_keyword': u'inf', u'sms_separator': u'+', u'title': u'SMS Example', u'type': u'survey' } self.assertEqual(survey.to_json_dict(), expected_dict)
def test_loop(self): survey = utils.create_survey_from_fixture( "loop", filetype=FIXTURE_FILETYPE) expected_dict = { u'name': u'loop', u'id_string': u'loop', u'sms_keyword': u'loop', u'title': u'loop', u'type': u'survey', u'default_language': u'default', u'children': [ { u'name': u'available_toilet_types', u'label': { u'english': u'What type of toilets are on the premises?' }, u'type': u'select all that apply', u'children': [ { u'name': u'pit_latrine_with_slab', u'label': {u'english': u'Pit latrine with slab'} }, { u'name': u'open_pit_latrine', u'label': { u'english': u'Pit latrine without slab/open pit' } }, { u'name': u'bucket_system', u'label': {u'english': u'Bucket system'} }, # Removing this because select alls shouldn't need # an explicit none option #{ # u'name': u'none', # u'label': u'None', # }, { u'name': u'other', u'label': u'Other' }, ] }, { u'name': u'available_toilet_types_other', u'bind': { u'relevant': u"selected(../available_toilet_types, 'other')" }, u'label': u'Specify other.', u'type': u'text' }, { u'name': u'loop_toilet_types', u'type': u'group', u'children': [ { u'name': u'pit_latrine_with_slab', u'label': {u'english': u'Pit latrine with slab'}, u'type': u'group', u'children': [ { u'name': u'number', u'label': { u'english': u'How many Pit latrine with slab are' u' on the premises?' }, u'type': u'integer' }]}, { u'name': u'open_pit_latrine', u'label': { u'english': u'Pit latrine without slab/open pit' }, u'type': u'group', u'children': [ { u'name': u'number', u'label': { u'english': u'How many Pit latrine without ' u'slab/open pit are on the premises?' }, u'type': u'integer' } ] }, { u'name': u'bucket_system', u'label': {u'english': u'Bucket system'}, u'type': u'group', u'children': [ { u'name': u'number', u'label': { u'english': u'How many Bucket system are on the' u' premises?'}, u'type': u'integer' } ] }]}, { u'children': [ { u'bind': { 'calculate': "concat('uuid:', uuid())", 'readonly': 'true()' }, u'name': 'instanceID', u'type': 'calculate' } ], u'control': { 'bodyless': True }, u'name': 'meta', u'type': u'group' }]} self.maxDiff = None self.assertEqual(survey.to_json_dict(), expected_dict)
def test_loop(self): survey = utils.create_survey_from_fixture("loop", filetype=FIXTURE_FILETYPE) expected_dict = { u'name': u'loop', u'id_string': u'loop', u'sms_keyword': u'loop', u'title': u'loop', u'type': u'survey', u'default_language': u'default', u'children': [ { u'name': u'available_toilet_types', u'label': { u'english': u'What type of toilets are on the premises?' }, u'type': u'select all that apply', u'children': [ { u'name': u'pit_latrine_with_slab', u'label': { u'english': u'Pit latrine with slab' } }, { u'name': u'open_pit_latrine', u'label': { u'english': u'Pit latrine without slab/open pit' } }, { u'name': u'bucket_system', u'label': { u'english': u'Bucket system' } }, # Removing this because select alls shouldn't need # an explicit none option #{ # u'name': u'none', # u'label': u'None', # }, { u'name': u'other', u'label': u'Other' }, ] }, { u'name': u'available_toilet_types_other', u'bind': { u'relevant': u"selected(../available_toilet_types, 'other')" }, u'label': u'Specify other.', u'type': u'text' }, { u'name': u'loop_toilet_types', u'type': u'group', u'children': [{ u'name': u'pit_latrine_with_slab', u'label': { u'english': u'Pit latrine with slab' }, u'type': u'group', u'children': [{ u'name': u'number', u'label': { u'english': u'How many Pit latrine with slab are' u' on the premises?' }, u'type': u'integer' }] }, { u'name': u'open_pit_latrine', u'label': { u'english': u'Pit latrine without slab/open pit' }, u'type': u'group', u'children': [{ u'name': u'number', u'label': { u'english': u'How many Pit latrine without ' u'slab/open pit are on the premises?' }, u'type': u'integer' }] }, { u'name': u'bucket_system', u'label': { u'english': u'Bucket system' }, u'type': u'group', u'children': [{ u'name': u'number', u'label': { u'english': u'How many Bucket system are on the' u' premises?' }, u'type': u'integer' }] }] }, { u'children': [{ u'bind': { 'calculate': "concat('uuid:', uuid())", 'readonly': 'true()' }, u'name': 'instanceID', u'type': 'calculate' }], u'control': { 'bodyless': True }, u'name': 'meta', u'type': u'group' } ] } self.maxDiff = None self.assertEqual(survey.to_json_dict(), expected_dict)
def test_include_json(self): survey_in = utils.create_survey_from_fixture("include_json", filetype=FIXTURE_FILETYPE, include_directory=True) for k, v in survey_in.to_dict().items(): if k!="name": self.assertEqual(v, self.survey_out_dict[k])
def test_sms_columns(self): survey = utils.create_survey_from_fixture("sms_info", filetype=FIXTURE_FILETYPE) expected_dict = { u"children": [ { u"children": [ {u"label": u"How old are you?", u"name": u"age", u"sms_field": u"q1", u"type": u"integer"}, { u"children": [ {u"label": u"no", u"name": u"0", u"sms_option": u"n"}, {u"label": u"yes", u"name": u"1", u"sms_option": u"y"}, ], u"label": u"Do you have any children?", u"name": u"has_children", u"sms_field": u"q2", u"type": u"select one", }, {u"label": u"What's your birth day?", u"name": u"bday", u"sms_field": u"q3", u"type": u"date"}, {u"label": u"What is your name?", u"name": u"name", u"sms_field": u"q4", u"type": u"text"}, ], u"name": u"section1", u"sms_field": u"a", u"type": u"group", }, { u"children": [ {u"label": u"May I take your picture?", u"name": u"picture", u"type": u"photo"}, {u"label": u"Record your GPS coordinates.", u"name": u"gps", u"type": u"geopoint"}, ], u"name": u"medias", u"sms_field": u"c", u"type": u"group", }, { u"children": [ { u"children": [ {u"label": u"Mozilla Firefox", u"name": u"firefox", u"sms_option": u"ff"}, {u"label": u"Google Chrome", u"name": u"chrome", u"sms_option": u"gc"}, {u"label": u"Internet Explorer", u"name": u"ie", u"sms_option": u"ie"}, {u"label": u"Safari", u"name": u"safari", u"sms_option": u"saf"}, ], u"label": u"What web browsers do you use?", u"name": u"web_browsers", u"sms_field": u"q5", u"type": u"select all that apply", } ], u"name": u"browsers", u"sms_field": u"b", u"type": u"group", }, { u"children": [ {u"label": u"Phone Number", u"name": u"phone", u"type": u"phonenumber"}, {u"label": u"Start DT", u"name": u"start", u"type": u"start"}, {u"label": u"End DT", u"name": u"end", u"type": u"end"}, {u"label": u"Send Day", u"name": u"today", u"type": u"today"}, {u"label": u"IMEI", u"name": u"imei", u"type": u"deviceid"}, {u"label": u"Hey!", u"name": u"nope", u"type": u"note"}, ], u"name": u"metadata", u"sms_field": u"meta", u"type": u"group", }, { u"children": [ { u"bind": {"calculate": "concat('uuid:', uuid())", "readonly": "true()"}, u"name": "instanceID", u"type": "calculate", } ], u"control": {"bodyless": True}, u"name": "meta", u"type": u"group", }, ], u"default_language": u"default", u"id_string": u"sms_info_form", u"name": u"sms_info", u"sms_allow_media": u"TRUE", u"sms_date_format": u"%Y-%m-%d", u"sms_datetime_format": u"%Y-%m-%d-%H:%M", u"sms_keyword": u"inf", u"sms_separator": u"+", u"title": u"SMS Example", u"type": u"survey", } self.assertEqual(survey.to_json_dict(), expected_dict)
def test_loop(self): survey = utils.create_survey_from_fixture("loop", filetype=FIXTURE_FILETYPE) expected_dict = { u"name": u"loop", u"id_string": u"loop", u"sms_keyword": u"loop", u"title": u"loop", u"type": u"survey", u"default_language": u"default", u"children": [ { u"name": u"available_toilet_types", u"label": {u"english": u"What type of toilets are on the premises?"}, u"type": u"select all that apply", # u'bind': {u'constraint': u"(.='none' or not(selected(., 'none')))"}, u"children": [ {u"name": u"pit_latrine_with_slab", u"label": {u"english": u"Pit latrine with slab"}}, {u"name": u"open_pit_latrine", u"label": {u"english": u"Pit latrine without slab/open pit"}}, {u"name": u"bucket_system", u"label": {u"english": u"Bucket system"}}, # Removing this because select alls shouldn't need an explicit none option # { # u'name': u'none', # u'label': u'None', # }, {u"name": u"other", u"label": u"Other"}, ], }, { u"name": u"available_toilet_types_other", u"bind": {u"relevant": u"selected(../available_toilet_types, 'other')"}, u"label": u"Specify other.", u"type": u"text", }, { u"name": u"loop_toilet_types", u"type": u"group", u"children": [ { u"name": u"pit_latrine_with_slab", u"label": {u"english": u"Pit latrine with slab"}, u"type": u"group", u"children": [ { u"name": u"number", u"label": {u"english": u"How many Pit latrine with slab are on the premises?"}, u"type": u"integer", } ], }, { u"name": u"open_pit_latrine", u"label": {u"english": u"Pit latrine without slab/open pit"}, u"type": u"group", u"children": [ { u"name": u"number", u"label": { u"english": u"How many Pit latrine without slab/open pit are on the premises?" }, u"type": u"integer", } ], }, { u"name": u"bucket_system", u"label": {u"english": u"Bucket system"}, u"type": u"group", u"children": [ { u"name": u"number", u"label": {u"english": u"How many Bucket system are on the premises?"}, u"type": u"integer", } ], }, ], }, { u"children": [ { u"bind": {"calculate": "concat('uuid:', uuid())", "readonly": "true()"}, u"name": "instanceID", u"type": "calculate", } ], u"control": {"bodyless": True}, u"name": "meta", u"type": u"group", }, ], } self.maxDiff = None self.assertEqual(survey.to_json_dict(), expected_dict)
def test_loop(self): survey = utils.create_survey_from_fixture("loop", filetype=FIXTURE_FILETYPE) expected_dict = { u'name': 'loop', u'type': u'survey', u'children': [ { u'name': u'available_toilet_types', u'label': {u'english': u'What type of toilets are on the premises?'}, u'type': u'select all that apply', u'bind': {u'constraint': u"(.='none' or not(selected(., 'none')))"}, u'children': [ { u'name': u'pit_latrine_with_slab', u'label': {u'english': u'Pit latrine with slab'} }, { u'name': u'open_pit_latrine', u'label': {u'english': u'Pit latrine without slab/open pit'} }, { u'name': u'bucket_system', u'label': {u'english': u'Bucket system'} }, { u'name': u'none', u'label': u'None', }, { u'name': u'other', u'label': u'Other' }, ] }, { u'name': u'available_toilet_types_other', u'bind': {u'relevant': u"selected(../available_toilet_types, 'other')"}, u'label': u'Specify other.', u'type': u'text' }, { u'name': u'pit_latrine_with_slab', u'label': {u'english': u'Pit latrine with slab'}, u'type' : u'group', u'children': [ { u'name': u'number', u'label': {u'english': u'How many Pit latrine with slab are on the premises?'}, u'type': u'integer' }]}, { u'name': u'open_pit_latrine', u'label': {u'english': u'Pit latrine without slab/open pit'}, u'type' : u'group', u'children': [ { u'name': u'number', u'label': {u'english': u'How many Pit latrine without slab/open pit are on the premises?'}, u'type': u'integer' } ] }, { u'name': u'bucket_system', u'label': {u'english': u'Bucket system'}, u'type' : u'group', u'children': [ { u'name': u'number', u'label': {u'english': u'How many Bucket system are on the premises?'}, u'type': u'integer' } ] }, { u'name': u'other', u'label': u'Other', u'type' : u'group', u'children': [{u'name': u'number', u'label': {u'english': u'How many Other are on the premises?'}, u'type': u'integer'}]}]} self.assertEqual(survey.to_dict(), expected_dict)
def test_cascading_selects(self): survey_cs = utils.create_survey_from_fixture("cascading_select_test", filetype=FIXTURE_FILETYPE) survey_eq = utils.create_survey_from_fixture( "cascading_select_test_equivalent", filetype=FIXTURE_FILETYPE) self.assertEqual(survey_cs.to_json_dict(), survey_eq.to_json_dict())
def test_specify_other(self): survey = utils.create_survey_from_fixture("specify_other", filetype=FIXTURE_FILETYPE) expected_dict = { u'name': u'specify_other', u'type': u'survey', u'title': u'specify_other', u'default_language': u'default', u'id_string': u'specify_other', u'sms_keyword': u'specify_other', u'children': [ { u'name': u'sex', u'label': { u'English': u'What sex are you?' }, u'type': u'select one', u'children': [ # TODO Change to choices (there is stuff in the # json2xform half that will need to change) { u'name': u'male', u'label': { u'English': u'Male' } }, { u'name': u'female', u'label': { u'English': u'Female' } }, { u'name': u'other', u'label': u'Other' } ] }, { u'name': u'sex_other', u'bind': { u'relevant': u"selected(../sex, 'other')" }, u'label': u'Specify other.', u'type': u'text' }, { u'children': [{ u'bind': { 'calculate': "concat('uuid:', uuid())", 'readonly': 'true()' }, u'name': 'instanceID', u'type': 'calculate' }], u'control': { 'bodyless': True }, u'name': 'meta', u'type': u'group' } ] } self.maxDiff = None self.assertEqual(survey.to_json_dict(), expected_dict)
def test_cascading_selects(self): survey_cs = utils.create_survey_from_fixture("cascading_select_test", filetype=FIXTURE_FILETYPE) survey_eq = utils.create_survey_from_fixture("cascading_select_test_equivalent", filetype=FIXTURE_FILETYPE) self.assertEqual(survey_cs.to_json_dict(), survey_eq.to_json_dict())
def test_loop(self): survey = utils.create_survey_from_fixture("loop", filetype=FIXTURE_FILETYPE) expected_dict = { u'name': u'loop', u'id_string': u'loop', u'title': u'loop', u'type': u'survey', u'default_language': u'default', u'children': [ { u'name': u'available_toilet_types', u'label': { u'english': u'What type of toilets are on the premises?' }, u'type': u'select all that apply', #u'bind': {u'constraint': u"(.='none' or not(selected(., 'none')))"}, u'children': [ { u'name': u'pit_latrine_with_slab', u'label': { u'english': u'Pit latrine with slab' } }, { u'name': u'open_pit_latrine', u'label': { u'english': u'Pit latrine without slab/open pit' } }, { u'name': u'bucket_system', u'label': { u'english': u'Bucket system' } }, #Removing this because select alls shouldn't need an explicit none option #{ # u'name': u'none', # u'label': u'None', # }, { u'name': u'other', u'label': u'Other' }, ] }, { u'name': u'available_toilet_types_other', u'bind': { u'relevant': u"selected(../available_toilet_types, 'other')" }, u'label': u'Specify other.', u'type': u'text' }, { u'name': u'pit_latrine_with_slab', u'label': { u'english': u'Pit latrine with slab' }, u'type': u'group', u'children': [{ u'name': u'number', u'label': { u'english': u'How many Pit latrine with slab are on the premises?' }, u'type': u'integer' }] }, { u'name': u'open_pit_latrine', u'label': { u'english': u'Pit latrine without slab/open pit' }, u'type': u'group', u'children': [{ u'name': u'number', u'label': { u'english': u'How many Pit latrine without slab/open pit are on the premises?' }, u'type': u'integer' }] }, { u'name': u'bucket_system', u'label': { u'english': u'Bucket system' }, u'type': u'group', u'children': [{ u'name': u'number', u'label': { u'english': u'How many Bucket system are on the premises?' }, u'type': u'integer' }] } ] } self.maxDiff = None self.assertEqual(survey.to_json_dict(), expected_dict)
def test_sms_columns(self): survey = utils.create_survey_from_fixture("sms_info", filetype=FIXTURE_FILETYPE) expected_dict = { u'children': [{ u'children': [{ u'label': u'How old are you?', u'name': u'age', u'sms_field': u'q1', u'type': u'integer' }, { u'children': [{ u'label': u'no', u'name': u'0', u'sms_option': u'n' }, { u'label': u'yes', u'name': u'1', u'sms_option': u'y' }], u'label': u'Do you have any children?', u'name': u'has_children', u'sms_field': u'q2', u'type': u'select one' }, { u'label': u"What's your birth day?", u'name': u'bday', u'sms_field': u'q3', u'type': u'date' }, { u'label': u'What is your name?', u'name': u'name', u'sms_field': u'q4', u'type': u'text' }], u'name': u'section1', u'sms_field': u'a', u'type': u'group' }, { u'children': [{ u'label': u'May I take your picture?', u'name': u'picture', u'type': u'photo' }, { u'label': u'Record your GPS coordinates.', u'name': u'gps', u'type': u'geopoint' }], u'name': u'medias', u'sms_field': u'c', u'type': u'group' }, { u'children': [{ u'children': [{ u'label': u'Mozilla Firefox', u'name': u'firefox', u'sms_option': u'ff' }, { u'label': u'Google Chrome', u'name': u'chrome', u'sms_option': u'gc' }, { u'label': u'Internet Explorer', u'name': u'ie', u'sms_option': u'ie' }, { u'label': u'Safari', u'name': u'safari', u'sms_option': u'saf' }], u'label': u'What web browsers do you use?', u'name': u'web_browsers', u'sms_field': u'q5', u'type': u'select all that apply' }], u'name': u'browsers', u'sms_field': u'b', u'type': u'group' }, { u'children': [{ u'label': u'Phone Number', u'name': u'phone', u'type': u'phonenumber' }, { u'label': u'Start DT', u'name': u'start', u'type': u'start' }, { u'label': u'End DT', u'name': u'end', u'type': u'end' }, { u'label': u'Send Day', u'name': u'today', u'type': u'today' }, { u'label': u'IMEI', u'name': u'imei', u'type': u'deviceid' }, { u'label': u'Hey!', u'name': u'nope', u'type': u'note' }], u'name': u'metadata', u'sms_field': u'meta', u'type': u'group' }, { u'children': [{ u'bind': { 'calculate': "concat('uuid:', uuid())", 'readonly': 'true()' }, u'name': 'instanceID', u'type': 'calculate' }], u'control': { 'bodyless': True }, u'name': 'meta', u'type': u'group' }], u'default_language': u'default', u'id_string': u'sms_info_form', u'name': u'sms_info', u'sms_allow_media': u'TRUE', u'sms_date_format': u'%Y-%m-%d', u'sms_datetime_format': u'%Y-%m-%d-%H:%M', u'sms_keyword': u'inf', u'sms_separator': u'+', u'title': u'SMS Example', u'type': u'survey' } self.assertEqual(survey.to_json_dict(), expected_dict)