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 = EntityFormModel(dbm=dbm, entity_type=entity_type) 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_call_subject_mapping_update_for_registration_form_model( self): dbm = Mock(spec=DatabaseManager) form_model_document = Mock(spec=EntityFormModelDocument) form_model_document.form_code = "clinic" with patch( "mangrove.form_model.form_model.EntityFormModel.new_from_doc" ) as new_from_doc: with patch("datawinners.search.mapping.create_subject_mapping" ) as create_subject_mapping: entity_form_model = EntityFormModel(dbm) entity_form_model._doc = form_model_document new_from_doc.return_value = entity_form_model entity_form_model_change_handler(form_model_document, dbm) assert create_subject_mapping.called
def test_subject_index_dict(self): dbm = Mock(spec=DatabaseManager) entity_type = ['entity_type'] mock_entity = Entity(dbm=dbm, entity_type=entity_type) mock_entity.add_data(data=[('name1', 'ans1'), ('name2', 'ans2')]) with patch.object(Entity, 'get') as get: get.return_value = mock_entity form_model = EntityFormModel(dbm=dbm, entity_type=entity_type) form_model.add_field(TextField('name1', 'code1', 'label1')) form_model.add_field(TextField('name2', 'code2', 'label2')) 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_set_entity_type_in_doc(self): entity_form_model = EntityFormModel(self.manager) entity_form_model._doc = FormModelDocument() entity_form_model.entity_type = ["WaterPoint", "Dam"] self.assertEqual(entity_form_model.entity_type, ["WaterPoint", "Dam"])