コード例 #1
0
ファイル: test_form_model.py プロジェクト: mariot/mangrove
 def get_form_model_doc(self, fields=[]):
     if len(fields) == 0:
         fields = [{
             "constraints": [('range', {
                 "max": 10,
                 "min": 0
             })],
             "label": "",
             "type": "integer",
             "name": "What is your age?",
             "code": "AGE",
             "required": False
         }, {
             "choices": [{
                 "text": "Pune"
             }, {
                 "text": "Bangalore"
             }],
             "label": "",
             "type": "select",
             "name": "Where do you live?",
             "code": "PLC",
             "required": False
         }]
     document = FormModelDocument()
     document.json_fields = fields
     document.document_type = "FormModel"
     document.form_code = "F1"
     document.name = "New Project"
     document.type = "survey"
     document.type = "survey"
     return document
コード例 #2
0
 def test_should_create_a_questionnaire_from_dictionary(self):
     fields = [
             {
             "name": "What are you reporting on?",
             "defaultValue": "",
             "label": {
                 "eng": "Entity being reported on"
             },
             "entity_question_flag": True,
             "type": "text",
             "ddtype": self.default_ddtype.to_json(),
             "code": "eid",
             "length": {"min": 1, "max": 10},
             },
             {
             "range": {
                 "max": 10,
                 "min": 0
             },
             "label": {"eng": ""},
             "type": "integer",
             "ddtype": self.default_ddtype.to_json(),
             "name": "What is your age?",
             "code": "AGE"
         },
             {
             "choices": [
                     {
                     "text": {"eng": "Pune"}
                 },
                     {
                     "text": {"eng": "Bangalore"}
                 }
             ],
             "label": {"eng": ""},
             "type": "select",
             "ddtype": self.default_ddtype.to_json(),
             "name": "Where do you live?",
             "code": "PLC"
         }]
     document = FormModelDocument()
     document.json_fields = fields
     document.entity_type = ["Reporter"]
     document.document_type = "FormModel"
     document.form_code = "F1"
     document.name = "New Project"
     document.type = "survey"
     document.type = "survey"
     entityQ = TextField(name="What are you reporting on?", code="eid",
                         label="Entity being reported on", entity_question_flag=True,
                         length=TextConstraint(min=1, max=10), ddtype=self.default_ddtype)
     ageQ = IntegerField(name="What is your age?", code="AGE", label="",
                         range=NumericConstraint(min=0, max=10), ddtype=self.default_ddtype)
     placeQ = SelectField(name="Where do you live?", code="PLC", label="",
                          options=[{"text": {"eng": "Pune"}}, {"text": {"eng": "Bangalore"}}],
                          single_select_flag=False, ddtype=self.default_ddtype)
     questions = [entityQ, ageQ, placeQ]
     questionnaire = FormModel.new_from_doc(self.dbm, document)
     self.maxDiff = None
     self.assertListEqual(questionnaire.entity_type, ["Reporter"])
     self.assertEqual(questionnaire.name, "New Project")
     self.assertEqual(questionnaire.type, "survey")
     for i in range(len(questions)):
         self.assertEqual(questionnaire.fields[i]._to_json(), questions[i]._to_json())
コード例 #3
0
 def test_should_create_a_questionnaire_from_dictionary(self):
     fields = [{
         "name": "What are you reporting on?",
         "defaultValue": "",
         "label": {
             "eng": "Entity being reported on"
         },
         "entity_question_flag": True,
         "type": "text",
         "ddtype": self.default_ddtype.to_json(),
         "code": "eid",
         "length": {
             "min": 1,
             "max": 10
         },
     }, {
         "range": {
             "max": 10,
             "min": 0
         },
         "label": {
             "eng": ""
         },
         "type": "integer",
         "ddtype": self.default_ddtype.to_json(),
         "name": "What is your age?",
         "code": "AGE"
     }, {
         "choices": [{
             "text": {
                 "eng": "Pune"
             }
         }, {
             "text": {
                 "eng": "Bangalore"
             }
         }],
         "label": {
             "eng": ""
         },
         "type":
         "select",
         "ddtype":
         self.default_ddtype.to_json(),
         "name":
         "Where do you live?",
         "code":
         "PLC"
     }]
     document = FormModelDocument()
     document.json_fields = fields
     document.entity_type = ["Reporter"]
     document.document_type = "FormModel"
     document.form_code = "F1"
     document.name = "New Project"
     document.type = "survey"
     document.type = "survey"
     entityQ = TextField(name="What are you reporting on?",
                         code="eid",
                         label="Entity being reported on",
                         entity_question_flag=True,
                         length=TextConstraint(min=1, max=10),
                         ddtype=self.default_ddtype)
     ageQ = IntegerField(name="What is your age?",
                         code="AGE",
                         label="",
                         range=NumericConstraint(min=0, max=10),
                         ddtype=self.default_ddtype)
     placeQ = SelectField(name="Where do you live?",
                          code="PLC",
                          label="",
                          options=[{
                              "text": {
                                  "eng": "Pune"
                              }
                          }, {
                              "text": {
                                  "eng": "Bangalore"
                              }
                          }],
                          single_select_flag=False,
                          ddtype=self.default_ddtype)
     questions = [entityQ, ageQ, placeQ]
     questionnaire = FormModel.new_from_doc(self.dbm, document)
     self.maxDiff = None
     self.assertListEqual(questionnaire.entity_type, ["Reporter"])
     self.assertEqual(questionnaire.name, "New Project")
     self.assertEqual(questionnaire.type, "survey")
     for i in range(len(questions)):
         self.assertEqual(questionnaire.fields[i]._to_json(),
                          questions[i]._to_json())