Files
computer-playbook/tests/unit/plugins/lookup/test_application_gid.py
T
kevinveenbirkenbachandClaude Opus 4.7 c55ad69c41 refactor: drop requirement-file references from code, add doc rule + lint
Strip every `req <NNN>`, `req-<NNN>`, `Requirement <NNN>`,
`requirement-<NNN>`, and `docs/requirements/<NNN>-...md` mention from
non-Markdown source files. Comments anchored to requirement numbers
rot when requirements are renumbered or rewritten and conflate
present-state behaviour (which the comment should describe) with the
audit trail of how the code got there (which belongs in commit
messages, PR descriptions, and the requirement file itself).

* Document the rule in `docs/contributing/documentation.md` under
  "Comments". Code MUST describe the *why* in present-state language;
  contract enforcement lives in tests, not folklore.
* Clean 254 source files across `roles/`, `tests/`, `plugins/`,
  `cli/`, `scripts/`, `utils/`, `group_vars/`, and the repo-root
  `eslint.config.js`. Pure comment / docstring / log-message edits;
  no behavioural change.
* Add `tests/lint/repository/test_no_req_references_in_code.py` to
  enforce the rule going forward across `.js`, `.py`, `.yml`,
  `.yaml`, `.j2`, and `.sh` files. The legacy
  `test_no_stale_requirement_refs.py` is exempt as the only file
  whose purpose is to detect these very tokens.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-10 16:25:22 +02:00

62 lines
2.0 KiB
Python

import shutil
import tempfile
import unittest
from pathlib import Path
from plugins.lookup.application_gid import LookupModule
from utils.cache.yaml import dump_yaml
class TestApplicationGidLookup(unittest.TestCase):
def setUp(self):
# Create a temporary roles directory
self.temp_dir = tempfile.mkdtemp()
self.roles_dir = str(Path(self.temp_dir) / "roles")
Path(self.roles_dir).mkdir()
# Define mock application_ids (role directory names are the canonical ids)
self.application_ids = [
"web-app-nextcloud",
"web-app-moodle",
"web-app-wordpress",
"web-app-taiga",
]
# Per an "application role" is identified by the presence of
# at least one of the project-owned `meta/<topic>.yml` files.
for application_id in self.application_ids:
role_path = str(Path(self.roles_dir) / application_id / "meta")
Path(role_path).mkdir(parents=True)
dump_yaml(
str(Path(role_path) / "services.yml"),
{application_id: {"title": application_id}},
)
self.lookup = LookupModule()
def tearDown(self):
shutil.rmtree(self.temp_dir)
def test_gid_lookup(self):
expected_order = sorted(self.application_ids)
for i, application_id in enumerate(expected_order):
result = self.lookup.run([application_id], roles_dir=self.roles_dir)
self.assertEqual(result, [10000 + i])
def test_custom_base_gid(self):
result = self.lookup.run(
["web-app-taiga"],
roles_dir=self.roles_dir,
base_gid=20000,
)
self.assertEqual(result, [20002]) # 2nd index in sorted list
def test_application_id_not_found(self):
with self.assertRaises(Exception) as context:
self.lookup.run(["unknownapp"], roles_dir=self.roles_dir)
self.assertIn("Application ID 'unknownapp' not found", str(context.exception))
if __name__ == "__main__":
unittest.main()