Improved ClanURI

This commit is contained in:
Qubasa
2023-12-12 21:31:47 +01:00
parent c90053834a
commit e139628fbd
4 changed files with 63 additions and 19 deletions

View File

@@ -101,6 +101,31 @@ def test_from_path_with_default() -> None:
assert False
def test_from_str() -> None:
# Create a ClanURI object from a remote URI with parameters
uri_str = "https://example.com?password=asdasd&test=1234"
params = ClanParameters(flake_attr="myVM")
uri = ClanURI.from_str(url=uri_str, params=params)
assert uri.params.flake_attr == "myVM"
match uri.scheme:
case ClanScheme.HTTP.value(url):
assert url == "https://example.com?password=asdasd&test=1234" # type: ignore
case _:
assert False
uri_str = "~/Downloads/democlan"
params = ClanParameters(flake_attr="myVM")
uri = ClanURI.from_str(url=uri_str, params=params)
assert uri.params.flake_attr == "myVM"
assert uri.get_internal() == "~/Downloads/democlan"
uri_str = "~/Downloads/democlan"
uri = ClanURI.from_str(url=uri_str)
assert uri.params.flake_attr == "defaultVM"
assert uri.get_internal() == "~/Downloads/democlan"
def test_remote_with_all_params() -> None:
# Create a ClanURI object from a remote URI with parameters
uri = ClanURI("clan://https://example.com?flake_attr=myVM&password=1234")

View File

@@ -13,26 +13,26 @@ if TYPE_CHECKING:
def test_history_add(
test_flake: FlakeForTest,
test_flake_with_core: FlakeForTest,
) -> None:
cli = Cli()
cmd = [
"history",
"add",
str(test_flake.path),
str(test_flake_with_core.path),
]
breakpoint()
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.path)
assert history[0].flake.flake_url == str(test_flake_with_core.path)
def test_history_list(
capsys: CaptureFixture,
test_flake: FlakeForTest,
test_flake_with_core: FlakeForTest,
) -> None:
cli = Cli()
cmd = [
@@ -41,8 +41,8 @@ def test_history_list(
]
cli.run(cmd)
assert str(test_flake.path) not in capsys.readouterr().out
assert str(test_flake_with_core.path) not in capsys.readouterr().out
cli.run(["history", "add", str(test_flake.path)])
cli.run(["history", "add", str(test_flake_with_core.path)])
cli.run(cmd)
assert str(test_flake.path) in capsys.readouterr().out
assert str(test_flake_with_core.path) in capsys.readouterr().out