clan-core/pkgs/clan-cli/tests/test_history_cli.py
Qubasa 442e5b45ba
All checks were successful
checks / check-links (pull_request) Successful in 22s
checks / checks-impure (pull_request) Successful in 1m55s
checks / checks (pull_request) Successful in 2m48s
clan_cli: Simplify ClanURI
2024-03-07 19:04:48 +07:00

54 lines
1.3 KiB
Python

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