Implement F007 explicit project profiles
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
from forge.profile_config import read_flat_record
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
COMMAND = ["python3", str(ROOT / "scripts/configure-profile.py")]
|
||||
|
||||
|
||||
def configure(project, profile, owner, brand, *extra):
|
||||
return subprocess.run(COMMAND + ["--project", str(project), "--profile", profile,
|
||||
"--owner", owner, "--brand", brand,
|
||||
"--contributor-access", "Captain approval required",
|
||||
"--testing", "local unit tests",
|
||||
"--deployment", "manual approval", *extra],
|
||||
capture_output=True, text=True)
|
||||
|
||||
|
||||
class ProfileTests(unittest.TestCase):
|
||||
def test_both_profiles_keep_owner_and_brand_independent(self):
|
||||
with tempfile.TemporaryDirectory() as temp:
|
||||
business = Path(temp) / "existing-business"
|
||||
personal = Path(temp) / "new-personal"
|
||||
business.mkdir()
|
||||
personal.mkdir()
|
||||
(business / "README.md").write_text("existing work\n")
|
||||
self.assertEqual(configure(business, "business", "Independent Ltd", "Northstar").returncode, 0)
|
||||
self.assertEqual(configure(personal, "personal", "Alex", "Garden Notes").returncode, 0)
|
||||
one = read_flat_record(business / ".bortstack/profile.yaml")
|
||||
two = read_flat_record(personal / ".bortstack/profile.yaml")
|
||||
self.assertEqual((one["ownership"], one["branding"]), ("Independent Ltd", "Northstar"))
|
||||
self.assertEqual((two["ownership"], two["branding"]), ("Alex", "Garden Notes"))
|
||||
self.assertEqual((one["profile"], two["profile"]), ("business", "personal"))
|
||||
self.assertEqual((business / "README.md").read_text(), "existing work\n")
|
||||
self.assertNotIn("Bortstack", one["ownership"])
|
||||
|
||||
def test_selection_is_explicit_and_existing_record_is_preserved(self):
|
||||
with tempfile.TemporaryDirectory() as temp:
|
||||
project = Path(temp)
|
||||
dry = configure(project, "business", "Owner", "Brand", "--dry-run")
|
||||
self.assertEqual(dry.returncode, 0)
|
||||
self.assertFalse((project / ".bortstack").exists())
|
||||
self.assertEqual(configure(project, "business", "Owner", "Brand").returncode, 0)
|
||||
path = project / ".bortstack/profile.yaml"
|
||||
original = path.read_bytes()
|
||||
again = configure(project, "personal", "Other", "Other")
|
||||
self.assertNotEqual(again.returncode, 0)
|
||||
self.assertEqual(path.read_bytes(), original)
|
||||
|
||||
def test_rejects_placeholder_and_invalid_project(self):
|
||||
with tempfile.TemporaryDirectory() as temp:
|
||||
project = Path(temp) / "missing"
|
||||
self.assertNotEqual(configure(project, "business", "Owner", "Brand").returncode, 0)
|
||||
project.mkdir()
|
||||
self.assertNotEqual(configure(project, "business", "project-specific", "Brand").returncode, 0)
|
||||
self.assertFalse((project / ".bortstack").exists())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user