示例#1
0
    def test_subject_index_dict(self):
        dbm = Mock(spec=DatabaseManager)
        entity_type = ['entity_type']

        with patch('datawinners.search.index_utils.get_entity_type_fields'
                   ) as get_entity_type:
            with patch('datawinners.search.index_utils.tabulate_data'
                       ) as tabulate_data:
                get_entity_type.return_value = ['name1', 'name2'
                                                ], ['label1', 'label2'
                                                    ], ['code1', 'code2']
                mock_entity = Mock(spec=Entity)
                mock_entity.is_void.return_value = False
                tabulate_data.return_value = {'cols': ['ans1', 'ans2']}
                with patch.object(Entity, 'get') as get:
                    get.return_value = mock_entity
                    form_model = FormModel(dbm=dbm,
                                           entity_type=entity_type,
                                           is_registration_model=True)
                    form_model._doc = Mock(form_code="abc", id='form_id')
                    entity_doc = Mock()

                    result = subject_dict(entity_type, entity_doc, dbm,
                                          form_model)

                    expected = {
                        'form_id_code1': 'ans1',
                        'form_id_code2': 'ans2',
                        'entity_type': ['entity_type'],
                        'void': False
                    }
                    self.assertEquals(result, expected)
 def test_should_update_submission_index_date_field_with_current_format(
         self):
     dd_type = Mock(spec=DataDictType)
     fields = [
         TextField(name="entity_question",
                   code="EID",
                   label="What is associated entity",
                   entity_question_flag=True,
                   ddtype=dd_type),
         DateField("date", "date", "Date", "dd.mm.yyyy", dd_type)
     ]
     form_model = FormModel(dbm=Mock(spec=DatabaseManager),
                            form_code="001",
                            type="survey",
                            name="form",
                            entity_type=["clinic"],
                            fields=fields)
     form_model._doc.entity_type = ["clinic"]
     values = {'eid': 'cid005', 'date': '12.21.2012'}
     submission_doc = SurveyResponseDocument(values=values,
                                             status="success",
                                             form_model_revision="rev1")
     search_dict = {}
     form_model._doc = Mock(spec=FormModelDocument)
     form_model._doc.rev = "rev2"
     form_model._snapshots = {
         "rev1": [DateField("date", "date", "Date", "mm.dd.yyyy", dd_type)]
     }
     with patch('datawinners.search.submission_index.lookup_entity_name'
                ) as lookup_entity_name:
         lookup_entity_name.return_value = 'Test'
         search_dict = _update_with_form_model_fields(
             Mock(spec=DatabaseManager), submission_doc, search_dict,
             form_model)
         self.assertEquals("21.12.2012", search_dict.get("date"))
示例#3
0
 def test_should_call_submission_mapping_if_not_registration_form_model(
         self):
     dbm = Mock(spec=DatabaseManager)
     form_model_document = Mock(spec=FormModelDocument)
     with patch("mangrove.form_model.form_model.FormModel.new_from_doc"
                ) as new_from_doc:
         with patch("datawinners.search.mapping.create_submission_mapping"
                    ) as create_submission_mapping:
             form_model = FormModel(dbm, form_code='clinic')
             form_model._doc = form_model_document
             new_from_doc.return_value = form_model
             form_model_change_handler(form_model_document, dbm)
             assert create_submission_mapping.called