58 lines
2.7 KiB
Python
58 lines
2.7 KiB
Python
import pathlib
|
|
import sys
|
|
import unittest
|
|
|
|
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
|
|
|
from atlassian.jira import Entry, entry_of, Link
|
|
from failure import Failure
|
|
from atlassian import jira
|
|
|
|
BLOCKED = {"id": "9", "type": {"inward": "is blocked by"}, "inwardIssue": {"key": "ABC-2"}}
|
|
SHAPE = "ABC-1 is not in the shape Jira Cloud's REST API version 3 documents: "
|
|
|
|
|
|
def raw(*links: object, **more: object) -> dict[str, object]:
|
|
return {"key": "ABC-1", "fields": {"issuelinks": list(links)}} | more
|
|
|
|
|
|
class TheHeadOfAnEntry(unittest.TestCase):
|
|
def test_holds_the_key_the_fields_the_blocked_by_links_and_the_property_asked_for(self):
|
|
outward = {"id": "3", "type": {"inward": "is blocked by"}, "outwardIssue": {"key": "ABC-3"}}
|
|
relates = {"id": "4", "type": {"inward": "relates to"}, "inwardIssue": {"key": "ABC-4"}}
|
|
found = entry_of(raw(BLOCKED, outward, relates, properties={"plan": {"L": 2}}), "plan")
|
|
self.assertEqual(found, Entry("ABC-1", {"issuelinks": [BLOCKED, outward, relates]}, (Link("ABC-2", "9"),), {"L": 2}))
|
|
self.assertEqual(entry_of(raw(), "plan"), Entry("ABC-1", {"issuelinks": []}, (), {}))
|
|
|
|
def test_an_entry_without_an_issue_key_is_a_failure(self):
|
|
for wrong in ([], {}, {"key": 7}, {"key": "abc"}):
|
|
with self.subTest(wrong=wrong):
|
|
self.assertEqual(entry_of(wrong, "plan"), Failure("the search answered an issue without an issue key"))
|
|
|
|
def test_an_entry_in_another_shape_is_a_failure_naming_the_issue_and_the_field(self):
|
|
cases = {
|
|
"its fields are no object": {"key": "ABC-1"},
|
|
"its properties are no object": raw(properties=[]),
|
|
"its issuelinks are no list": {"key": "ABC-1", "fields": {}},
|
|
"its issuelinks hold a link that is no object": raw("link"),
|
|
"its issuelinks hold a link whose type names no inward text": raw(BLOCKED | {"type": None}),
|
|
"its issuelinks hold a link whose id or whose linked issue's key is no text": raw(BLOCKED | {"inwardIssue": {"key": 7}}),
|
|
}
|
|
for how, wrong in cases.items():
|
|
with self.subTest(how=how):
|
|
self.assertEqual(entry_of(wrong, "plan"), Failure(SHAPE + how))
|
|
self.assertEqual(entry_of(raw(BLOCKED | {"id": 9}), "plan"), Failure(SHAPE + "its issuelinks hold a link whose id or whose linked issue's key is no text"))
|
|
self.assertEqual(entry_of(raw(BLOCKED | {"inwardIssue": None}), "plan"), Failure(SHAPE + "its issuelinks hold a link whose id or whose linked issue's key is no text"))
|
|
|
|
def test_a_fault_in_reading_the_links_is_not_reported_as_jiras(self):
|
|
class Faulty(dict):
|
|
def get(self, key, default=None):
|
|
raise TypeError("ours")
|
|
|
|
with self.assertRaisesRegex(TypeError, "ours"):
|
|
entry_of({"key": "ABC-1", "fields": Faulty()}, "plan")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|