Ejemplo n.º 1
0
 def test_should_create_integer_field_type_with_range(self):
     expected_json = {
         "label": "What is your age",
         "name": "Age",
         "code": "Q2",
         "constraints": [('range', {
             "min": 15,
             "max": 120
         })],
         "parent_field_code": None,
         "type": "integer",
         "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",
         constraints=[NumericRangeConstraint(min=15, max=120)],
         instruction="test_instruction")
     actual_json = field._to_json()
     self.assertEqual(actual_json, expected_json)
Ejemplo n.º 2
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())
Ejemplo n.º 3
0
 def test_should_create_integer_field_type_for_default_english_language_with_range(
         self):
     expected_json = {
         "label": {
             "eng": "What is your age"
         },
         "name": "Age",
         "code": "Q2",
         "range": {
             "min": 15,
             "max": 120
         },
         "ddtype": self.DDTYPE_JSON,
         "type": "integer",
         "instruction": "test_instruction"
     }
     field = IntegerField(name="Age",
                          code="Q2",
                          label="What is your age",
                          language="eng",
                          range=NumericConstraint(min=15, max=120),
                          ddtype=self.ddtype,
                          instruction="test_instruction")
     actual_json = field._to_json()
     self.assertEqual(actual_json, expected_json)
Ejemplo n.º 4
0
 def test_should_add_entity_field_with_default_constraints(self):
     expected_json = {
         "defaultValue":
         "",
         "label":
         "What is your name",
         "name":
         "field1_Name",
         "code":
         "Q1",
         "type":
         "short_code",
         'parent_field_code':
         None,
         "constraints": [("length", {
             "max": 20
         }), ("short_code", "^[a-zA-Z0-9]+$")],
         "required":
         False,
         "instruction":
         "test_instruction"
     }
     field = ShortCodeField(name="field1_Name",
                            code="Q1",
                            label="What is your name",
                            instruction="test_instruction")
     actual_json = field._to_json()
     self.assertDictEqual(actual_json, expected_json)
Ejemplo n.º 5
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())
Ejemplo n.º 6
0
 def test_telephone_number_field_should_return_expected_json(self):
     mobile_number_length = TextLengthConstraint(max=15)
     mobile_number_pattern = RegexConstraint(reg='^[0-9]+$')
     field = TelephoneNumberField(
         name="test",
         code='MC',
         label='question',
         constraints=[mobile_number_length, mobile_number_pattern],
         instruction='')
     expected_json = {
         "label": "question",
         "name": "test",
         "code": "MC",
         'parent_field_code': None,
         "type": "telephone_number",
         "instruction": "",
         "constraints": [('length', {
             'max': 15
         }), ('regex', '^[0-9]+$')],
         "defaultValue": '',
         "required": True,
         "appearance": None,
         "constraint_message": None,
         "default": None,
         "hint": None,
         "xform_constraint": None,
         "relevant": None
     }
     self.assertEqual(expected_json, field._to_json())
Ejemplo n.º 7
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())
Ejemplo n.º 8
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())
Ejemplo n.º 9
0
 def test_should_create_text_field_type_for_default_english_language(self):
     expected_json = {
         "defaultValue": "some default value",
         "label": {
             "eng": "What is your name"
         },
         "name": "field1_Name",
         "instruction": "Answer is word or phrase",
         "code": "Q1",
         "length": {
             "min": 1,
             "max": 20
         },
         "type": "text",
         "ddtype": self.DDTYPE_JSON,
     }
     field = TextField(name="field1_Name",
                       code="Q1",
                       label="What is your name",
                       defaultValue="some default value",
                       length=TextConstraint(1, 20),
                       language="eng",
                       ddtype=self.ddtype,
                       instruction="Answer is word or phrase")
     actual_json = field._to_json()
     self.assertEqual(actual_json, expected_json)
Ejemplo n.º 10
0
 def test_should_set_new_instruction_for_field(self):
     new_instruction = "new_instruction"
     expected_json = {
         "label": "What is your age",
         "name": "name",
         "code": "Q2",
         "parent_field_code": None,
         "type": "integer",
         "required": True,
         "instruction": new_instruction,
         "appearance": None,
         "constraint_message": None,
         "default": None,
         "hint": None,
         "xform_constraint": None,
         "relevant": None
     }
     field = Field(type="integer",
                   name="name",
                   code="Q2",
                   label="What is your age",
                   instruction="instruction")
     field.set_instruction(new_instruction)
     actual_json = field._to_json()
     self.assertEqual(actual_json, expected_json)
