tests(registry): add registry tests

This commit is contained in:
2026-04-18 16:13:27 +02:00
parent 98a1a330c5
commit 98e6309256
3 changed files with 160 additions and 10 deletions
+2 -5
View File
@@ -4,15 +4,12 @@ import dataclasses
@dataclasses.dataclass
class Page:
path: str
with_index: bool
with_index: bool = False
host: str | None = None
token_hash: str | None = None
def get_url_path(self) -> str:
return f"/{self.path}/"
def __repr__(self) -> str:
out = self.get_url_path()
out = f"/{self.path}/"
if self.host is not None:
out += f" [{self.host}]"
if not self.with_index:
+6 -5
View File
@@ -34,21 +34,22 @@ class Registry:
self.logger.info("Updated %s", self.pages[path])
def set_host(self, path: str, host: str) -> None:
if self.pages[path].host != host:
if path in self.pages and self.pages[path].host != host:
self.data_dir.set_file(path, self.HOST_FILE, host)
self.pages[path].host = host
self.logger.debug("Updated %s", self.pages[path])
def set_token_hash(self, path: str, token_hash: str) -> None:
if self.pages[path].token_hash != token_hash:
if path in self.pages and self.pages[path].token_hash != token_hash:
self.data_dir.set_file(path, self.TOKEN_FILE, token_hash, 0o600)
self.pages[path].token_hash = token_hash
self.logger.debug("Updated %s", self.pages[path])
def remove(self, path: str) -> None:
page = self.pages[path]
del self.pages[path]
self.logger.info("Removed %s", page)
if path in self.pages:
page = self.pages[path]
del self.pages[path]
self.logger.info("Removed %s", page)
def get_from_path(self, path: str) -> page.Page | None:
if path in self.pages: