def create_and_submit(self, user): """ Helper method that lets us create new SoftwareSecurePhotoVerifications """ attempt = SoftwareSecurePhotoVerification(user=user) attempt.upload_face_image("Fake Data") attempt.upload_photo_id_image("More Fake Data") attempt.mark_ready() attempt.submit() attempt.expiry_date = now() + timedelta(days=FAKE_SETTINGS["DAYS_GOOD_FOR"]) return attempt
def test_deprecated_expiry_date(self): """ Test `expiration_datetime` returns `expiry_date` if it is not null. """ user = UserFactory.create() with freeze_time(now()): verification = SoftwareSecurePhotoVerification(user=user) # First, assert that expiration_date is set correctly assert verification.expiration_datetime == ( now() + timedelta(days=FAKE_SETTINGS['DAYS_GOOD_FOR'])) verification.expiry_date = now() + timedelta(days=10) # Then, assert that expiration_datetime favors expiry_date's value if set assert verification.expiration_datetime == (now() + timedelta(days=10))
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.expiry_date = now() - timedelta(days=FAKE_SETTINGS['DAYS_GOOD_FOR']) verification.status = 'approved' verification.save() self.assertIsNone(verification.expiry_email_date) SoftwareSecurePhotoVerification.update_expiry_email_date_for_user(user, email_config) result = SoftwareSecurePhotoVerification.get_recent_verification(user=user) self.assertIsNotNone(result.expiry_email_date)
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.expiry_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) self.assertIsNotNone(recent_verification) self.assertEqual(recent_verification.id, attempt.id)