Files
jobtrackingapp/scripts/test_gitea_backlog.py
T
cesnimda c05d6f8906
CI and Deploy / test (pull_request) Failing after 7m16s
CI and Deploy / deploy (pull_request) Has been skipped
Establish Gitea backlog workflow and reconcile Project 1
2026-12-02 18:30:39 +01:00

57 lines
2.4 KiB
Python

import unittest
from unittest.mock import patch
import gitea_backlog as backlog
class ImportTests(unittest.TestCase):
def setUp(self):
self.item = {"key": "SAMPLE", "title": "Review the sample"}
self.issue = {"number": 12, "title": "Review the sample", "body": "<!-- jobbjakt:SAMPLE -->"}
self.state = {"issues": {}}
def match(self, issues):
return backlog.matches([self.item], issues, self.state)
def test_recover_after_server_create_before_checkpoint(self):
self.assertEqual(self.match([self.issue]), {"SAMPLE": self.issue})
def test_existing_human_title_requires_review(self):
with self.assertRaises(ValueError):
self.match([{**self.issue, "body": "Keep the original report"}])
def test_ambiguous_and_missing_recorded_identity_stop_import(self):
with self.assertRaises(ValueError):
self.match([self.issue, {**self.issue, "number": 13}])
self.state["issues"]["SAMPLE"] = {"number": 12}
with self.assertRaises(ValueError):
self.match([])
def test_pagination_continues_even_when_server_caps_page_size(self):
with patch.object(backlog, "request", side_effect=[[1], [2], []]) as req:
self.assertEqual(backlog.pages("issues?state=all"), [1, 2])
self.assertEqual(req.call_args.args, ("issues?state=all&limit=50&page=3",))
def test_board_takes_precedence_over_fallback(self):
issue = {**self.issue, "labels": [{"name": "Status/Blocked"}]}
self.assertEqual(backlog.effective_stage(issue, {}), "Blocked")
self.assertEqual(backlog.effective_stage(issue, {12: "Ready"}), "Ready")
def test_every_template_has_a_distinct_name_and_existing_kind(self):
templates = list((backlog.ROOT.parents[1] / ".gitea/ISSUE_TEMPLATE").glob("*.md"))
self.assertEqual(len(templates), 8)
names = set()
for f in templates:
text = f.read_text(encoding="utf-8")
header, content = text.split("---\n", 2)[1:]
names.add(header.split('name: "')[1].split('"')[0])
kind = header.split('labels: ["')[1].split('"')[0]
self.assertIn(kind, backlog.label_spec())
self.assertIn('projects: ["JobbJakt Development"]', header)
self.assertIn("- [ ]", content)
self.assertEqual(len(names), len(templates))
if __name__ == "__main__":
unittest.main()