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_style_column(self): survey = utils.create_survey_from_fixture("style_settings", filetype=FIXTURE_FILETYPE) expected_dict = { "children": [ { "label": { "english": "What is your name?" }, "name": "your_name", "type": "text", }, { "label": { "english": "How many years old are you?" }, "name": "your_age", "type": "integer", }, { "children": [{ "bind": { "jr:preload": "uid", "readonly": "true()" }, "name": "instanceID", "type": "calculate", }], "control": { "bodyless": True }, "name": "meta", "type": "group", }, ], "default_language": "default", "id_string": "new_id", "name": "style_settings", "sms_keyword": "new_id", "style": "ltr", "title": "My Survey", "type": "survey", } actual_dict = survey.to_json_dict() actual_dict.pop("generated_by", None) self.assertEqual(actual_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.encode('utf-8')) body_elms = list(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_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 = { "name": "choice_name_same_as_select_name", "title": "choice_name_same_as_select_name", "sms_keyword": "choice_name_same_as_select_name", "default_language": "default", "id_string": "choice_name_same_as_select_name", "type": "survey", "children": [ { "children": [{ "name": "zone", "label": "Zone" }], "type": "select one", "name": "zone", "label": "Zone", "list_name": "zone", }, { "children": [{ "bind": { "jr:preload": "uid", "readonly": "true()" }, "name": "instanceID", "type": "calculate", }], "control": { "bodyless": True }, "name": "meta", "type": "group", }, ], } actual_dict = survey.to_json_dict() actual_dict.pop("generated_by", None) self.maxDiff = None self.assertEqual(actual_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.encode('utf-8')) body_elms = list( 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_not_added_to_body_if_not_present(self): survey = utils.create_survey_from_fixture("settings", filetype=FIXTURE_FILETYPE) xml = survey.to_xml() # find the body tag root_elm = ETree.fromstring(xml.encode("utf-8")) body_elms = list( 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.assertIsNone(body_elms[0].get("class"))
def test_style_not_added_to_body_if_not_present(self): survey = utils.create_survey_from_fixture("settings", filetype=FIXTURE_FILETYPE) xml = survey.to_xml() # find the body tag root_elm = ETree.fromstring(xml.encode("utf-8")) body_elms = list( 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.assertIsNone(body_elms[0].get("class"))
def test_specify_other(self): survey = utils.create_survey_from_fixture( "specify_other", filetype=FIXTURE_FILETYPE ) expected_dict = { "name": "specify_other", "type": "survey", "title": "specify_other", "default_language": "default", "id_string": "specify_other", "sms_keyword": "specify_other", "children": [ { "name": "sex", "label": {"English": "What sex are you?"}, "type": "select one", "children": [ # TODO Change to choices (there is stuff in the # json2xform half that will need to change) {"name": "male", "label": {"English": "Male"}}, {"name": "female", "label": {"English": "Female"}}, {"name": "other", "label": "Other"}, ], }, { "name": "sex_other", "bind": {"relevant": "selected(../sex, 'other')"}, "label": "Specify other.", "type": "text", }, { "children": [ { "bind": { "calculate": "concat('uuid:', uuid())", "readonly": "true()", }, "name": "instanceID", "type": "calculate", } ], "control": {"bodyless": True}, "name": "meta", "type": "group", }, ], } self.maxDiff = None self.assertEqual(survey.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_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_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 = { "name": "choice_name_same_as_select_name", "title": "choice_name_same_as_select_name", "sms_keyword": "choice_name_same_as_select_name", "default_language": "default", "id_string": "choice_name_same_as_select_name", "type": "survey", "children": [ { "children": [{"name": "zone", "label": "Zone"}], "type": "select one", "name": "zone", "label": "Zone", }, { "children": [ { "bind": { "calculate": "concat('uuid:', uuid())", "readonly": "true()", }, "name": "instanceID", "type": "calculate", } ], "control": {"bodyless": True}, "name": "meta", "type": "group", }, ], } self.maxDiff = None self.assertEqual(survey.to_json_dict(), expected_dict)
def test_style_column(self): survey = utils.create_survey_from_fixture( "style_settings", filetype=FIXTURE_FILETYPE ) expected_dict = { "children": [ { "label": {"english": "What is your name?"}, "name": "your_name", "type": "text", }, { "label": {"english": "How many years old are you?"}, "name": "your_age", "type": "integer", }, { "children": [ { "bind": { "calculate": "concat('uuid:', uuid())", "readonly": "true()", }, "name": "instanceID", "type": "calculate", } ], "control": {"bodyless": True}, "name": "meta", "type": "group", }, ], "default_language": "default", "id_string": "new_id", "name": "style_settings", "sms_keyword": "new_id", "style": "ltr", "title": "My Survey", "type": "survey", } self.assertEqual(survey.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_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 = { "name": "loop", "id_string": "loop", "sms_keyword": "loop", "title": "loop", "type": "survey", "default_language": "default", "children": [ { "name": "available_toilet_types", "label": {"english": "What type of toilets are on the premises?"}, "type": "select all that apply", "children": [ { "name": "pit_latrine_with_slab", "label": {"english": "Pit latrine with slab"}, }, { "name": "open_pit_latrine", "label": {"english": "Pit latrine without slab/open pit"}, }, { "name": "bucket_system", "label": {"english": "Bucket system"}, }, # Removing this because select alls shouldn't need # an explicit none option # { # u'name': u'none', # u'label': u'None', # }, {"name": "other", "label": "Other"}, ], }, { "name": "available_toilet_types_other", "bind": { "relevant": "selected(../available_toilet_types, 'other')" }, "label": "Specify other.", "type": "text", }, { "name": "loop_toilet_types", "type": "group", "children": [ { "name": "pit_latrine_with_slab", "label": {"english": "Pit latrine with slab"}, "type": "group", "children": [ { "name": "number", "label": { "english": "How many Pit latrine with slab are" " on the premises?" }, "type": "integer", } ], }, { "name": "open_pit_latrine", "label": {"english": "Pit latrine without slab/open pit"}, "type": "group", "children": [ { "name": "number", "label": { "english": "How many Pit latrine without " "slab/open pit are on the premises?" }, "type": "integer", } ], }, { "name": "bucket_system", "label": {"english": "Bucket system"}, "type": "group", "children": [ { "name": "number", "label": { "english": "How many Bucket system are on the" " premises?" }, "type": "integer", } ], }, ], }, { "children": [ { "bind": { "calculate": "concat('uuid:', uuid())", "readonly": "true()", }, "name": "instanceID", "type": "calculate", } ], "control": {"bodyless": True}, "name": "meta", "type": "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'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_sms_columns(self): survey = utils.create_survey_from_fixture("sms_info", filetype=FIXTURE_FILETYPE) expected_dict = { "children": [ { "children": [ { "label": "How old are you?", "name": "age", "sms_field": "q1", "type": "integer", }, { "children": [ { "label": "no", "name": "0", "sms_option": "n" }, { "label": "yes", "name": "1", "sms_option": "y" }, ], "label": "Do you have any children?", "name": "has_children", "sms_field": "q2", "type": "select one", }, { "label": "What's your birth day?", "name": "bday", "sms_field": "q3", "type": "date", }, { "label": "What is your name?", "name": "name", "sms_field": "q4", "type": "text", }, ], "name": "section1", "sms_field": "a", "type": "group", }, { "children": [ { "label": "May I take your picture?", "name": "picture", "type": "photo", }, { "label": "Record your GPS coordinates.", "name": "gps", "type": "geopoint", }, ], "name": "medias", "sms_field": "c", "type": "group", }, { "children": [{ "children": [ { "label": "Mozilla Firefox", "name": "firefox", "sms_option": "ff", }, { "label": "Google Chrome", "name": "chrome", "sms_option": "gc", }, { "label": "Internet Explorer", "name": "ie", "sms_option": "ie", }, { "label": "Safari", "name": "safari", "sms_option": "saf", }, ], "label": "What web browsers do you use?", "name": "web_browsers", "sms_field": "q5", "type": "select all that apply", }], "name": "browsers", "sms_field": "b", "type": "group", }, { "children": [ { "label": "Phone Number", "name": "phone", "type": "phonenumber", }, { "label": "Start DT", "name": "start", "type": "start" }, { "label": "End DT", "name": "end", "type": "end" }, { "label": "Send Day", "name": "today", "type": "today" }, { "label": "IMEI", "name": "imei", "type": "deviceid" }, { "label": "Hey!", "name": "nope", "type": "note" }, ], "name": "metadata", "sms_field": "meta", "type": "group", }, { "children": [{ "bind": { "jr:preload": "uid", "readonly": "true()" }, "name": "instanceID", "type": "calculate", }], "control": { "bodyless": True }, "name": "meta", "type": "group", }, ], "default_language": "default", "id_string": "sms_info_form", "name": "sms_info", "sms_allow_media": "TRUE", "sms_date_format": "%Y-%m-%d", "sms_datetime_format": "%Y-%m-%d-%H:%M", "sms_keyword": "inf", "sms_separator": "+", "title": "SMS Example", "type": "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 = { "name": "loop", "id_string": "loop", "sms_keyword": "loop", "title": "loop", "type": "survey", "default_language": "default", "children": [ { "name": "available_toilet_types", "label": { "english": "What type of toilets are on the premises?" }, "type": "select all that apply", "children": [ { "name": "pit_latrine_with_slab", "label": { "english": "Pit latrine with slab" }, }, { "name": "open_pit_latrine", "label": { "english": "Pit latrine without slab/open pit" }, }, { "name": "bucket_system", "label": { "english": "Bucket system" }, }, # Removing this because select alls shouldn't need # an explicit none option # { # u'name': u'none', # u'label': u'None', # }, { "name": "other", "label": "Other" }, ], }, { "name": "available_toilet_types_other", "bind": { "relevant": "selected(../available_toilet_types, 'other')" }, "label": "Specify other.", "type": "text", }, { "name": "loop_toilet_types", "type": "group", "children": [ { "name": "pit_latrine_with_slab", "label": { "english": "Pit latrine with slab" }, "type": "group", "children": [{ "name": "number", "label": { "english": "How many Pit latrine with slab are" " on the premises?" }, "type": "integer", }], }, { "name": "open_pit_latrine", "label": { "english": "Pit latrine without slab/open pit" }, "type": "group", "children": [{ "name": "number", "label": { "english": "How many Pit latrine without " "slab/open pit are on the premises?" }, "type": "integer", }], }, { "name": "bucket_system", "label": { "english": "Bucket system" }, "type": "group", "children": [{ "name": "number", "label": { "english": "How many Bucket system are on the" " premises?" }, "type": "integer", }], }, ], }, { "children": [{ "bind": { "jr:preload": "uid", "readonly": "true()" }, "name": "instanceID", "type": "calculate", }], "control": { "bodyless": True }, "name": "meta", "type": "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_sms_columns(self): survey = utils.create_survey_from_fixture("sms_info", filetype=FIXTURE_FILETYPE) expected_dict = { "children": [ { "children": [ { "label": "How old are you?", "name": "age", "sms_field": "q1", "type": "integer", }, { "children": [ {"label": "no", "name": "0", "sms_option": "n"}, {"label": "yes", "name": "1", "sms_option": "y"}, ], "label": "Do you have any children?", "name": "has_children", "sms_field": "q2", "type": "select one", }, { "label": "What's your birth day?", "name": "bday", "sms_field": "q3", "type": "date", }, { "label": "What is your name?", "name": "name", "sms_field": "q4", "type": "text", }, ], "name": "section1", "sms_field": "a", "type": "group", }, { "children": [ { "label": "May I take your picture?", "name": "picture", "type": "photo", }, { "label": "Record your GPS coordinates.", "name": "gps", "type": "geopoint", }, ], "name": "medias", "sms_field": "c", "type": "group", }, { "children": [ { "children": [ { "label": "Mozilla Firefox", "name": "firefox", "sms_option": "ff", }, { "label": "Google Chrome", "name": "chrome", "sms_option": "gc", }, { "label": "Internet Explorer", "name": "ie", "sms_option": "ie", }, { "label": "Safari", "name": "safari", "sms_option": "saf", }, ], "label": "What web browsers do you use?", "name": "web_browsers", "sms_field": "q5", "type": "select all that apply", } ], "name": "browsers", "sms_field": "b", "type": "group", }, { "children": [ { "label": "Phone Number", "name": "phone", "type": "phonenumber", }, {"label": "Start DT", "name": "start", "type": "start"}, {"label": "End DT", "name": "end", "type": "end"}, {"label": "Send Day", "name": "today", "type": "today"}, {"label": "IMEI", "name": "imei", "type": "deviceid"}, {"label": "Hey!", "name": "nope", "type": "note"}, ], "name": "metadata", "sms_field": "meta", "type": "group", }, { "children": [ { "bind": { "calculate": "concat('uuid:', uuid())", "readonly": "true()", }, "name": "instanceID", "type": "calculate", } ], "control": {"bodyless": True}, "name": "meta", "type": "group", }, ], "default_language": "default", "id_string": "sms_info_form", "name": "sms_info", "sms_allow_media": "TRUE", "sms_date_format": "%Y-%m-%d", "sms_datetime_format": "%Y-%m-%d-%H:%M", "sms_keyword": "inf", "sms_separator": "+", "title": "SMS Example", "type": "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)