57290da1e8
Three new unit test modules: - tests/unit/test_contrib_gitea_client.py — GiteaClient (urllib mocked) and GiteaForge delegation - tests/unit/orchestrator/test_main.py — __main__ run/status commands - tests/unit/orchestrator/test_bootstrap.py — _token, BotBottleStateStore, _to_forge_state/_to_record, make_forge, make_sidecar, build Augments to existing suites: - test_events: non-"created" comment action ignored - test_lifecycle: _iso_now callable, untracked-issue comment ignored, untracked-PR closed ignored (covers _find_by_pr return-None path) - test_runner: destroy command, _default_run via subprocess mock - test_sidecar: _jsonable dataclass/list branches, OpLog.read on missing file, drain_done_events on corrupted file, socket _Handler invalid-JSON and empty-line paths, serve() with pre-existing socket path - test_watchdog: _loop body covered by patching _TICK_SECS to 0.01s - test_webhook: unknown GET path returns 404 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
69 lines
2.5 KiB
Python
69 lines
2.5 KiB
Python
"""Unit: webhook payload parsing."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import unittest
|
|
|
|
from bot_bottle.orchestrator.events import parse_event
|
|
from bot_bottle.orchestrator.model import CommentCreated, IssueAssigned, PullRequestClosed
|
|
|
|
_REPO = {"repository": {"name": "bot-bottle", "owner": {"login": "didericis"}}}
|
|
|
|
|
|
class ParseEventTest(unittest.TestCase):
|
|
def test_issue_assigned(self):
|
|
payload = {
|
|
**_REPO,
|
|
"action": "assigned",
|
|
"issue": {
|
|
"number": 17,
|
|
"title": "Fix it",
|
|
"body": "please",
|
|
"assignees": [{"login": "agent-bot"}],
|
|
"labels": [{"name": "bot-bottle:implementer"}],
|
|
},
|
|
}
|
|
ev = parse_event("issues", payload)
|
|
self.assertIsInstance(ev, IssueAssigned)
|
|
assert isinstance(ev, IssueAssigned)
|
|
self.assertEqual(("didericis", "bot-bottle", 17), (ev.owner, ev.repo, ev.issue_number))
|
|
self.assertEqual(("agent-bot",), ev.assignees)
|
|
self.assertEqual(("bot-bottle:implementer",), ev.labels)
|
|
|
|
def test_issue_non_assigned_ignored(self):
|
|
self.assertIsNone(parse_event("issues", {**_REPO, "action": "opened", "issue": {}}))
|
|
|
|
def test_comment_created(self):
|
|
payload = {
|
|
**_REPO,
|
|
"action": "created",
|
|
"issue": {"number": 42, "pull_request": {"x": 1}},
|
|
"comment": {"id": 5, "user": {"login": "reviewer"}, "body": "redo"},
|
|
}
|
|
ev = parse_event("issue_comment", payload)
|
|
assert isinstance(ev, CommentCreated)
|
|
self.assertEqual(42, ev.issue_number)
|
|
self.assertEqual("reviewer", ev.author)
|
|
self.assertTrue(ev.is_pull)
|
|
|
|
def test_pull_request_closed(self):
|
|
payload = {**_REPO, "action": "closed", "pull_request": {"number": 8, "merged": True}}
|
|
ev = parse_event("pull_request", payload)
|
|
assert isinstance(ev, PullRequestClosed)
|
|
self.assertEqual(8, ev.pr_number)
|
|
self.assertTrue(ev.merged)
|
|
|
|
def test_pull_request_non_closed_ignored(self):
|
|
self.assertIsNone(parse_event("pull_request", {**_REPO, "action": "opened"}))
|
|
|
|
def test_comment_non_created_action_ignored(self):
|
|
payload = {**_REPO, "action": "edited", "issue": {}, "comment": {}}
|
|
self.assertIsNone(parse_event("issue_comment", payload))
|
|
|
|
def test_unknown_kind_ignored(self):
|
|
self.assertIsNone(parse_event("push", {**_REPO}))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|