def test_verify_WHEN_called_AND_status_is_validated_THEN_raise_exception( self): otp = OTP( method=self.otp_method, to=self.to, hashed_otp=self.hashed_otp, encoder=self.hash_stub, status=OTPStatusEnum.VALIDATED.value, ) with self.assertRaises(OTPVerificationFailedException): otp.verify(self.invalid_otp_code)
def test_verify_WHEN_called_with_incorrect_otp_AND_status_is_pending_THEN_raise_exception( self, ): otp = OTP( method=self.otp_method, to=self.to, hashed_otp=self.hashed_otp, encoder=self.hash_stub, status=OTPStatusEnum.PENDING.value, ) with self.assertRaises(OTPVerificationFailedException): otp.verify(self.invalid_otp_code)
def test_verify_WHEN_called_AND_status_is_pending_THEN_calls_encoder_compare( self): otp = OTP( method=self.otp_method, to=self.to, hashed_otp=self.hashed_otp, encoder=self.hash_stub, status=OTPStatusEnum.PENDING.value, ) otp.verify(self.otp_code) self.hash_stub.compare.assert_called_once_with(string=self.otp_code, hashed=self.hashed_otp)
def test_verify_WHEN_called_with_correct_otp_AND_status_is_pending_THEN_set_status_to_validated( self, ): expected_status = OTPStatusEnum.VALIDATED.value otp = OTP( method=self.otp_method, to=self.to, hashed_otp=self.hashed_otp, encoder=self.hash_stub, status=OTPStatusEnum.PENDING.value, ) otp.verify(self.otp_code) actual_status = otp.status self.assertEqual(expected_status, actual_status)