feat: profiles rename_profile
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -57,3 +57,16 @@ def create_profile(base, name, pid, ts=0):
|
|||||||
reg["profiles"].append(entry)
|
reg["profiles"].append(entry)
|
||||||
write_registry(base, reg)
|
write_registry(base, reg)
|
||||||
return entry
|
return entry
|
||||||
|
|
||||||
|
|
||||||
|
def rename_profile(base, pid, name):
|
||||||
|
reg = read_registry(base)
|
||||||
|
entry = find_by_id(reg, pid)
|
||||||
|
if not entry:
|
||||||
|
raise KeyError(pid)
|
||||||
|
other = find_by_name(reg, name)
|
||||||
|
if other and other["id"] != pid:
|
||||||
|
raise ValueError(f"profile name already exists: {name}")
|
||||||
|
entry["name"] = name
|
||||||
|
write_registry(base, reg)
|
||||||
|
return entry
|
||||||
|
|||||||
@@ -34,3 +34,16 @@ def test_create_duplicate_name_raises(tmp_path):
|
|||||||
pr.create_profile(str(tmp_path), "setA", "id1")
|
pr.create_profile(str(tmp_path), "setA", "id1")
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError):
|
||||||
pr.create_profile(str(tmp_path), "setA", "id2")
|
pr.create_profile(str(tmp_path), "setA", "id2")
|
||||||
|
|
||||||
|
def test_rename_profile(tmp_path):
|
||||||
|
pr.create_profile(str(tmp_path), "old", "id1")
|
||||||
|
e = pr.rename_profile(str(tmp_path), "id1", "new")
|
||||||
|
assert e["name"] == "new"
|
||||||
|
assert pr.find_by_name(pr.read_registry(str(tmp_path)), "new")["id"] == "id1"
|
||||||
|
|
||||||
|
def test_rename_to_existing_name_raises(tmp_path):
|
||||||
|
import pytest
|
||||||
|
pr.create_profile(str(tmp_path), "a", "id1")
|
||||||
|
pr.create_profile(str(tmp_path), "b", "id2")
|
||||||
|
with pytest.raises(ValueError):
|
||||||
|
pr.rename_profile(str(tmp_path), "id2", "a")
|
||||||
|
|||||||
Reference in New Issue
Block a user