From 7fd7db9cd12d59f7c523dc2a1a167f7445e5b2f3 Mon Sep 17 00:00:00 2001 From: Simeon Simeonov Date: Mon, 4 May 2026 18:38:58 +0200 Subject: Add support for the %e{key} format and add support for type checkers (ty) --- tests/test_cli.py | 91 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 49 insertions(+), 42 deletions(-) (limited to 'tests/test_cli.py') diff --git a/tests/test_cli.py b/tests/test_cli.py index b7913da..6e28378 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -26,9 +26,13 @@ from etoolkit.__main__ import main @unittest.mock.patch('builtins.input') -def test_decrypt_v1(binput, capsys, config_file, master_password): +def test_decrypt_v1( + binput: unittest.mock.MagicMock, + capsys: pytest.CaptureFixture, + config_file: str, + master_password: str, +) -> None: """Tests v1 decryption via the CLI interface""" - binput.return_value = ( 'enc-val$1$rye0sMGEnd35gOWyISE1FQa6dzS+8/jf6aopMO5tPr4=$' 'RjnRY0bUJWFOiejTlM3OhKNimQ==' @@ -44,15 +48,14 @@ def test_decrypt_v1(binput, capsys, config_file, master_password): @unittest.mock.patch('builtins.input') def test_decrypt_v2( - binput, - capsys, - config_file, - master_password, - short_encrypted_value, - short_value, -): + binput: unittest.mock.MagicMock, + capsys: pytest.CaptureFixture, + config_file: str, + master_password: str, + short_encrypted_value: str, + short_value: str, +) -> None: """Tests v2 decryption via the CLI interface""" - binput.return_value = short_encrypted_value with unittest.mock.patch.dict( os.environ, {'ETOOLKIT_MASTER_PASSWORD': master_password} @@ -68,17 +71,16 @@ def test_decrypt_v2( @unittest.mock.patch('os.urandom') @unittest.mock.patch('builtins.input') def test_encrypt_with_echo( - binput, - urandom, - capsys, - non_random_bytes_57, - config_file, - master_password, - short_encrypted_value, - short_value, -): + binput: unittest.mock.MagicMock, + urandom: unittest.mock.MagicMock, + capsys: pytest.CaptureFixture, + non_random_bytes_57: bytes, + config_file: str, + master_password: str, + short_encrypted_value: str, + short_value: str, +) -> None: """Tests encryption via the CLI interface""" - binput.return_value = short_value urandom.return_value = non_random_bytes_57 with unittest.mock.patch.dict( @@ -95,17 +97,16 @@ def test_encrypt_with_echo( @unittest.mock.patch('os.urandom') @unittest.mock.patch('getpass.getpass') def test_encrypt_without_echo( - getpass, - urandom, - capsys, - non_random_bytes_57, - config_file, - master_password, - short_encrypted_value, - short_value, -): + getpass: unittest.mock.MagicMock, + urandom: unittest.mock.MagicMock, + capsys: pytest.CaptureFixture, + non_random_bytes_57: bytes, + config_file: str, + master_password: str, + short_encrypted_value: str, + short_value: str, +) -> None: """Tests encryption via the CLI interface""" - getpass.return_value = short_value urandom.return_value = non_random_bytes_57 with unittest.mock.patch.dict( @@ -119,20 +120,26 @@ def test_encrypt_without_echo( ) -def test_fetch_encrypted_value(config_file, master_password, short_value): +def test_fetch_encrypted_value( + config_file: str, master_password: str, short_value: str +) -> None: """Tests decryption of encrypted value""" - with unittest.mock.patch.dict( os.environ, {'ETOOLKIT_MASTER_PASSWORD': master_password} ): assert os.environ.get('ETOOLKIT_TEST_PASSWORD') is None - main(['-c', f'{config_file}', '-q', '-s', '/bin/false', 'secret']) + with pytest.raises(SystemExit) as exit_info: + main(['-c', f'{config_file}', '-q', '-s', '/bin/false', 'secret']) + assert exit_info.value.code == 0 assert os.environ.get('ETOOLKIT_TEST_PASSWORD') == short_value -def test_list(capsys, config_file, nonexistent_config_file): +def test_list( + capsys: pytest.CaptureFixture, + config_file: str, + nonexistent_config_file: str, +) -> None: """Tests list via the CLI interface""" - with pytest.raises(SystemExit) as exit_info: main(['-c', nonexistent_config_file, '-l']) assert exit_info.value.code == errno.EIO @@ -142,9 +149,8 @@ def test_list(capsys, config_file, nonexistent_config_file): assert capsys.readouterr().out.strip() == f'dev{os.linesep}secret' -def test_help(capsys): +def test_help(capsys: pytest.CaptureFixture) -> None: """Dummy test checking if the CLI is available at all""" - with pytest.raises(SystemExit) as exit_info: main(['-h']) assert exit_info.value.code == 0 @@ -154,10 +160,12 @@ def test_help(capsys): @unittest.mock.patch('os.urandom') @unittest.mock.patch('getpass.getpass') def test_generate_master_password_hash( - getpass, urandom, capsys, non_random_bytes_32 -): + getpass: unittest.mock.MagicMock, + urandom: unittest.mock.MagicMock, + capsys: pytest.CaptureFixture, + non_random_bytes_32: bytes, +) -> None: """Tests master password hash generation via the CLI interface""" - getpass.return_value = 'The very secret passwd' urandom.return_value = non_random_bytes_32 with pytest.raises(SystemExit) as exit_info: @@ -169,9 +177,8 @@ def test_generate_master_password_hash( ) -def test_version(capsys): +def test_version(capsys: pytest.CaptureFixture) -> None: """Dummy test checking if the CLI is available at all""" - with pytest.raises(SystemExit) as exit_info: main(['-v']) assert exit_info.value.code == 0 -- cgit v1.3