clan-core/pkgs/clan-cli/tests/test_history_cli.py

54 lines
1.3 KiB
Python
Raw Normal View History

2023-12-12 12:56:54 +00:00
import json
from typing import TYPE_CHECKING
import pytest
2023-12-12 12:56:54 +00:00
from cli import Cli
from fixtures_flakes import FlakeForTest
from pytest import CaptureFixture
2024-03-07 12:04:48 +00:00
from clan_cli.clan_uri import ClanURI
2023-12-12 12:56:54 +00:00
from clan_cli.dirs import user_history_file
from clan_cli.history.add import HistoryEntry
if TYPE_CHECKING:
pass
@pytest.mark.impure
2023-12-12 12:56:54 +00:00
def test_history_add(
2023-12-12 20:31:47 +00:00
test_flake_with_core: FlakeForTest,
2023-12-12 12:56:54 +00:00
) -> None:
cli = Cli()
2024-03-07 12:04:48 +00:00
uri = ClanURI.from_str(str(test_flake_with_core.path), "vm1")
2023-12-12 12:56:54 +00:00
cmd = [
"history",
"add",
str(uri),
2023-12-12 12:56:54 +00:00
]
cli.run(cmd)
history_file = user_history_file()
assert history_file.exists()
history = [HistoryEntry(**entry) for entry in json.loads(open(history_file).read())]
2023-12-12 20:31:47 +00:00
assert history[0].flake.flake_url == str(test_flake_with_core.path)
2023-12-12 12:56:54 +00:00
@pytest.mark.impure
2023-12-12 12:56:54 +00:00
def test_history_list(
capsys: CaptureFixture,
2023-12-12 20:31:47 +00:00
test_flake_with_core: FlakeForTest,
2023-12-12 12:56:54 +00:00
) -> None:
cli = Cli()
2024-03-07 12:04:48 +00:00
uri = ClanURI.from_str(str(test_flake_with_core.path), "vm1")
2023-12-12 12:56:54 +00:00
cmd = [
"history",
"list",
]
cli.run(cmd)
2023-12-12 20:31:47 +00:00
assert str(test_flake_with_core.path) not in capsys.readouterr().out
2023-12-12 12:56:54 +00:00
cli.run(["history", "add", str(uri)])
2023-12-12 12:56:54 +00:00
cli.run(cmd)
2023-12-12 20:31:47 +00:00
assert str(test_flake_with_core.path) in capsys.readouterr().out