from tempfile import TemporaryDirectory import os.path from mu4web.password import ( Passwords, ) dir = TemporaryDirectory() path = os.path.join(dir.name, 'passwords.json') def test_password() -> None: # Start with a blank store store1 = Passwords(path) # Try to validate a non-existant user (this should fail) assert not store1.validate('hugo', 'password') # Add a user store1.add('hugo', 'password') # Try to validate it (this should succeed) assert store1.validate('hugo', 'password') # Try to validate it with the wrong password (this should not succeed) assert not store1.validate('hugo', 'Hunter2') # Save store to disk store1.save() # Load same store into different instance store2 = Passwords(path) # Check that password was correctly saved. assert store2.validate('hugo', 'password')