Files
govoplan-docs/tests/test_docs_context.py

92 lines
3.4 KiB
Python

from __future__ import annotations
import unittest
from types import SimpleNamespace
from govoplan_access.backend.manifest import get_manifest as get_access_manifest
from govoplan_core.core.registry import PlatformRegistry
from govoplan_tenancy.backend.manifest import get_manifest as get_tenancy_manifest
from govoplan_docs.backend.api.v1.routes import (
_classify_documentation,
_documentation_topic_anchor,
_documentation_topic_groups,
)
from govoplan_docs.backend.manifest import get_manifest as get_docs_manifest
class FakePrincipal:
tenant_id = "tenant-1"
user = SimpleNamespace(id="user-1")
def __init__(self, scopes: set[str]) -> None:
self.scopes = frozenset(scopes)
def has(self, required_scope: str) -> bool:
return required_scope in self.scopes
class DocsContextTests(unittest.TestCase):
def test_topic_groups_preserve_layer_classification(self) -> None:
registry = PlatformRegistry()
registry.register(get_tenancy_manifest())
registry.register(get_access_manifest())
registry.register(get_docs_manifest())
principal = FakePrincipal({"admin:users:read", "admin:groups:read", "docs:documentation:read"})
layers = _classify_documentation(
registry,
principal,
settings=None,
session=None,
documentation_type="admin",
locale="en",
)
groups = _documentation_topic_groups(layers)
workflow_ids = {topic["id"] for topic in groups["workflow"]}
reference_ids = {topic["id"] for topic in groups["reference"]}
pattern_ids = {topic["id"] for topic in groups["pattern"]}
system_ids = {topic["id"] for topic in groups["system"]}
self.assertIn("access.workflow.grant-user-access", workflow_ids)
self.assertIn("access.reference.admin-access-fields", reference_ids)
self.assertIn("docs.pattern.field-help", pattern_ids)
self.assertIn("docs.configured-system-documentation", system_ids)
configured_ids = {topic["id"] for topic in layers["configured"]}
always_ids = {topic["id"] for topic in layers["always"]}
self.assertIn("access.workflow.grant-user-access", configured_ids)
self.assertIn("docs.pattern.field-help", always_ids)
def test_unavailable_topic_still_appears_in_kind_group(self) -> None:
registry = PlatformRegistry()
registry.register(get_tenancy_manifest())
registry.register(get_access_manifest())
registry.register(get_docs_manifest())
principal = FakePrincipal({"docs:documentation:read"})
layers = _classify_documentation(
registry,
principal,
settings=None,
session=None,
documentation_type="user",
locale="en",
)
groups = _documentation_topic_groups(layers)
workflows = {topic["id"]: topic for topic in groups["workflow"]}
self.assertIn("access.workflow.grant-user-access", workflows)
self.assertFalse(workflows["access.workflow.grant-user-access"]["active"])
self.assertIn("access.workflow.grant-user-access", {topic["id"] for topic in layers["available"]})
def test_topic_anchor_is_stable(self) -> None:
self.assertEqual(
_documentation_topic_anchor("access", "access.workflow.grant-user-access"),
"docs-topic-access-access-workflow-grant-user-access",
)
if __name__ == "__main__":
unittest.main()