Beispiel #1
0
    def test_should_create_text_field_type_for_default_english_language(self):
        expected_json = {
            "defaultValue": "some default value",
            "label": "What is your name",
            "name": "field1_Name",
            "instruction": "Answer is word or phrase",
            "code": "Q1",
            'parent_field_code': None,
            "constraints": [("length", {
                "min": 1,
                "max": 20
            })],
            "type": "text",
            "required": True,
        }
        field = TextField(name="field1_Name",
                          code="Q1",
                          label="What is your name",
                          defaultValue="some default value",
                          constraints=[TextLengthConstraint(1, 20)],
                          instruction="Answer is word or phrase")
        actual_json = field._to_json()
        self.assertEqual(actual_json, expected_json)

        field.set_value("abc")
        self.assertEqual("abc", field.convert_to_unicode())
Beispiel #2
0
 def test_should_create_location_field_type_for_default_english_language(
         self):
     expected_json = {
         "label": "Where do you stay?",
         "name": "field1_Loc",
         "code": "Q1",
         "type": "geocode",
         "parent_field_code": None,
         "required": True,
         "instruction": "test_instruction",
         "appearance": None,
         "constraint_message": None,
         "default": None,
         "hint": None,
         "xform_constraint": None,
         "relevant": None
     }
     field = GeoCodeField(
         name="field1_Loc",
         code="Q1",
         label="Where do you stay?",
         instruction="test_instruction",
     )
     actual_json = field._to_json()
     self.assertEqual(actual_json, expected_json)
     field.set_value(field.validate("23,23"))
     self.assertEqual("23.0, 23.0", field.convert_to_unicode())
Beispiel #3
0
 def test_should_create_integer_field_type_for_default_english_language(
         self):
     expected_json = {
         "label": "What is your age",
         "name": "Age",
         "code": "Q2",
         "type": "integer",
         'parent_field_code': None,
         "required": True,
         "instruction": "test_instruction",
         "appearance": None,
         "constraint_message": None,
         "default": None,
         "hint": None,
         "xform_constraint": None,
         "relevant": None
     }
     field = IntegerField(name="Age",
                          code="Q2",
                          label="What is your age",
                          instruction="test_instruction")
     actual_json = field._to_json()
     self.assertEqual(actual_json, expected_json)
     field.set_value(123)
     self.assertEqual("123", field.convert_to_unicode())
Beispiel #4
0
    def test_should_create_list_field_type_for_default_english_language(self):
        expected_json = {
            "label": "What is your location",
            "name": "loc",
            "instruction": "Answer is list",
            "parent_field_code": None,
            "code": "Q1",
            "type": "list",
            "required": True,
            "appearance": None,
            "constraint_message": None,
            "default": None,
            "hint": None,
            "xform_constraint": None,
            "relevant": None
        }
        field = HierarchyField(name="loc",
                               code="Q1",
                               label="What is your location",
                               instruction="Answer is list")
        actual_json = field._to_json()
        self.assertEqual(actual_json, expected_json)

        field.set_value(["abc", "def"])
        self.assertEqual("abc,def", field.convert_to_unicode())
Beispiel #5
0
 def test_should_create_multi_select_field_type_for_default_english_language(
         self):
     expected_json = {
         "label":
         "What is your favorite color",
         "name":
         "color",
         "choices": [{
             "text": "RED",
             "val": 'a'
         }, {
             "text": "YELLOW",
             "val": 'b'
         }, {
             "text": 'green',
             'val': 'green'
         }],
         "code":
         "Q3",
         "parent_field_code":
         None,
         "type":
         "select",
         "required":
         True,
         "instruction":
         "test_instruction",
         "appearance":
         None,
         "constraint_message":
         None,
         "default":
         None,
         "hint":
         None,
         "xform_constraint":
         None,
         "relevant":
         None,
         "is_cascade":
         False
     }
     field = SelectField(name="color",
                         code="Q3",
                         label="What is your favorite color",
                         options=[("RED", 'a'), ("YELLOW", 'b'), ('green')],
                         single_select_flag=False,
                         instruction="test_instruction")
     actual_json = field._to_json()
     self.assertEqual(actual_json, expected_json)
     field.set_value(field.validate('ab'))
     self.assertEqual("RED,YELLOW", field.convert_to_unicode())
Beispiel #6
0
    def test_should_create_select_one_field_type_for_default_english_language(
            self):
        expected_json = {
            "label":
            "What is your favorite color",
            "name":
            "color",
            "choices": [{
                "text": "RED",
                "val": 'a'
            }, {
                "text": "YELLOW",
                "val": 'b'
            }, {
                "text": 'green',
                "val": 'c'
            }],
            "code":
            "Q3",
            'parent_field_code':
            None,
            "type":
            "select1",
            "required":
            True,
            "instruction":
            None
        }
        field = SelectField(name="color",
                            code="Q3",
                            label="What is your favorite color",
                            options=[("RED", 'a'), ("YELLOW", 'b'),
                                     ('green', 'c')])
        actual_json = field._to_json()
        self.assertEqual(actual_json, expected_json)

        field.set_value(field.validate('b'))
        self.assertEqual("YELLOW", field.convert_to_unicode())