Answer stability round 2: 0 🔴, 1 🟡 (0 misread); run two looped tests under subTest, refuse a blocker that is no issue key, and test the page cap, the four conversions at once and the search's failure messages
This commit is contained in:
@@ -150,8 +150,8 @@ def issue_of(raw: object) -> Issue | Failure:
|
||||
issue = Issue(key, fields["summary"].strip(), fields["description"], tuple(version["name"] for version in fields["fixVersions"]), blockers, typing.cast(dict[str, typing.Any], raw).get("properties", {}).get(PROPERTY, {}))
|
||||
except (AttributeError, KeyError, TypeError) as failure:
|
||||
return Failure(f"{key} is not in the shape Jira Cloud's REST API version 3 documents: {failure!r}")
|
||||
if not isinstance(issue.description, dict | None) or not all(isinstance(name, str) for name in issue.fix_versions + issue.blockers):
|
||||
return Failure(f"{key} is not in the shape Jira Cloud's REST API version 3 documents: its description, a Fix Version's name or a linked issue's key is of another type")
|
||||
if not isinstance(issue.description, dict | None) or not all(isinstance(name, str) for name in issue.fix_versions + issue.blockers) or not all(ISSUE_KEY.fullmatch(blocker) for blocker in issue.blockers):
|
||||
return Failure(f"{key} is not in the shape Jira Cloud's REST API version 3 documents: its description, a Fix Version's name or a linked issue's key holds another kind of value")
|
||||
return issue
|
||||
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@ import base64
|
||||
import pathlib
|
||||
import sys
|
||||
import tempfile
|
||||
import threading
|
||||
import time
|
||||
import unittest
|
||||
import unittest.mock
|
||||
|
||||
@@ -107,7 +109,8 @@ class JiraPlan(unittest.TestCase):
|
||||
bare = issue("ABC-35")
|
||||
del bare["properties"]
|
||||
for item in self.items(issue("ABC-34"), bare):
|
||||
self.assertEqual((item.scores, item.moves, item.exempt, item.detail, item.likelihood), ({}, (), "", "", 0))
|
||||
with self.subTest(item=item.id):
|
||||
self.assertEqual((item.scores, item.moves, item.exempt, item.detail, item.likelihood), ({}, (), "", "", 0))
|
||||
|
||||
def test_an_issue_is_blocked_by_each_blocker_still_in_the_plan(self):
|
||||
blocked, _ = self.items(issue("ABC-34", blocked_by=("ABC-35", "ABC-2", "OTHER-9"), blocks=("ABC-35",)), issue("ABC-35", blocks=("ABC-34",)))
|
||||
@@ -153,14 +156,36 @@ class JiraPlan(unittest.TestCase):
|
||||
self.assertEqual(self.store().read(), Failure("POST /rest/api/3/search/jql answered 401: no"))
|
||||
|
||||
def test_an_answer_in_another_shape_fails_the_read(self):
|
||||
for page in ([], {"issues": "none"}, {"issues": ["ABC-1"]}, {"issues": [{"key": 7, "fields": {}}]}, {"issues": [{"key": "abc", "fields": {}}]}):
|
||||
no_page, no_key = "the search answered something other than a page of issues", "the search answered an issue without an issue key"
|
||||
for page, reason in (([], no_page), ({"issues": "none"}, no_page), ({"issues": ["ABC-1"]}, no_key), ({"issues": [{"key": 7, "fields": {}}]}, no_key), ({"issues": [{"key": "abc", "fields": {}}]}, no_key)):
|
||||
with self.subTest(page=page):
|
||||
self.pages, self.calls = [page], []
|
||||
self.assertIsInstance(self.store().read(), Failure)
|
||||
self.assertEqual(self.store().read(), Failure(reason))
|
||||
|
||||
def test_a_search_that_never_names_a_last_page_fails_the_read(self):
|
||||
self.pages = [{"issues": [], "nextPageToken": "more"}] * 2
|
||||
with unittest.mock.patch.object(jira_epic, "MAX_PAGES", 2):
|
||||
self.assertEqual(self.store().read(), Failure("the search for ABC-12's children did not end within 2 pages"))
|
||||
|
||||
def test_converts_at_most_four_descriptions_at_once(self):
|
||||
lock, running, most = threading.Lock(), [0], [0]
|
||||
|
||||
def slow(document: dict[str, object]) -> str:
|
||||
with lock:
|
||||
running[0] += 1
|
||||
most[0] = max(most[0], running[0])
|
||||
time.sleep(0.02)
|
||||
with lock:
|
||||
running[0] -= 1
|
||||
return "text"
|
||||
|
||||
self.pages = [{"issues": [issue(f"ABC-{number}", description=adf("Why.")) for number in range(1, 41)]}]
|
||||
self.assertIsInstance(jira_epic.JiraPlan(EPIC, self.env, self.http, slow).read(), Plan)
|
||||
self.assertLessEqual(most[0], 4)
|
||||
|
||||
def test_an_issue_in_another_shape_fails_the_read_naming_it(self):
|
||||
good = issue("ABC-1")
|
||||
for wrong in ({"key": "ABC-1"}, issue("ABC-1", summary=None), issue("ABC-1", description="text"), good | {"fields": good["fields"] | {"fixVersions": [{"name": 7}]}}, good | {"fields": good["fields"] | {"issuelinks": [{"type": {"inward": "is blocked by"}, "inwardIssue": {"key": 7}}]}}, good | {"properties": None}): # type: ignore[arg-type, operator]
|
||||
for wrong in ({"key": "ABC-1"}, issue("ABC-1", summary=None), issue("ABC-1", description="text"), good | {"fields": good["fields"] | {"fixVersions": [{"name": 7}]}}, good | {"fields": good["fields"] | {"issuelinks": [{"type": {"inward": "is blocked by"}, "inwardIssue": {"key": 7}}]}}, good | {"fields": good["fields"] | {"issuelinks": [{"type": {"inward": "is blocked by"}, "inwardIssue": {"key": "ABC-x"}}]}}, good | {"properties": None}): # type: ignore[arg-type, operator]
|
||||
with self.subTest(wrong=wrong):
|
||||
failure = self.read(wrong) # type: ignore[arg-type]
|
||||
self.assertIsInstance(failure, Failure)
|
||||
|
||||
Reference in New Issue
Block a user