'Test that method \'get_initial_verification\' of model
\'SoftwareSecurePhotoVerification\' always returns the initial
verification with field \'photo_id_key\' set against a user.'

def test_initial_verification_for_user(self):

    user = UserFactory.create()
    result = SoftwareSecurePhotoVerification.get_initial_verification(user=user)
    self.assertIs(result, None)
    attempt = SoftwareSecurePhotoVerification(user=user, photo_id_key='dummy_photo_id_key')
    attempt.status = 'approved'
    attempt.save()
    first_result = SoftwareSecurePhotoVerification.get_initial_verification(user=user)
    self.assertIsNotNone(first_result)
    attempt = SoftwareSecurePhotoVerification(user=user)
    attempt.status = 'submitted'
    attempt.save()
    second_result = SoftwareSecurePhotoVerification.get_initial_verification(user=user)
    self.assertIsNotNone(second_result)
    self.assertEqual(second_result, first_result)
    expired_future = (datetime.utcnow() + timedelta(days=(FAKE_SETTINGS['DAYS_GOOD_FOR'] + 1)))
    with freeze_time(expired_future):
        third_result = SoftwareSecurePhotoVerification.get_initial_verification(user)
        self.assertIsNone(third_result)
    expired_future = (datetime.utcnow() + timedelta(days=(FAKE_SETTINGS['DAYS_GOOD_FOR'] + 1)))
    earliest_allowed = (datetime.utcnow() - timedelta(days=1))
    with freeze_time(expired_future):
        fourth_result = SoftwareSecurePhotoVerification.get_initial_verification(user, earliest_allowed)
        self.assertIsNotNone(fourth_result)
        self.assertEqual(fourth_result, first_result)
