def test_survey_response_is_saved_with_reporter_id_in_upper_case(self):
        test_data = TestData(self.manager)
        survey_response_service = SurveyResponseService(self.manager)

        values = {'ID': test_data.entity1.short_code, 'Q1': 'name', 'Q2': '80', 'Q3': 'a'}
        transport_info = TransportInfo('web', 'src', 'dest')
        request = Request(values, transport_info)
        response = survey_response_service.save_survey('CL1', values, [], transport_info, 'REP2')

        self.assertTrue(response.success)
        self.assertEqual(0, response.errors.__len__())
        self.assertIsNotNone(response.datarecord_id)
        self.assertIsNotNone(response.survey_response_id)
        self.assertEqual(test_data.entity_type, response.entity_type)
        self.assertEqual('CL1', response.form_code)
        self.assertEqual('1', response.short_code)
        self.assertDictEqual(OrderedDict([('Q1', 'name'), ('Q3', ['RED']), ('Q2', 80), ('ID', u'1')]),
                             response.processed_data)

        survey_response = SurveyResponse.get(self.manager, response.survey_response_id)
        self.assertDictEqual({'Q1': 'name', 'Q3': 'a', 'Q2': '80', 'ID': '1'}, survey_response.values)
        self.assertDictEqual({'Q1': 'name', 'Q3': 'a', 'Q2': '80', 'ID': '1'}, survey_response.values)
        self.assertEqual(test_data.form_model.revision, survey_response.form_model_revision)
        self.assertEqual(True, survey_response.status)
        self.assertIsNotNone(survey_response.data_record)
Exemple #2
0
 def delete_survey_response(self,
                            survey_response,
                            additional_details,
                            logger=None):
     assert survey_response is not None
     service = SurveyResponseService(self.dbm, logger, self.feeds_dbm)
     return service.delete_survey(survey_response, additional_details)
 def _save_survey(self, user_profile, valid_row):
     service = SurveyResponseService(self.dbm, logger, self.feed_dbm,
                                     user_profile.reporter_id)
     additional_feed_dictionary = get_feed_dictionary(self.form_model)
     transport_info = get_web_transport_info(self.user.username)
     return service.save_survey(self.form_model.form_code, valid_row, [],
                                transport_info, valid_row.get('dsid'),
                                additional_feed_dictionary)
    def test_survey_response_is_edited_and_new_submission_and_datarecord_is_created(
            self):
        test_data = TestData(self.manager)
        survey_response_service = SurveyResponseService(self.manager)

        values = {
            'ID': test_data.entity1.short_code,
            'Q1': 'name',
            'Q2': '80',
            'Q3': 'a'
        }
        transport_info = TransportInfo('web', 'src', 'dest')
        request = Request(values, transport_info)

        saved_response = survey_response_service.save_survey(
            'CL1', values, [], transport_info, "rep2")
        self.assertDictEqual(
            OrderedDict([('Q1', 'name'), ('Q3', ['RED']), ('Q2', 80),
                         ('ID', u'1')]), saved_response.processed_data)

        new_values = {
            'ID': test_data.entity1.short_code,
            'Q1': 'new_name',
            'Q2': '430',
            'Q3': 'b'
        }
        survey_response_to_edit = SurveyResponse.get(
            self.manager, saved_response.survey_response_id)
        edited_response = survey_response_service.edit_survey(
            'CL1', new_values, [], survey_response_to_edit)

        self.assertTrue(edited_response.success)
        self.assertEqual(0, edited_response.errors.__len__())
        self.assertIsNotNone(edited_response.datarecord_id)
        self.assertIsNotNone(edited_response.survey_response_id)
        self.assertEqual(test_data.entity_type, edited_response.entity_type)
        self.assertEqual('CL1', edited_response.form_code)
        self.assertDictEqual(
            OrderedDict([('Q1', 'new_name'), ('Q3', ['YELLOW']), ('Q2', 430),
                         ('ID', u'1')]), edited_response.processed_data)

        self.assertNotEquals(saved_response.datarecord_id,
                             edited_response.datarecord_id)

        old_data_record = DataRecord.get(self.manager,
                                         saved_response.datarecord_id)
        self.assertTrue(old_data_record.voided)
        new_data_record = DataRecord.get(self.manager,
                                         edited_response.datarecord_id)
        self.assertFalse(new_data_record.voided)

        edited_survey_response = SurveyResponse.get(
            self.manager, edited_response.survey_response_id)
        self.assertEquals(1,
                          len(edited_survey_response._doc.data_record_history))
        self.assertEquals(old_data_record.id,
                          edited_survey_response._doc.data_record_history[0])
    def test_response_has_no_error_when_feed_creation_fails(self):
        manager = Mock(spec=DatabaseManager)
        feed_manager = Mock(spec=DatabaseManager)
        values = {'ID': 'short_code', 'Q1': 'name', 'Q2': '80', 'Q3': 'a'}
        transport_info = TransportInfo('web', 'src', 'dest')
        request = Request(values, transport_info)

        additional_dictionary = {
            'project': {
                'name': 'someproject',
                'status': 'active',
                'id': 'someid'
            }
        }

        survey_response_service = SurveyResponseService(manager,
                                                        feeds_dbm=feed_manager)

        with patch(
                'mangrove.transport.services.survey_response_service.by_short_code'
        ) as get_reporter:
            with patch(
                    'mangrove.transport.services.survey_response_service.get_form_model_by_code'
            ) as get_form_model_by_code:
                with patch('mangrove.datastore.entity.by_short_code'
                           ) as by_short_code:
                    with patch(
                            'mangrove.transport.services.survey_response_service.DataFormSubmission'
                    ) as data_form_submission:
                        with patch(
                                'mangrove.transport.services.survey_response_service.EnrichedSurveyResponseBuilder'
                        ) as builder:
                            get_reporter.return_value = Mock(spec=Entity)
                            builder.feed_document.side_effect = Exception(
                                'Some error')
                            builder.return_value = builder
                            instance_mock = data_form_submission.return_value
                            type(instance_mock).is_valid = PropertyMock(
                                return_value=True)
                            type(instance_mock).data_record_id = PropertyMock(
                                return_value='sdsddsd')
                            type(instance_mock).errors = PropertyMock(
                                return_value='')

                            by_short_code.return_value = Mock(spec=Entity)
                            mock_form_model = MagicMock(spec=FormModel)
                            mock_form_model._dbm = manager
                            mock_form_model._doc = MagicMock()
                            mock_form_model._data = {}
                            mock_form_model.validate_submission.return_value = values, ""
                            get_form_model_by_code.return_value = mock_form_model
                            response = survey_response_service.save_survey(
                                'CL1', values, [], transport_info, '',
                                additional_dictionary)
                            self.assertFalse(response.errors)
                            self.assertTrue(response.feed_error_message)
