diff --git a/bin/do_epic/e2e/sandbox.py b/bin/do_epic/e2e/sandbox.py index 5b6a5958..8a085b94 100644 --- a/bin/do_epic/e2e/sandbox.py +++ b/bin/do_epic/e2e/sandbox.py @@ -65,7 +65,10 @@ def deleted_with_children(sandbox: Sandbox, key: str, authorization: str, http: found = searched(sandbox.jira_url, f"the issues of {key}", f"parent = {key}", {"fields": ["summary"]}, authorization, http) # The epic is deleted all the same; the first failure is the one to report. problem = found if isinstance(found, Failure) else None - children = [] if isinstance(found, Failure) else [item["key"] for item in found if isinstance(item, dict) and isinstance(item.get("key"), str)] + entries = [] if isinstance(found, Failure) else found + children = [item["key"] for item in entries if isinstance(item, dict) and isinstance(item.get("key"), str)] + if len(children) < len(entries): + problem = Failure(f"the search for the issues of {key} answered an entry without a key, so that issue is not deleted") for each in [*children, key]: deleted = http("DELETE", api(sandbox, f"issue/{each}?deleteSubtasks=true"), authorization, None) problem = problem or (deleted if isinstance(deleted, Failure) else None) diff --git a/bin/do_epic/e2e/scenario.py b/bin/do_epic/e2e/scenario.py index a1ddb8ea..b6253fa9 100644 --- a/bin/do_epic/e2e/scenario.py +++ b/bin/do_epic/e2e/scenario.py @@ -44,7 +44,7 @@ class Machine: home: pathlib.Path launcher: pathlib.Path env: typing.Mapping[str, str] - timeout: int = TIMEOUT + timeout: float = TIMEOUT def do_epic(self, *args: str, stdin: str = "") -> subprocess.CompletedProcess[str]: env = {**self.env, "HOME": str(self.home)} diff --git a/bin/do_epic/e2e/test_sandbox.py b/bin/do_epic/e2e/test_sandbox.py index 402e5593..aa1e2c97 100644 --- a/bin/do_epic/e2e/test_sandbox.py +++ b/bin/do_epic/e2e/test_sandbox.py @@ -66,6 +66,15 @@ class EpicMadeTest(unittest.TestCase): self.assertEqual(jira.bodies[2], {"jql": "parent = SBX-1", "fields": ["summary"], "maxResults": 100, "nextPageToken": "more"}) self.assertEqual([url for method, url in jira.requests if method == "DELETE"], [f"issue/SBX-{n}?deleteSubtasks=true" for n in (2, 3, 1)]) + def test_deletes_the_rest_and_says_so_when_a_found_issue_has_no_key(self) -> None: + jira = JiraStub() + jira.search_answer = {"issues": [{"key": "SBX-2"}, {"summary": "no key"}]} + with self.assertRaises(Leftover) as left: + with epic_made(self.sandbox, "An epic", jira, lambda markdown: {"type": "doc"}): + pass + self.assertIn("without a key", str(left.exception)) + self.assertEqual([url for method, url in jira.requests if method == "DELETE"], ["issue/SBX-2?deleteSubtasks=true", "issue/SBX-1?deleteSubtasks=true"]) + def test_deletes_them_when_the_block_raises(self) -> None: jira = JiraStub() with self.assertRaises(ZeroDivisionError): diff --git a/bin/do_epic/e2e/test_scenario.py b/bin/do_epic/e2e/test_scenario.py index 685c569d..f7a7d52d 100644 --- a/bin/do_epic/e2e/test_scenario.py +++ b/bin/do_epic/e2e/test_scenario.py @@ -226,7 +226,7 @@ class MachineTest(unittest.TestCase): self.assertEqual((finished.returncode, finished.stdout, finished.stderr), (3, "out\n", "err\n")) def test_stops_a_do_epic_that_runs_over_its_time_and_says_so(self) -> None: - finished = scenario.Machine(self.folder, self.script("sleep 30"), {}, timeout=1).do_epic("ABC-1") + finished = scenario.Machine(self.folder, self.script("exec sleep 30"), {}, timeout=0.2).do_epic("ABC-1") self.assertEqual(finished.returncode, 124) - self.assertIn("ran over 1 seconds", finished.stderr) + self.assertIn("ran over 0.2 seconds", finished.stderr) self.assertIn("ABC-1", finished.stderr) diff --git a/bin/do_epic/e2e/test_settings.py b/bin/do_epic/e2e/test_settings.py index b1dbe5a0..883a0157 100644 --- a/bin/do_epic/e2e/test_settings.py +++ b/bin/do_epic/e2e/test_settings.py @@ -44,10 +44,7 @@ class SettingsTest(unittest.TestCase): def test_refuses_a_site_that_is_not_an_https_address_without_a_path(self) -> None: self.assertIn(JIRA_URL, self.failure({**self.env, JIRA_URL: "http://acme.atlassian.net/jira"})) - def test_refuses_a_project_that_is_not_a_project_key(self) -> None: - self.assertIn(PROJECT, self.failure({**self.env, PROJECT: "sbx-1"})) - - def test_refuses_an_env_file_that_cannot_be_read_saying_why(self) -> None: + def test_refuses_an_env_file_that_cannot_be_read_naming_the_file(self) -> None: gone = self.env_file.parent / "gone.env" self.assertIn(str(gone), self.failure({**self.env, ENV_FILE: str(gone)})) self.env_file.chmod(0o644)