krz/yoshi-cli

Archived

A password manager for the command line. cli password-manager terminal

Commit 51da30891e

51da30891ecb75b2f565ee02b1b3648adaa0f931

parent: 00eaf465f1

Verified · cmc

cmc <hello@cleberg.net> · 2024-11-07 03:17 UTC

add docstrings, fix imports, and disable certain pylint warnings

Layout: unified · split

account.py +1 −2
@@ -12,8 +12,7 @@ class Account:
1212 """Represents a login account."""
1313
1414 def __init__(self, uuid: str, application: str, username: str,
15 password: str, url: str) -> None:
16 self.self = self
15 password: str, url: str) -> None: #pylint: R0913,R0917
1716 self.uuid = uuid
1817 self.application = application
1918 self.username = username
tests/test_crypto.py +26 −3
@@ -1,27 +1,48 @@
1# test_crypto.py
2import unittest
3from io import BytesIO
1"""
2Test file for crypto.py
3"""
4
5import os
46from cryptography.fernet import Fernet
7from io import BytesIO
8from unittest import TestCase
59from crypto import generate_key, load_key, encrypt, decrypt
10from unittest.mock import patch
611
712class TestCryptoFunctions(unittest.TestCase):
13 """
14 This test class checks the functionality of various encryption and
15 decryption functions.
16
17 The tests cover key generation, loading, and usage in both encryption and
18 decryption processes.
19 """
820
921 def setUp(self):
22 """Initialize test environment by generating a new key."""
1023 self.key = generate_key()
1124 with open('vault.sqlite', 'wb') as vault:
1225 vault.write(b'Hello, world!')
1326
1427 def tearDown(self):
28 """Clean up test data after each test."""
1529 try:
1630 os.remove('vault.sqlite')
1731 except FileNotFoundError:
1832 pass
1933
2034 def test_generate_key(self):
35 """Test that generate_key() returns a new key on each call."""
2136 new_key = generate_key()
2237 self.assertNotEqual(new_key, self.key)
2338
2439 def test_load_key(self):
40 """
41 Test that load_key() loads and returns the correct key from file.
42
43 This function also checks for a FileNotFoundError when loading an
44 invalid key file.
45 """
2546 key_file = 'key.bin'
2647 with open(key_file, 'wb') as key:
2748 key.write(self.key)
@@ -29,6 +50,7 @@ class TestCryptoFunctions(unittest.TestCase):
2950 self.assertEqual(loaded_key, self.key)
3051
3152 def test_encrypt_decrypt(self):
53 """Test the end-to-end encryption and decryption process."""
3254 encrypt(self.key, filename='vault.sqlite')
3355 with open('vault.sqlite', 'rb') as vault:
3456 encrypted_data = vault.read()
@@ -39,6 +61,7 @@ class TestCryptoFunctions(unittest.TestCase):
3961 self.assertEqual(f.decrypt(encrypted_data), b'Hello, world!')
4062
4163 def test_load_invalid_key(self):
64 """Test that load_key() raises a FileNotFoundError for invalid key files."""
4265 key_file = 'key.bin'
4366 try:
4467 load_key(key_file)