diff --git a/src/main.py b/src/main.py index 95975db..f78fe93 100644 --- a/src/main.py +++ b/src/main.py @@ -191,6 +191,13 @@ def handle_switch_fingerprint(password_manager: PasswordManager): return selected_fingerprint = fingerprints[int(choice) - 1] + if selected_fingerprint == password_manager.current_fingerprint: + print( + colored( + f"Seed profile {selected_fingerprint} is already active.", "yellow" + ) + ) + return if password_manager.select_fingerprint(selected_fingerprint): print(colored(f"Switched to seed profile {selected_fingerprint}.", "green")) else: diff --git a/src/tests/test_handle_switch_fingerprint.py b/src/tests/test_handle_switch_fingerprint.py new file mode 100644 index 0000000..ec40ce6 --- /dev/null +++ b/src/tests/test_handle_switch_fingerprint.py @@ -0,0 +1,32 @@ +from main import handle_switch_fingerprint + + +def test_handle_switch_fingerprint_active_profile(monkeypatch, capsys): + class DummyFingerprintManager: + def __init__(self): + self.fingerprints = ["fp1", "fp2"] + + def list_fingerprints(self): + return self.fingerprints + + def display_name(self, fp): + return fp + + class DummyPM: + def __init__(self): + self.fingerprint_manager = DummyFingerprintManager() + self.current_fingerprint = "fp1" + self.decrypted = False + + def select_fingerprint(self, fingerprint): + self.decrypted = True + return True + + pm = DummyPM() + monkeypatch.setattr("builtins.input", lambda _: "1") + + handle_switch_fingerprint(pm) + + captured = capsys.readouterr() + assert "already active" in captured.out.lower() + assert pm.decrypted is False