Exemple #6
0
 def _save_survey(self, is_organization_user, user_profile, valid_row):
     reporter_id = self._get_reporter_id_for_submission(
         is_organization_user, user_profile, valid_row)
     service = SurveyResponseService(self.dbm, logger, self.feed_dbm,
                                     user_profile.reporter_id)
     additional_feed_dictionary = get_feed_dictionary(self.project)
     transport_info = get_web_transport_info(self.user.username)
     return service.save_survey(self.form_model.form_code, valid_row, [],
                                transport_info, valid_row, reporter_id,
                                additional_feed_dictionary)
Exemple #7
0
 def add_survey_response(self,
                         request,
                         reporter_id,
                         additional_feed_dictionary=None,
                         logger=None):
     assert request is not None
     form_code, values = self._parse(request.message)
     service = SurveyResponseService(self.dbm, logger, self.feeds_dbm,
                                     self.admin_id)
     return service.save_survey(form_code, values, [], request.transport,
                                reporter_id, additional_feed_dictionary)
Exemple #8
0
    def _create_survey_response(self, form_model, reporter_id, values, extra_data):
        transport_info = TransportInfo(transport='api', source=reporter_id, destination='')
        response = self._is_request_valid(form_model, reporter_id, extra_data)
        if response.success:
            service = SurveyResponseService(self.dbm)
            response = service.save_survey(form_model.form_code, values, [], transport_info, reporter_id)

            if response.success:
                self._increment_web_counter()
            return response
        else:
            return response
    def test_survey_response_event_created_when_survey_response_created(self):
        manager = Mock(spec=DatabaseManager)
        feed_manager = Mock(spec=DatabaseManager)
        survey_response_service = SurveyResponseService(manager,
                                                        feeds_dbm=feed_manager)

        values = {'ID': 'short_code', 'Q1': 'name', 'Q2': '80', 'Q3': 'a'}
        transport_info = TransportInfo('web', 'src', 'dest')
        request = Request(values, transport_info)

        additional_dictionary = {
            'project': {
                'name': 'someproject',
                'status': 'active',
                'id': 'someid'
            }
        }
        with patch(
                'mangrove.transport.services.survey_response_service.by_short_code'
        ) as get_reporter:
            with patch(
                    'mangrove.transport.services.survey_response_service.get_form_model_by_code'
            ) as get_form_model_by_code:
                with patch('mangrove.datastore.entity.by_short_code'
                           ) as by_short_code:
                    with patch(
                            'mangrove.transport.services.survey_response_service.EnrichedSurveyResponseBuilder'
                    ) as builder:
                        with patch(
                                "mangrove.form_model.form_submission.DataRecordDocument"
                        ) as DataRecordDocumentMock:
                            get_reporter.return_value = Mock(spec=Entity)
                            builder.return_value = Mock(
                                spec=EnrichedSurveyResponseBuilder)
                            entity_mock = MagicMock(spec=Entity)
                            entity_mock._doc = EntityDocument()
                            by_short_code.return_value = entity_mock
                            mock_form_model = MagicMock(spec=FormModel)
                            mock_form_model._dbm = manager
                            mock_form_model._doc = MagicMock()
                            mock_form_model._data = {}
                            mock_form_model.validate_submission.return_value = OrderedDict(
                                values), OrderedDict('')
                            mock_form_model.is_entity_registration_form.return_value = False
                            mock_form_model.entity_questions = []
                            mock_form_model.entity_type = 'sometype'
                            get_form_model_by_code.return_value = mock_form_model
                            survey_response_service.save_survey(
                                'CL1', values, [], transport_info, '',
                                additional_dictionary)
                            self.assertEquals(
                                1, feed_manager._save_document.call_count)