Ejemplo n.º 11
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())
Ejemplo n.º 12
0
 def test_should_create_location_field_type_for_default_english_language(self):
     expected_json = {
         "label": {"eng": "Where do you stay?"},
         "name": "field1_Loc",
         "code": "Q1",
         "type": "geocode",
         "ddtype": self.DDTYPE_JSON,
         "instruction":"test_instruction"
         }
     field = GeoCodeField(name="field1_Loc", code="Q1", label="Where do you stay?", ddtype=self.ddtype,
                          language="eng", instruction="test_instruction",)
     actual_json = field._to_json()
     self.assertEqual(actual_json, expected_json)
Ejemplo n.º 13
0
 def test_date_field_with_event_time_flag_should_return_expected_json(self):
     field = DateField('event_time', 'et', 'event_time', '%m.%d.%Y')
     expected_json = {
         "instruction": None,
         "label": "event_time",
         "name": "event_time",
         "code": "et",
         'parent_field_code': None,
         "type": "date",
         "date_format": "%m.%d.%Y",
         "required": True,
     }
     self.assertEqual(expected_json, field._to_json())
Ejemplo n.º 14
0
 def test_should_create_list_field_type_for_default_english_language(self):
     expected_json = {
         "label": {"eng": "What is your location"},
         "name": "loc",
         "instruction": "Answer is list",
         "code": "Q1",
         "type": "list",
         "ddtype": self.DDTYPE_JSON,
         }
     field = HierarchyField(name="loc", code="Q1", label="What is your location", language="eng",
                       ddtype=self.ddtype, instruction="Answer is list")
     actual_json = field._to_json()
     self.assertEqual(actual_json, expected_json)
Ejemplo n.º 15
0
 def test_should_create_integer_field_type_for_default_english_language_with_range(self):
     expected_json = {
         "label": {"eng": "What is your age"},
         "name": "Age",
         "code": "Q2",
         "range": {"min": 15, "max": 120},
         "ddtype": self.DDTYPE_JSON,
         "type": "integer",
         "instruction":"test_instruction"
         }
     field = IntegerField(name="Age", code="Q2", label="What is your age",
                          language="eng", range=NumericConstraint(min=15, max=120), ddtype=self.ddtype, instruction="test_instruction")
     actual_json = field._to_json()
     self.assertEqual(actual_json, expected_json)
Ejemplo n.º 16
0
 def test_should_create_select_one_field_type_for_default_english_language(self):
     expected_json = {
         "label": {"eng": "What is your favorite color"},
         "name": "color",
         "choices": [{"text": {"eng": "RED"}, "val": 1}, {"text": {"eng": "YELLOW"}, "val": 2},
                     {"text": {'eng': 'green'}, "val": 3}],
         "code": "Q3",
         "ddtype": self.DDTYPE_JSON,
         "type": "select1",
         "instruction":None
         }
     field = SelectField(name="color", code="Q3", label="What is your favorite color",
                         language="eng", options=[("RED", 1), ("YELLOW", 2), ('green', 3)], ddtype=self.ddtype)
     actual_json = field._to_json()
     self.assertEqual(actual_json, expected_json)
Ejemplo n.º 17
0
 def test_should_create_text_field_type_for_default_english_language(self):
     expected_json = {
         "defaultValue": "some default value",
         "label": {"eng": "What is your name"},
         "name": "field1_Name",
         "instruction": "Answer is word or phrase",
         "code": "Q1",
         "length": {"min": 1, "max": 20},
         "type": "text",
         "ddtype": self.DDTYPE_JSON,
         }
     field = TextField(name="field1_Name", code="Q1", label="What is your name",
                       defaultValue="some default value", length=TextConstraint(1, 20), language="eng",
                       ddtype=self.ddtype, instruction="Answer is word or phrase")
     actual_json = field._to_json()
     self.assertEqual(actual_json, expected_json)
Ejemplo n.º 18
0
 def test_should_add_entity_field(self):
     expected_json = {
         "defaultValue": "",
         "label": {"eng": "What is your name"},
         "name": "field1_Name",
         "code": "Q1",
         "length": {},
         "type": "text",
         "ddtype": self.DDTYPE_JSON,
         "entity_question_flag": True,
         "instruction":"test_instruction"
     }
     field = TextField(name="field1_Name", code="Q1", label="What is your name",
                       entity_question_flag=True, ddtype=self.ddtype, instruction="test_instruction")
     actual_json = field._to_json()
     self.assertEqual(actual_json, expected_json)
