def test_expiration_date_null(self): """ Test if the `expiration_date` field is null, `expiration_datetime` returns a default expiration date based on the time the entry was created. """ user = UserFactory.create() verification = SoftwareSecurePhotoVerification(user=user) verification.expiration_date = None verification.save() assert verification.expiration_datetime == ( verification.created_at + timedelta(days=FAKE_SETTINGS['DAYS_GOOD_FOR']))
def test_get_recent_verification(self): """Test that method 'get_recent_verification' of model 'SoftwareSecurePhotoVerification' always returns the most recent 'approved' verification based on updated_at set against a user. """ user = UserFactory.create() attempt = None for _ in range(2): # Make an approved verification attempt = SoftwareSecurePhotoVerification(user=user) attempt.status = PhotoVerification.STATUS.approved attempt.expiration_date = datetime.now() attempt.save() # Test method 'get_recent_verification' returns the most recent # verification attempt based on updated_at recent_verification = SoftwareSecurePhotoVerification.get_recent_verification( user=user) assert recent_verification is not None assert recent_verification.id == attempt.id
def test_update_expiry_email_date_for_user(self): """Test that method update_expiry_email_date_for_user of model 'SoftwareSecurePhotoVerification' set expiry_email_date if the most recent approved verification is expired. """ email_config = getattr(settings, 'VERIFICATION_EXPIRY_EMAIL', { 'DAYS_RANGE': 1, 'RESEND_DAYS': 15 }) user = UserFactory.create() verification = SoftwareSecurePhotoVerification(user=user) verification.expiration_date = now() - timedelta( days=FAKE_SETTINGS['DAYS_GOOD_FOR']) verification.status = PhotoVerification.STATUS.approved verification.save() assert verification.expiry_email_date is None SoftwareSecurePhotoVerification.update_expiry_email_date_for_user( user, email_config) result = SoftwareSecurePhotoVerification.get_recent_verification( user=user) assert result.expiry_email_date is not None