Ejemplo n.º 1
0
 def test_generate_otp_WHEN_called_AND_hashed_otp_already_exists_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(OTPGenerationFailedException):
         otp.generate_otp()
Ejemplo n.º 2
0
    def test_generate_otp_WHEN_called_AND_hashed_otp_is_none_THEN_calls_encoder_to_hash(
            self, randint_mock):
        randint_mock.return_value = self.otp_code

        otp = OTP(
            method=self.otp_method,
            to=self.to,
            encoder=self.hash_stub,
            status=OTPStatusEnum.PENDING.value,
        )

        otp.generate_otp()

        self.hash_stub.to_hash.assert_called_once_with(password=self.otp_code)
Ejemplo n.º 3
0
    def test_generate_otp_WHEN_called_AND_hashed_otp_is_none_THEN_set_hashed_otp(
            self, randint_mock):
        randint_mock.return_value = self.otp_code

        expected_hashed_code = self.hashed_otp

        otp = OTP(
            method=self.otp_method,
            to=self.to,
            encoder=self.hash_stub,
            status=OTPStatusEnum.PENDING.value,
        )

        otp.generate_otp()

        actual_hashed_code = otp.hashed_otp

        self.assertEqual(expected_hashed_code, actual_hashed_code)
Ejemplo n.º 4
0
    def test_generate_otp_WHEN_called_AND_hashed_otp_is_none_THEN_calls_randint(
            self, randint_mock):
        randint_mock.return_value = self.otp_code

        expected_call_arguments = (0, 999999)

        otp = OTP(
            method=self.otp_method,
            to=self.to,
            encoder=self.hash_stub,
            status=OTPStatusEnum.PENDING.value,
        )

        otp.generate_otp()

        actual_call_arguments = randint_mock.call_args[0]

        self.assertEqual(expected_call_arguments, actual_call_arguments)