Exemple #10
0
 def add_survey_response(self, request, reporter_id, logger=None):
     assert request is not None
     form_code, values = self._parse(request.message)
     media_submission_service = MediaSubmissionService(
         self.dbm, request.media, form_code)
     media_files = media_submission_service.create_media_documents(values)
     service = SurveyResponseService(self.dbm, logger, self.feeds_dbm)
     response = service.save_survey(form_code, values, [],
                                    request.transport, reporter_id)
     thumbnails = self._add_new_attachments(media_files,
                                            response.survey_response_id)
     media_submission_service.create_preview_documents(thumbnails)
     return response
Exemple #11
0
 def edit_survey_response(self,
                          request,
                          survey_response,
                          owner_id,
                          additional_feed_dictionary=None,
                          logger=None):
     assert request is not None
     form_code, values = self._parse(request.message)
     service = SurveyResponseService(self.dbm,
                                     logger,
                                     feeds_dbm=self.feeds_dbm,
                                     admin_id=self.admin_id)
     return service.edit_survey(form_code, values, [], survey_response,
                                additional_feed_dictionary, owner_id)
Exemple #12
0
def activate_project(request, project_id=None):
    manager = get_database_manager(request.user)
    project = Project.load(manager.database, project_id)
    project.activate(manager)
    form_model = FormModel.get(manager, project.qid)
    oneDay = datetime.timedelta(days=1)
    tomorrow = datetime.datetime.now() + oneDay
    survey_responses = get_survey_responses(manager, form_model.form_code, from_time=0,
                                            to_time=int(mktime(tomorrow.timetuple())) * 1000, page_size=None)
    feeds_dbm = get_feeds_database(request.user)
    service = SurveyResponseService(manager, logger, feeds_dbm)
    additional_feed_dictionary = get_project_details_dict_for_feed(project)
    for survey_response in survey_responses:
        service.delete_survey(survey_response, additional_feed_dictionary)
    UserActivityLog().log(request, action=ACTIVATED_PROJECT, project=project.name)
    return HttpResponseRedirect(reverse('project-overview', args=[project_id]))
    def test_feeds_created_if_subject_not_found_for_a_submission(self):
        manager = Mock(spec=DatabaseManager)
        feed_manager = Mock(spec=DatabaseManager)
        project = Mock(spec=Project)
        values = {'ID': 'short_code', 'Q1': 'name', 'Q2': '80', 'Q3': 'a'}
        transport_info = TransportInfo('web', 'src', 'dest')
        request = Request(values, transport_info)

        additional_dictionary = {'project': {'name': 'someproject', 'status': 'active', 'id': 'someid'}}

        survey_response_service = SurveyResponseService(manager, feeds_dbm=feed_manager)

        with patch('mangrove.transport.services.survey_response_service.by_short_code') as get_reporter:
            with patch(
                    'mangrove.transport.services.survey_response_service.get_form_model_by_code') as get_form_model_by_code:
                with patch('mangrove.datastore.entity.by_short_code') as by_short_code:
                    with patch(
                            'mangrove.transport.services.survey_response_service.DataFormSubmission') as data_form_submission:
                        with patch(
                                'mangrove.transport.services.survey_response_service.EnrichedSurveyResponseBuilder')as builder:
                            with patch('mangrove.transport.services.survey_response_service.Project.from_form_model') as from_form_model:
                                get_reporter.return_value = Mock(spec=Entity)
                                builder.return_value = Mock(spec=EnrichedSurveyResponseBuilder)
                                instance_mock = data_form_submission.return_value
                                type(instance_mock).is_valid = PropertyMock(return_value=True)
                                type(instance_mock).data_record_id = PropertyMock(return_value='sdsddsd')
                                instance_mock.save.side_effect = MangroveException("subject not found")
                                from_form_model.return_value = project
                                project.data_senders = []

                                by_short_code.return_value = Mock(spec=Entity)
                                mock_form_model = MagicMock(spec=FormModel)
                                mock_form_model._dbm = manager
                                mock_form_model._doc = MagicMock()
                                mock_form_model._data = {}
                                mock_form_model.validate_submission.return_value = values, ""
                                get_form_model_by_code.return_value = mock_form_model

                                try:
                                    survey_response_service.save_survey('CL1', values, [], transport_info, '',
                                                                        additional_dictionary)
                                    self.fail('the subject not found exception should be propagated')
                                except MangroveException:
                                    feed_manager._save_document.assert_called_once()
 def test_exception_is_raised_for_invalid_short_code_submissions(self):
     survey_response_service = SurveyResponseService(self.manager)
     with patch(
             'mangrove.transport.services.survey_response_service.get_active_form_model') as mock_get_active_form_model:
         mock_get_active_form_model.side_effect = FormModelDoesNotExistsException("form_code")
         values = {'ID': "invalid", 'Q1': 'name', 'Q2': '80', 'Q3': 'a'}
         transport_info = TransportInfo('web', 'src', 'dest')
         request = Request(values, transport_info)
         self.assertRaises(MangroveException, survey_response_service.save_survey, 'CL1', values, [], transport_info,
                           '')
