From 82ef6adec6e59f9cc9dc9fa1a13a2b43e534bada Mon Sep 17 00:00:00 2001 From: Simeon Simeonov Date: Sat, 28 Dec 2024 20:13:43 +0100 Subject: Rename *Exception to *Error and do some general linting --- test/test_generator.py | 55 +++++++++++++++++++++++++------------------------- test/test_main.py | 3 +-- test/test_server.py | 15 +++++++------- 3 files changed, 35 insertions(+), 38 deletions(-) (limited to 'test') diff --git a/test/test_generator.py b/test/test_generator.py index b4bb961..4329ae4 100644 --- a/test/test_generator.py +++ b/test/test_generator.py @@ -1,7 +1,6 @@ -# -*- coding: utf-8 -*- # SPDX-License-Identifier: BSD-2-Clause-FreeBSD # -# Copyright (c) 2020-2023, Simeon Simeonov +# Copyright (c) 2020-2025, Simeon Simeonov # All rights reserved. # # Redistribution and use in source and binary forms, with or without @@ -36,25 +35,25 @@ def test_caller_exceptions(): 'TeSt', otp2289.OTP_ALGO_MD5, ) - with pytest.raises(otp2289.OTPGeneratorException) as exc_info: + with pytest.raises(otp2289.OTPGeneratorError) as exc_info: gen.generate_otp_words('3') - assert exc_info.type is otp2289.OTPGeneratorException + assert exc_info.type is otp2289.OTPGeneratorError assert exc_info.value.args[0] == 'Step value MUST be an int' - with pytest.raises(otp2289.OTPGeneratorException) as exc_info: + with pytest.raises(otp2289.OTPGeneratorError) as exc_info: gen.generate_otp_hexdigest(-1) - assert exc_info.type is otp2289.OTPGeneratorException + assert exc_info.type is otp2289.OTPGeneratorError assert exc_info.value.args[0] == 'Step value MUST be >= 0' - with pytest.raises(otp2289.OTPChallengeException) as exc_info: + with pytest.raises(otp2289.OTPChallengeError) as exc_info: gen.generate_otp_hexdigest_from_challenge(b'md5 fbd TeSt') - assert exc_info.type is otp2289.OTPChallengeException + assert exc_info.type is otp2289.OTPChallengeError assert exc_info.value.args[0] == 'Challenge must be str' - with pytest.raises(otp2289.OTPChallengeException) as exc_info: + with pytest.raises(otp2289.OTPChallengeError) as exc_info: gen.generate_otp_hexdigest_from_challenge('md5 fbd TeSt') - assert exc_info.type is otp2289.OTPChallengeException + assert exc_info.type is otp2289.OTPChallengeError assert exc_info.value.args[0] == 'Invalid challenge' - with pytest.raises(otp2289.generator.OTPChallengeException) as exc_info: + with pytest.raises(otp2289.generator.OTPChallengeError) as exc_info: gen.generate_otp_hexdigest_from_challenge('otp-md5 fbd TeSt') - assert exc_info.type is otp2289.generator.OTPChallengeException + assert exc_info.type is otp2289.generator.OTPChallengeError assert exc_info.value.args[0] == 'Invalid challenge' @@ -63,74 +62,74 @@ def test_constructor_exceptions(): Tests the exceptions when initializing a new object (in the constructor) """ # test the otp2289.OTPGenerator __init__ and validators - with pytest.raises(otp2289.OTPGeneratorException) as exc_info: + with pytest.raises(otp2289.OTPGeneratorError) as exc_info: otp2289.OTPGenerator( 'This is a test.'.encode(), 'TeStø'.encode(), otp2289.OTP_ALGO_MD5, ) - assert exc_info.type is otp2289.OTPGeneratorException + assert exc_info.type is otp2289.OTPGeneratorError assert exc_info.value.args[0] == 'Seed must be a string' - with pytest.raises(otp2289.OTPGeneratorException) as exc_info: + with pytest.raises(otp2289.OTPGeneratorError) as exc_info: otp2289.OTPGenerator( 'This is a test.'.encode(), 'TeStøtEsTteSTteStTest', otp2289.OTP_ALGO_SHA1, ) - assert exc_info.type is otp2289.OTPGeneratorException + assert exc_info.type is otp2289.OTPGeneratorError assert exc_info.value.args[0] == ( 'The seed MUST be of 1 to 16 characters in length' ) - with pytest.raises(otp2289.OTPGeneratorException) as exc_info: + with pytest.raises(otp2289.OTPGeneratorError) as exc_info: otp2289.OTPGenerator( 'This is a test.'.encode(), 'TeStø', otp2289.OTP_ALGO_SHA1, ) - assert exc_info.type is otp2289.OTPGeneratorException + assert exc_info.type is otp2289.OTPGeneratorError assert exc_info.value.args[0] == ( 'The seed MUST consist of purely alphanumeric characters' ) - with pytest.raises(otp2289.OTPGeneratorException) as exc_info: + with pytest.raises(otp2289.OTPGeneratorError) as exc_info: otp2289.OTPGenerator( 'This is a test.'.encode(), 'TeSt', 9, ) - assert exc_info.type is otp2289.OTPGeneratorException + assert exc_info.type is otp2289.OTPGeneratorError assert exc_info.value.args[0] == ( 'hash_algo is not among the known algorithms' ) - with pytest.raises(otp2289.OTPGeneratorException) as exc_info: + with pytest.raises(otp2289.OTPGeneratorError) as exc_info: otp2289.OTPGenerator( 'This is a test.'.encode(), 'TeSt', b'md5', ) - assert exc_info.type is otp2289.OTPGeneratorException + assert exc_info.type is otp2289.OTPGeneratorError assert exc_info.value.args[0] == 'hash_algo must be an int or a str' # test the package structure as well - with pytest.raises(otp2289.generator.OTPGeneratorException) as exc_info: + with pytest.raises(otp2289.generator.OTPGeneratorError) as exc_info: otp2289.generator.OTPGenerator( 'This is a test.'.encode(), 'TeSt', 'foo', ) - assert exc_info.type is otp2289.generator.OTPGeneratorException + assert exc_info.type is otp2289.generator.OTPGeneratorError assert exc_info.value.args[0] == ( 'foo is not supported by this version of the hashlib module' ) - with pytest.raises(otp2289.OTPGeneratorException) as exc_info: + with pytest.raises(otp2289.OTPGeneratorError) as exc_info: otp2289.OTPGenerator('1234567', 'TeSt', otp2289.OTP_ALGO_MD5) - assert exc_info.type is otp2289.OTPGeneratorException + assert exc_info.type is otp2289.OTPGeneratorError assert exc_info.value.args[0] == 'Password must be a byte-string' - with pytest.raises(otp2289.OTPGeneratorException) as exc_info: + with pytest.raises(otp2289.OTPGeneratorError) as exc_info: otp2289.OTPGenerator( '1234567'.encode(), 'TeSt', otp2289.OTP_ALGO_MD5, ) - assert exc_info.type is otp2289.OTPGeneratorException + assert exc_info.type is otp2289.OTPGeneratorError assert exc_info.value.args[0] == 'Password must be longer than 10 bytes' diff --git a/test/test_main.py b/test/test_main.py index 35bd2a2..593bf80 100644 --- a/test/test_main.py +++ b/test/test_main.py @@ -1,7 +1,6 @@ -# -*- coding: utf-8 -*- # SPDX-License-Identifier: BSD-2-Clause-FreeBSD # -# Copyright (c) 2020-2023, Simeon Simeonov +# Copyright (c) 2020-2025, Simeon Simeonov # All rights reserved. # # Redistribution and use in source and binary forms, with or without diff --git a/test/test_server.py b/test/test_server.py index 64e7f67..e81532f 100644 --- a/test/test_server.py +++ b/test/test_server.py @@ -1,7 +1,6 @@ -# -*- coding: utf-8 -*- # SPDX-License-Identifier: BSD-2-Clause-FreeBSD # -# Copyright (c) 2020-2023, Simeon Simeonov +# Copyright (c) 2020-2025, Simeon Simeonov # All rights reserved. # # Redistribution and use in source and binary forms, with or without @@ -39,9 +38,9 @@ def test_state_caller_exceptions(): 'TeSt', otp2289.OTP_ALGO_MD5, ) - with pytest.raises(otp2289.OTPInvalidResponse) as exc_info: + with pytest.raises(otp2289.OTPInvalidResponseError) as exc_info: state.response_validates('bla') - assert exc_info.type is otp2289.OTPInvalidResponse + assert exc_info.type is otp2289.OTPInvalidResponseError assert exc_info.value.args[0] == ( 'The response is neither a valid token or hex' ) @@ -49,23 +48,23 @@ def test_state_caller_exceptions(): def test_state_constructor_exceptions(): """Tests the exceptions when initializing new OTPState objects""" - with pytest.raises(otp2289.OTPStateException) as exc_info: + with pytest.raises(otp2289.OTPStateError) as exc_info: otp2289.OTPState( '0x7965e05436f5029t', 1, 'TeStø'.encode(), otp2289.OTP_ALGO_MD5, ) - assert exc_info.type is otp2289.OTPStateException + assert exc_info.type is otp2289.OTPStateError assert exc_info.value.args[0] == 'Seed must be a string' - with pytest.raises(otp2289.OTPStateException) as exc_info: + with pytest.raises(otp2289.OTPStateError) as exc_info: otp2289.OTPState( '0x7965e05436f5029t', '1', 'TeSt', otp2289.OTP_ALGO_MD5, ) - assert exc_info.type is otp2289.OTPStateException + assert exc_info.type is otp2289.OTPStateError assert exc_info.value.args[0] == 'Step value MUST be an int' -- cgit v1.3