api/flake/list_history: init

Add an api endpoint to list the history of clan flakes that have been interacted with

Also add `clan flake list`
This commit is contained in:
DavHau
2023-11-17 17:56:07 +07:00
parent a01cb9434b
commit 64649ff7a9
5 changed files with 85 additions and 0 deletions

View File

@@ -23,6 +23,30 @@ def test_flake_add(
assert open(user_history_file()).read().strip() == str(test_flake.path)
def test_flake_list(
api: TestClient, test_flake: FlakeForTest, temporary_home: Path
) -> None:
response = api.get(
"/api/flake/list_history",
)
assert response.status_code == 200, response.text
assert response.json() == []
# add the test_flake
response = api.put(
f"/api/flake/add?flake_dir={str(test_flake.path)}",
json={},
)
assert response.status_code == 200, response.text
# list the flakes again
response = api.get(
"/api/flake/list_history",
)
assert response.status_code == 200, response.text
assert response.json() == [str(test_flake.path)]
@pytest.mark.impure
def test_inspect_ok(api: TestClient, test_flake_with_core: FlakeForTest) -> None:
params = {"url": str(test_flake_with_core.path)}

View File

@@ -2,6 +2,7 @@ from typing import TYPE_CHECKING
from cli import Cli
from fixtures_flakes import FlakeForTest
from pytest import CaptureFixture
from clan_cli.dirs import user_history_file
@@ -24,3 +25,21 @@ def test_flakes_add(
history_file = user_history_file()
assert history_file.exists()
assert open(history_file).read().strip() == str(test_flake.path)
def test_flakes_list(
capsys: CaptureFixture,
test_flake: FlakeForTest,
) -> None:
cli = Cli()
cmd = [
"flakes",
"list",
]
cli.run(cmd)
assert str(test_flake.path) not in capsys.readouterr().out
cli.run(["flakes", "add", str(test_flake.path)])
cli.run(cmd)
assert str(test_flake.path) in capsys.readouterr().out