Exemple #15
0
 def update_survey_response(self,
                            request,
                            logger=None,
                            survey_response=None,
                            additional_feed_dictionary=None):
     assert request is not None
     form_code, values = self._parse(request.message)
     media_submission_service = MediaSubmissionService(self.dbm,
                                                       request.media,
                                                       form_code,
                                                       is_update=True)
     media_files = media_submission_service.create_media_documents(values)
     service = SurveyResponseService(self.dbm, logger, self.feeds_dbm)
     response = service.edit_survey(form_code, values, [], survey_response,
                                    additional_feed_dictionary)
     self._delete_removed_attachments(request, survey_response.id,
                                      media_submission_service)
     thumbnails = self._add_new_attachments(media_files, survey_response.id)
     media_submission_service.create_preview_documents(thumbnails)
     return response
Exemple #16
0
    def add_survey_response(self,
                            request,
                            logger=None,
                            additional_feed_dictionary=None,
                            translation_processor=None):
        form_code, values, extra_elements = self._parse(request.message)
        post_sms_processor_response = self._post_parse_processor(
            form_code, values, extra_elements)

        if post_sms_processor_response is not None and not post_sms_processor_response.success:
            if logger is not None:
                log_entry = "message:message " + repr(
                    request.message
                ) + "|source: " + request.transport.source + "|"
                log_entry += "Status: False"
                logger.info(log_entry)
            return post_sms_processor_response

        try:
            reporter_entity = reporters.find_reporter_entity(
                self.dbm, request.transport.source)
            reporter_entity_names = self._get_reporter_name(reporter_entity)
            reporter_short_code = reporter_entity.short_code
        except NumberNotRegisteredException:
            reporter_short_code = None
            reporter_entity_names = None

        service = SurveyResponseService(self.dbm,
                                        logger,
                                        self.feeds_dbm,
                                        response=post_sms_processor_response)
        return service.save_survey(
            form_code,
            values,
            reporter_entity_names,
            request.transport,
            reporter_short_code,
            additional_feed_dictionary=additional_feed_dictionary,
            translation_processor=translation_processor)
