Skip to content

Commit

Permalink
Add service test
Browse files Browse the repository at this point in the history
  • Loading branch information
jadmsaadaot committed Jul 7, 2023
1 parent b61dc77 commit a621101
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 2 deletions.
35 changes: 35 additions & 0 deletions met-api/tests/unit/services/test_report_settings.py
Original file line number Diff line number Diff line change
@@ -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
19 changes: 19 additions & 0 deletions met-api/tests/utilities/factory_scenarios.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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')
}
19 changes: 17 additions & 2 deletions met-api/tests/utilities/factory_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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')
Expand Down Expand Up @@ -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

0 comments on commit a621101

Please sign in to comment.