예제 #1
0
    def test_should_save_submissions_when_the_limit_not_exceeded(self):
        submission_quota_service = MagicMock()
        submission_quota_service.has_exceeded_quota_and_notify_users.return_value = False
        user_profile = MagicMock()
        valid_rows = [{"key": "value1"}, {"key": "value2"}]
        with patch(
                "datawinners.project.submission.submission_import.SurveyResponseService"
        ) as SurveyResponseService:
            service, project, user, form_model = Mock(), Mock(), Mock(
            ), MagicMock()
            SurveyResponseService.return_value = service
            project.is_summary_project.return_value = False
            user_profile.reporter_id = "some_rep_id"
            submission_persister = SubmissionPersister(
                user, None, None, form_model, submission_quota_service)

            ignored_entries, saved_entries = submission_persister.save_submissions(
                True, user_profile, valid_rows)

            self.assertEqual(saved_entries, [{
                "key": "value1"
            }, {
                "key": "value2"
            }])
            self.assertEqual(ignored_entries, [])
예제 #2
0
    def test_should_save_survey_with_uploaded_entrys_report_id_for_summary_project_when_user_is_logged_in(
            self):
        submission_quota_service = MagicMock()
        submission_quota_service.has_exceeded_quota_and_notify_users.return_value = False
        user_profile = MagicMock()
        expected_reporter_id = "rep_1"
        valid_row = {"eid": expected_reporter_id}
        valid_rows = [valid_row]
        with patch(
                "datawinners.project.submission.submission_import.SurveyResponseService"
        ) as SurveyResponseService:
            service, project, user, form_model = Mock(), MagicMock(), Mock(
            ), MagicMock()

            SurveyResponseService.return_value = service
            project.is_summary_project.return_value = True
            form_model.form_code = "form_code"
            default_ddtype = DataDictType(Mock(spec=DatabaseManager),
                                          name='Default String Datadict Type',
                                          slug='string_default',
                                          primitive_type='string')
            form_model.fields = [
                TextField(name="Q1",
                          code="EID",
                          label="What is the reporter ID?",
                          entity_question_flag=True,
                          ddtype=default_ddtype)
            ]
            form_model.entity_question.code = "eid"

            submission_persister = SubmissionPersister(
                user, None, None, form_model, project,
                submission_quota_service)
            with patch(
                    "datawinners.project.submission.submission_import.get_web_transport_info"
            ) as get_web_transport_info:
                with patch(
                        "datawinners.project.submission.submission_import.get_feed_dictionary"
                ) as get_feed_dictionary:
                    transport_info = None
                    additional_feed_dictionary = None
                    get_feed_dictionary.return_value = additional_feed_dictionary
                    get_web_transport_info.return_value = transport_info

                    submission_persister.save_submissions(
                        True, user_profile, valid_rows)

                    service.save_survey.assert_called_with(
                        "form_code", valid_row, [], transport_info, valid_row,
                        expected_reporter_id, additional_feed_dictionary)
예제 #3
0
    def test_should_save_survey_with_uploaded_entries_report_id_for_summary_project_when_user_is_logged_in(
            self):
        submission_quota_service = MagicMock()
        submission_quota_service.has_exceeded_quota_and_notify_users.return_value = False
        user_profile = MagicMock()
        expected_reporter_id = "rep_1"
        user_profile.reporter_id = expected_reporter_id
        valid_row = {"dsid": expected_reporter_id}
        valid_rows = [valid_row]
        with patch(
                "datawinners.project.submission.submission_import.SurveyResponseService"
        ) as SurveyResponseService:
            service, project, user, form_model = Mock(), MagicMock(), Mock(
            ), MagicMock()

            SurveyResponseService.return_value = service
            project.is_summary_project.return_value = True
            form_model.form_code = "form_code"
            form_model.fields = [
                TextField(name="test", code="test", label="test")
            ]

            submission_persister = SubmissionPersister(
                user, None, None, form_model, submission_quota_service)
            with patch(
                    "datawinners.project.submission.submission_import.get_web_transport_info"
            ) as get_web_transport_info:
                with patch(
                        "datawinners.project.submission.submission_import.get_feed_dictionary"
                ) as get_feed_dictionary:
                    transport_info = None
                    additional_feed_dictionary = None
                    get_feed_dictionary.return_value = additional_feed_dictionary
                    get_web_transport_info.return_value = transport_info

                    submission_persister.save_submissions(
                        True, user_profile, valid_rows)

                    service.save_survey.assert_called_with(
                        "form_code", valid_row, [], transport_info,
                        expected_reporter_id, additional_feed_dictionary)
예제 #4
0
    def test_should_check_quotas_and_update_users_on_saving_submissions(self):
        submission_quota_service = MagicMock()
        submission_quota_service.has_exceeded_quota_and_notify_users.return_value = False
        user_profile = MagicMock()
        valid_rows = [{}]
        with patch(
                "datawinners.project.submission.submission_import.SurveyResponseService"
        ) as SurveyResponseService:
            service, project, user, form_model = Mock(), Mock(), Mock(
            ), MagicMock()
            SurveyResponseService.return_value = service
            project.is_summary_project.return_value = True
            user_profile.reporter_id = "some_rep_id"
            submission_persister = SubmissionPersister(
                user, None, None, form_model, submission_quota_service)

            submission_persister.save_submissions(True, user_profile,
                                                  valid_rows)
            self.assertEqual(
                submission_quota_service.increment_web_submission_count.
                call_count, 1)