class TestSurveyResponseService(TestCase):
    def setUp(self):
        self.dbm = Mock(spec=DatabaseManager)
        self.survey_response_service = SurveyResponseService(self.dbm)

    def form_model(self):
        question1 = UniqueIdField(unique_id_type='clinic', name="entity_question", code="q1",
                                  label="What is associated entity",
                                  )
        question2 = IntegerField(name="question1_Name", code="q2", label="What is your name",
                                 constraints=[NumericRangeConstraint(min=10, max=100)])
        return FormModel(self.dbm, name="aids", label="Aids form_model",
                         form_code="aids", fields=[question1, question2])

    # TODO : Need to add validations for incompatible data types -> eg. string for number. This validation is hadled outside the service for now.
    def test_edit_survey_response_when_fields_constraints_are_not_satisfied(self):
        survey_response = Mock(spec=SurveyResponse)
        with patch('mangrove.transport.services.survey_response_service.by_short_code') as get_reporter:
            with patch('mangrove.datastore.entity.by_short_code') as get_entity:
                with patch(
                        'mangrove.transport.services.survey_response_service.get_form_model_by_code') as get_form_model:
                    get_reporter.return_value = Mock(spec=Entity)
                    get_entity.return_value = Mock(spec=Entity)
                    get_form_model.return_value = self.form_model()
                    transport_info = TransportInfo('web', 'src', 'dest')
                    values = {'form_code': 'aids', 'q1': 'a1', 'q2': '200'}

                    request = Request(values, transport_info)
                    response = self.survey_response_service.edit_survey('aids', values, [], survey_response)
                    self.assertFalse(response.success)
                    self.assertEquals('aids', response.form_code)
                    self.assertEquals(OrderedDict([('q2', u'Answer 200 for question q2 is greater than allowed.')]),
                                      response.errors)
                    self.assertEquals(['clinic'], response.entity_type)
                    self.assertEquals(OrderedDict([('q1', 'a1')]), response.processed_data)
                    self.assertIsNotNone(response.survey_response_id)

                    assert not survey_response.update.called

    def test_survey_response_event_created_when_survey_response_created(self):
        manager = Mock(spec=DatabaseManager)
        feed_manager = Mock(spec=DatabaseManager)
        project = Mock(spec=Project)
        survey_response_service = SurveyResponseService(manager, feeds_dbm=feed_manager)

        values = {'ID': 'short_code', 'Q1': 'name', 'Q2': '80', 'Q3': 'a'}
        transport_info = TransportInfo('web', 'src', 'dest')
        request = Request(values, transport_info)

        additional_dictionary = {'project': {'name': 'someproject', 'status': 'active', 'id': 'someid'}}
        with patch('mangrove.transport.services.survey_response_service.by_short_code') as get_reporter:
            with patch(
                    'mangrove.transport.services.survey_response_service.get_form_model_by_code') as get_form_model_by_code:
                with patch('mangrove.datastore.entity.by_short_code') as by_short_code:
                    with patch(
                            'mangrove.transport.services.survey_response_service.EnrichedSurveyResponseBuilder')as builder:
                        with patch("mangrove.form_model.form_submission.DataRecordDocument") as DataRecordDocumentMock:
                            with patch('mangrove.transport.services.survey_response_service.Project.from_form_model') as from_form_model:
                                get_reporter.return_value = Mock(spec=Entity)
                                builder.return_value = Mock(spec=EnrichedSurveyResponseBuilder)
                                entity_mock = MagicMock(spec=Entity)
                                entity_mock._doc = EntityDocument()
                                by_short_code.return_value = entity_mock
                                mock_form_model = MagicMock(spec=FormModel)
                                mock_form_model._dbm = manager
                                mock_form_model._doc = MagicMock()
                                mock_form_model._data = {}
                                mock_form_model.validate_submission.return_value = OrderedDict(values), OrderedDict('')
                                mock_form_model.is_entity_registration_form.return_value = False
                                mock_form_model.entity_questions = []
                                mock_form_model.entity_type = 'sometype'
                                get_form_model_by_code.return_value = mock_form_model
                                from_form_model.return_value = project
                                project.data_senders = []
                                survey_response_service.save_survey('CL1', values, [], transport_info, '',
                                                                    additional_dictionary)
                                self.assertEquals(1, feed_manager._save_document.call_count)

    def test_feeds_created_if_subject_not_found_for_a_submission(self):
        manager = Mock(spec=DatabaseManager)
        feed_manager = Mock(spec=DatabaseManager)
        project = Mock(spec=Project)
        values = {'ID': 'short_code', 'Q1': 'name', 'Q2': '80', 'Q3': 'a'}
        transport_info = TransportInfo('web', 'src', 'dest')
        request = Request(values, transport_info)

        additional_dictionary = {'project': {'name': 'someproject', 'status': 'active', 'id': 'someid'}}

        survey_response_service = SurveyResponseService(manager, feeds_dbm=feed_manager)

        with patch('mangrove.transport.services.survey_response_service.by_short_code') as get_reporter:
            with patch(
                    'mangrove.transport.services.survey_response_service.get_form_model_by_code') as get_form_model_by_code:
                with patch('mangrove.datastore.entity.by_short_code') as by_short_code:
                    with patch(
                            'mangrove.transport.services.survey_response_service.DataFormSubmission') as data_form_submission:
                        with patch(
                                'mangrove.transport.services.survey_response_service.EnrichedSurveyResponseBuilder')as builder:
                            with patch('mangrove.transport.services.survey_response_service.Project.from_form_model') as from_form_model:
                                get_reporter.return_value = Mock(spec=Entity)
                                builder.return_value = Mock(spec=EnrichedSurveyResponseBuilder)
                                instance_mock = data_form_submission.return_value
                                type(instance_mock).is_valid = PropertyMock(return_value=True)
                                type(instance_mock).data_record_id = PropertyMock(return_value='sdsddsd')
                                instance_mock.save.side_effect = MangroveException("subject not found")
                                from_form_model.return_value = project
                                project.data_senders = []

                                by_short_code.return_value = Mock(spec=Entity)
                                mock_form_model = MagicMock(spec=FormModel)
                                mock_form_model._dbm = manager
                                mock_form_model._doc = MagicMock()
                                mock_form_model._data = {}
                                mock_form_model.validate_submission.return_value = values, ""
                                get_form_model_by_code.return_value = mock_form_model

                                try:
                                    survey_response_service.save_survey('CL1', values, [], transport_info, '',
                                                                        additional_dictionary)
                                    self.fail('the subject not found exception should be propagated')
                                except MangroveException:
                                    feed_manager._save_document.assert_called_once()

    def test_response_has_no_error_when_feed_creation_fails(self):
        manager = Mock(spec=DatabaseManager)
        feed_manager = Mock(spec=DatabaseManager)
        project = Mock(spec=Project)
        values = {'ID': 'short_code', 'Q1': 'name', 'Q2': '80', 'Q3': 'a'}
        transport_info = TransportInfo('web', 'src', 'dest')
        request = Request(values, transport_info)

        additional_dictionary = {'project': {'name': 'someproject', 'status': 'active', 'id': 'someid'}}

        survey_response_service = SurveyResponseService(manager, feeds_dbm=feed_manager)

        with patch('mangrove.transport.services.survey_response_service.by_short_code') as get_reporter:
            with patch(
                    'mangrove.transport.services.survey_response_service.get_form_model_by_code') as get_form_model_by_code:
                with patch('mangrove.datastore.entity.by_short_code') as by_short_code:
                    with patch(
                            'mangrove.transport.services.survey_response_service.DataFormSubmission') as data_form_submission:
                        with patch(
                                'mangrove.transport.services.survey_response_service.EnrichedSurveyResponseBuilder')as builder:
                            with patch('mangrove.transport.services.survey_response_service.Project.from_form_model') as from_form_model:
                                get_reporter.return_value = Mock(spec=Entity)
                                builder.feed_document.side_effect = Exception('Some error')
                                builder.return_value = builder
                                instance_mock = data_form_submission.return_value
                                type(instance_mock).is_valid = PropertyMock(return_value=True)
                                type(instance_mock).data_record_id = PropertyMock(return_value='sdsddsd')
                                type(instance_mock).errors = PropertyMock(return_value='')

                                by_short_code.return_value = Mock(spec=Entity)
                                mock_form_model = MagicMock(spec=FormModel)
                                mock_form_model._dbm = manager
                                mock_form_model._doc = MagicMock()
                                mock_form_model._data = {}
                                mock_form_model.validate_submission.return_value = values, ""
                                get_form_model_by_code.return_value = mock_form_model
                                from_form_model.return_value = project
                                project.data_senders = []
                                response = survey_response_service.save_survey('CL1', values, [], transport_info, '',
                                                                               additional_dictionary)
                                self.assertFalse(response.errors)
                                self.assertTrue(response.feed_error_message)
 def setUp(self):
     self.dbm = Mock(spec=DatabaseManager)
     self.survey_response_service = SurveyResponseService(self.dbm)