Ejemplo n.º 19
0
 def test_should_add_label_for_french_language(self):
     expected_json = {
         "defaultValue": "some default value",
         "label": {"eng": "What is your name", "fra": "french label"},
         "name": "field1_Name",
         "code": "Q1",
         "length": {},
         "instruction":"test_instruction",
         "ddtype": self.DDTYPE_JSON,
         "type": "text"
     }
     field = TextField(name="field1_Name", code="Q1", label="What is your name",
                       defaultValue="some default value", ddtype=self.ddtype, instruction="test_instruction")
     field.add_or_edit_label(language="fra", label="french label")
     actual_json = field._to_json()
     self.assertEqual(actual_json, expected_json)
Ejemplo n.º 20
0
 def test_should_set_new_instruction_for_field(self):
     new_instruction = "new_instruction"
     expected_json = {
         "label": "What is your age",
         "name": "name",
         "code": "Q2",
         'parent_field_code': None,
         "type": "integer",
         "required": True,
         "instruction": new_instruction
     }
     field = Field(type="integer",
                   name="name",
                   code="Q2",
                   label="What is your age",
                   instruction="instruction")
     field.set_instruction(new_instruction)
     actual_json = field._to_json()
     self.assertEqual(actual_json, expected_json)
Ejemplo n.º 21
0
 def test_should_create_list_field_type_for_default_english_language(self):
     expected_json = {
         "label": {
             "eng": "What is your location"
         },
         "name": "loc",
         "instruction": "Answer is list",
         "code": "Q1",
         "type": "list",
         "ddtype": self.DDTYPE_JSON,
     }
     field = HierarchyField(name="loc",
                            code="Q1",
                            label="What is your location",
                            language="eng",
                            ddtype=self.ddtype,
                            instruction="Answer is list")
     actual_json = field._to_json()
     self.assertEqual(actual_json, expected_json)
Ejemplo n.º 22
0
 def test_should_create_multi_select_field_type_for_default_english_language(
         self):
     expected_json = {
         "label": {
             "eng": "What is your favorite color"
         },
         "name":
         "color",
         "choices": [{
             "text": {
                 "eng": "RED"
             },
             "val": 1
         }, {
             "text": {
                 "eng": "YELLOW"
             },
             "val": 2
         }, {
             "text": {
                 'eng': 'green'
             }
         }],
         "code":
         "Q3",
         "ddtype":
         self.DDTYPE_JSON,
         "type":
         "select",
         "instruction":
         "test_instruction"
     }
     field = SelectField(name="color",
                         code="Q3",
                         label="What is your favorite color",
                         language="eng",
                         options=[("RED", 1), ("YELLOW", 2), ('green')],
                         single_select_flag=False,
                         ddtype=self.ddtype,
                         instruction="test_instruction")
     actual_json = field._to_json()
     self.assertEqual(actual_json, expected_json)
Ejemplo n.º 23
0
 def test_should_create_location_field_type_for_default_english_language(
         self):
     expected_json = {
         "label": {
             "eng": "Where do you stay?"
         },
         "name": "field1_Loc",
         "code": "Q1",
         "type": "geocode",
         "ddtype": self.DDTYPE_JSON,
         "instruction": "test_instruction"
     }
     field = GeoCodeField(
         name="field1_Loc",
         code="Q1",
         label="Where do you stay?",
         ddtype=self.ddtype,
         language="eng",
         instruction="test_instruction",
     )
     actual_json = field._to_json()
     self.assertEqual(actual_json, expected_json)
Ejemplo n.º 24
0
 def test_should_convert_ddtype_to_json(self):
     expected_json = {
         "defaultValue": "",
         "label": {
             "eng": "What is your name"
         },
         "name": "field1_Name",
         "code": "Q1",
         "length": {},
         "type": "text",
         "ddtype": self.DDTYPE_JSON,
         "entity_question_flag": True,
         "instruction": None
     }
     field = TextField(name="field1_Name",
                       code="Q1",
                       label="What is your name",
                       entity_question_flag=True,
                       ddtype=self.ddtype)
     actual_json = field._to_json()
     self.assertEqual(actual_json, expected_json)
     self.assertEqual(self.ddtype, field.ddtype)
Ejemplo n.º 25
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())
Ejemplo n.º 26
0
 def test_should_add_label_for_french_language(self):
     expected_json = {
         "defaultValue": "some default value",
         "label": {
             "eng": "What is your name",
             "fra": "french label"
         },
         "name": "field1_Name",
         "code": "Q1",
         "length": {},
         "instruction": "test_instruction",
         "ddtype": self.DDTYPE_JSON,
         "type": "text"
     }
     field = TextField(name="field1_Name",
                       code="Q1",
                       label="What is your name",
                       defaultValue="some default value",
                       ddtype=self.ddtype,
                       instruction="test_instruction")
     field.add_or_edit_label(language="fra", label="french label")
     actual_json = field._to_json()
     self.assertEqual(actual_json, expected_json)