diff --git a/met-api/tests/unit/services/test_report_settings.py b/met-api/tests/unit/services/test_report_settings.py new file mode 100644 index 000000000..3358dc139 --- /dev/null +++ b/met-api/tests/unit/services/test_report_settings.py @@ -0,0 +1,35 @@ +# Copyright © 2019 Province of British Columbia +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +"""Tests for the report settings service. + +Test suite to ensure that the Survey report settings service routines are working as expected. +""" +from met_api.services.report_setting_service import ReportSettingService +from tests.utilities.factory_scenarios import TestSurveyInfo +from tests.utilities.factory_utils import factory_survey_and_eng_model + + +def test_refresh_report_setting(session): # pylint:disable=unused-argument + """Assert that an Org can be created.""" + survey, _ = factory_survey_and_eng_model(TestSurveyInfo.survey3) + survey_data = { + 'id': survey.id, + 'form_json': survey.form_json, + } + result = ReportSettingService.refresh_report_setting(survey_data) + assert result == survey_data + + report_settings = ReportSettingService.get_report_setting(survey.id) + assert len(report_settings) == 1 + assert report_settings[0].get('survey_id') == survey.id diff --git a/met-api/tests/utilities/factory_scenarios.py b/met-api/tests/utilities/factory_scenarios.py index db7024f4e..e0b1fcaf6 100644 --- a/met-api/tests/utilities/factory_scenarios.py +++ b/met-api/tests/utilities/factory_scenarios.py @@ -28,6 +28,7 @@ from met_api.constants.widget import WidgetType from met_api.utils.enums import LoginSource + fake = Faker() CONFIG = get_named_config('testing') @@ -526,3 +527,21 @@ class TestEngagementSlugInfo(dict, Enum): 'slug': fake.text(max_nb_chars=20), 'created_date': datetime.now().strftime('%Y-%m-%d'), } + + +class TestReportSettingInfo(dict, Enum): + """Test scenarios of feedback.""" + + report_setting_1 = { + "created_by": str(fake.pyint()), + "created_date": datetime.now().strftime('%Y-%m-%d'), + "display": True, + "id": 1, + "question": "What is your opinion about this?", + "question_id": str(fake.pyint()), + "question_key": "simpletextarea", + "question_type": "simpletextarea", + "survey_id": 1, + "updated_by": str(fake.pyint()), + "updated_date": datetime.now().strftime('%Y-%m-%d') + } diff --git a/met-api/tests/utilities/factory_utils.py b/met-api/tests/utilities/factory_utils.py index 0bf322b08..2a5d5b781 100644 --- a/met-api/tests/utilities/factory_utils.py +++ b/met-api/tests/utilities/factory_utils.py @@ -29,6 +29,7 @@ from met_api.models.feedback import Feedback as FeedbackModel from met_api.models.membership import Membership as MembershipModel from met_api.models.participant import Participant as ParticipantModel +from met_api.models.report_setting import ReportSetting as ReportSettingModel from met_api.models.staff_user import StaffUser as StaffUserModel from met_api.models.submission import Submission as SubmissionModel from met_api.models.subscription import Subscription as SubscriptionModel @@ -40,8 +41,8 @@ from met_api.utils.enums import MembershipStatus from tests.utilities.factory_scenarios import ( TestCommentInfo, TestEngagementInfo, TestEngagementSlugInfo, TestFeedbackInfo, TestParticipantInfo, - TestSubmissionInfo, TestSurveyInfo, TestTenantInfo, TestUserInfo, TestWidgetDocumentInfo, TestWidgetInfo, - TestWidgetItemInfo) + TestReportSettingInfo, TestSubmissionInfo, TestSurveyInfo, TestTenantInfo, TestUserInfo, TestWidgetDocumentInfo, + TestWidgetInfo, TestWidgetItemInfo) CONFIG = get_named_config('testing') @@ -301,3 +302,17 @@ def factory_engagement_slug_model(eng_slug_info: dict = TestEngagementSlugInfo.s ) slug.save() return slug + + +def factory_survey_report_setting_model(eng_slug_info: dict = TestReportSettingInfo.report_setting_1): + """Produce a engagement model.""" + setting = ReportSettingModel( + survey_id=eng_slug_info.get('survey_id'), + question_id=eng_slug_info.get('question_id'), + question_key=eng_slug_info.get('question_key'), + question_type=eng_slug_info.get('question_type'), + question=eng_slug_info.get('question'), + display=eng_slug_info.get('display'), + ) + setting.save() + return setting