Add unit tests

This commit is contained in:
zandercymatics 2024-04-23 14:25:48 -06:00
parent d1fcb922c6
commit 883595ba44
No known key found for this signature in database
GPG key ID: FF4636ABEC9682B7
2 changed files with 12 additions and 3 deletions

View file

@ -158,7 +158,7 @@ class User(AbstractUser):
Given pre-existing data from TransitionDomain, VerifiedByStaff, and DomainInvitation,
set the verification "type" defined in VerificationTypeChoices.
"""
email_or_username = self.email or self.username
email_or_username = self.email if self.email else self.username
retrieved = DomainInvitation.DomainInvitationStatus.RETRIEVED
verification_type = self.get_verification_type_from_email(email_or_username, invitation_status=retrieved)
@ -173,7 +173,7 @@ class User(AbstractUser):
# If you joined BEFORE the oldest invitation was created, then you were verified normally.
# (See logic in get_verification_type_from_email)
if self.date_joined < invitation.created_at:
if invitation is not None and self.date_joined < invitation.created_at:
verification_type = User.VerificationTypeChoices.REGULAR
self.verification_type = verification_type

View file

@ -58,13 +58,21 @@ class TestPopulateVerificationType(MockEppLib):
)
self.grandfathered_user, _ = User.objects.get_or_create(username="grandpa@igormail.gov")
invited, _ = DomainInvitation.objects.get_or_create(email="invited@igormail.gov", domain=self.domain_1)
invited, _ = DomainInvitation.objects.get_or_create(
email="invited@igormail.gov", domain=self.domain_1, status=DomainInvitation.DomainInvitationStatus.RETRIEVED
)
self.invited_user, _ = User.objects.get_or_create(username="invited@igormail.gov")
self.untouched_user, _ = User.objects.get_or_create(
username="iaminvincible@igormail.gov", verification_type=User.VerificationTypeChoices.GRANDFATHERED
)
# Fixture users should be untouched by the script. These will auto update once the
# user logs in / creates an account.
self.fixture_user, _ = User.objects.get_or_create(
username="fixture@igormail.gov", verification_type=User.VerificationTypeChoices.FIXTURE_USER
)
def tearDown(self):
"""Deletes all DB objects related to migrations"""
super().tearDown()
@ -112,6 +120,7 @@ class TestPopulateVerificationType(MockEppLib):
self.assertEqual(self.invited_user.verification_type, User.VerificationTypeChoices.INVITED)
self.assertEqual(self.verified_by_staff_user.verification_type, User.VerificationTypeChoices.VERIFIED_BY_STAFF)
self.assertEqual(self.untouched_user.verification_type, User.VerificationTypeChoices.GRANDFATHERED)
self.assertEqual(self.fixture_user.verification_type, User.VerificationTypeChoices.FIXTURE_USER)
class TestPopulateOrganizationType(MockEppLib):