From 689e7be66aa7e5204a14201f962fbd45f36bb024 Mon Sep 17 00:00:00 2001 From: Ratheesh kumar R Date: Thu, 8 Feb 2024 14:31:09 -0800 Subject: [PATCH] Updating unit test --- .../unit/api/test_email_verification_service.py | 5 +++-- .../unit/services/test_email_verification_service.py | 7 +++++-- met-api/tests/utilities/factory_utils.py | 12 ++++++++++-- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/met-api/tests/unit/api/test_email_verification_service.py b/met-api/tests/unit/api/test_email_verification_service.py index 87bef2173..325425485 100644 --- a/met-api/tests/unit/api/test_email_verification_service.py +++ b/met-api/tests/unit/api/test_email_verification_service.py @@ -41,7 +41,8 @@ def test_email_verification(client, jwt, session, notify_mock, ): # pylint:disa survey, eng = factory_survey_and_eng_model() to_dict = { 'email_address': fake.email(), - 'survey_id': survey.id + 'survey_id': survey.id, + 'type': EmailVerificationType.Survey, } headers = factory_auth_header(jwt=jwt, claims=claims) rv = client.post('/api/email_verification/', data=json.dumps(to_dict), @@ -87,7 +88,7 @@ def test_patch_email_verification_by_token(client, jwt, session): # pylint:disa claims = TestJwtClaims.public_user_role set_global_tenant() survey, eng = factory_survey_and_eng_model() - email_verification = factory_email_verification(survey.id) + email_verification = factory_email_verification(survey.id, EmailVerificationType.Subscribe) headers = factory_auth_header(jwt=jwt, claims=claims) rv = client.put(f'/api/email_verification/{email_verification.verification_token}', diff --git a/met-api/tests/unit/services/test_email_verification_service.py b/met-api/tests/unit/services/test_email_verification_service.py index 2f96cdd14..813cd1b27 100644 --- a/met-api/tests/unit/services/test_email_verification_service.py +++ b/met-api/tests/unit/services/test_email_verification_service.py @@ -23,6 +23,7 @@ from met_api.exceptions.business_exception import BusinessException from met_api.services.email_verification_service import EmailVerificationService +from met_api.constants.email_verification import EmailVerificationType from met_api.utils import notification from tests.utilities.factory_scenarios import TestEngagementSlugInfo from tests.utilities.factory_utils import factory_engagement_slug_model, factory_survey_and_eng_model, set_global_tenant @@ -43,7 +44,8 @@ def test_create_email_verification(client, jwt, session, ): # pylint:disable=un email = fake.email() to_dict = { 'email_address': email, - 'survey_id': survey.id + 'survey_id': survey.id, + 'type': EmailVerificationType.Survey } with patch.object(notification, 'send_email', return_value=False) as mock_mail: EmailVerificationService().create(to_dict) @@ -66,7 +68,8 @@ def test_create_email_verification_exception(client, jwt, session, ): # pylint: email = fake.email() to_dict = { 'email_address': email, - 'survey_id': survey.id + 'survey_id': survey.id, + 'type': EmailVerificationType.Survey } with pytest.raises(BusinessException) as exception: with patch.object(notification, 'send_email', side_effect=Exception('mocked error')): diff --git a/met-api/tests/utilities/factory_utils.py b/met-api/tests/utilities/factory_utils.py index 7d2b8809c..c7fb23278 100644 --- a/met-api/tests/utilities/factory_utils.py +++ b/met-api/tests/utilities/factory_utils.py @@ -50,6 +50,7 @@ from met_api.models.widget_video import WidgetVideo as WidgetVideoModel from met_api.utils.constants import TENANT_ID_HEADER from met_api.utils.enums import MembershipStatus +from met_api.constants.email_verification import EmailVerificationType from tests.utilities.factory_scenarios import ( TestCommentInfo, TestEngagementInfo, TestEngagementMetadataInfo, TestEngagementMetadataTaxonInfo, TestEngagementSlugInfo, TestFeedbackInfo, TestJwtClaims, TestParticipantInfo, TestPollAnswerInfo, @@ -121,12 +122,17 @@ def factory_subscription_model(): return subscription -def factory_email_verification(survey_id): +def factory_email_verification(survey_id, type=None): """Produce a EmailVerification model.""" email_verification = EmailVerificationModel( verification_token=fake.uuid4(), - is_active=True + is_active=True, ) + if type: + email_verification.type = type + else: + email_verification.type = EmailVerificationType.Survey + if survey_id: email_verification.survey_id = survey_id @@ -134,6 +140,8 @@ def factory_email_verification(survey_id): return email_verification + + def factory_engagement_model(eng_info: dict = TestEngagementInfo.engagement1, name=None, status=None): """Produce a engagement model.""" engagement = EngagementModel(