Skip to content

Commit

Permalink
Updating unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
ratheesh-aot committed Feb 8, 2024
1 parent f6cc977 commit 689e7be
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
5 changes: 3 additions & 2 deletions met-api/tests/unit/api/test_email_verification_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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}',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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')):
Expand Down
12 changes: 10 additions & 2 deletions met-api/tests/utilities/factory_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -121,19 +122,26 @@ 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

email_verification.save()
return email_verification




def factory_engagement_model(eng_info: dict = TestEngagementInfo.engagement1, name=None, status=None):
"""Produce a engagement model."""
engagement = EngagementModel(
Expand Down

0 comments on commit 689e7be

Please sign in to comment.