Files
claude-config/bin/do_epic/e2e/test_settings.py
T

55 lines
2.2 KiB
Python

import pathlib
import sys
import tempfile
import unittest
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[2]))
from do_epic.e2e.settings import ENV_FILE, JIRA_URL, PROJECT, read, Sandbox
from failure import Failure
class SettingsTest(unittest.TestCase):
def setUp(self) -> None:
made = tempfile.TemporaryDirectory()
self.addCleanup(made.cleanup)
self.env_file = pathlib.Path(made.name) / "jira.env"
self.env_file.write_text("ATLASSIAN_EMAIL=a@example.com\nATLASSIAN_API_TOKEN=secret\n", encoding="utf-8")
self.env_file.chmod(0o600)
self.env = {JIRA_URL: "https://acme.atlassian.net", ENV_FILE: str(self.env_file), PROJECT: "SBX"}
def failure(self, env: dict[str, str]) -> str:
found = read(env)
assert isinstance(found, Failure), found
return found.reason
def test_reads_the_site_the_env_file_and_the_project(self) -> None:
self.assertEqual(read(self.env), Sandbox("https://acme.atlassian.net", self.env_file, "SBX"))
def test_names_each_setting_that_is_missing(self) -> None:
reason = self.failure({})
for name in (JIRA_URL, ENV_FILE, PROJECT):
self.assertIn(name, reason)
self.assertNotIn(PROJECT, self.failure({k: v for k, v in self.env.items() if k != JIRA_URL}))
def test_treats_a_blank_setting_as_missing(self) -> None:
self.assertIn(f"{ENV_FILE} is missing", self.failure({**self.env, ENV_FILE: " "}))
def test_names_every_fault_at_once_separated_by_semicolons(self) -> None:
self.env_file.chmod(0o644)
reason = self.failure({**self.env, PROJECT: "sbx-1"})
self.assertTrue(reason.startswith(f"{PROJECT} is"))
self.assertIn(f"; {self.env_file} ", reason)
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_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)
self.assertIn(str(self.env_file), self.failure(self.env))
def test_refuses_an_env_file_that_is_not_an_absolute_path(self) -> None:
self.assertIn(ENV_FILE, self.failure({**self.env, ENV_FILE: "jira.env"}))