Files
computer-playbook/tests/unit/python/cli/build/docs/readme/test_generate.py
T
kevinveenbirkenbachandClaude Opus 5.5 558784e6ca feat(web-app-erpnext): set up the service provider's company and its accounting basics
The wizard bypass left ERPNext without a Company, so no app could create quotes, orders or invoices. The deploy now creates the Company from the service provider's name and country, with the currency from ERPNext's country data and an abbreviation that defaults to the name's initials, plus a fiscal year, five tax accounts, a cash account and the default company. It never rewrites an existing Company and fails loudly on a country ERPNext does not know. The README generator marks roles that read the service provider country, and the CI replay fills the placeholder.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-22 20:52:30 +02:00

74 lines
2.3 KiB
Python

from __future__ import annotations
import tempfile
import unittest
from pathlib import Path
from cli.build.docs.readme.generate import generate_readme
from utils.roles.mapping import (
ROLE_FILE_TASKS_MAIN,
ROLE_FILE_TEMPL_COMPOSE,
ROLE_FILE_VARS_MAIN,
)
ROLE = "web-app-sample"
READS_COUNTRY = 'SAMPLE_COUNTRY: "{{ service_provider.company.address.country }}"\n'
COUNTRY_VARS = (
'\\"service_provider\\": {\\"company\\": {\\"address\\": '
'{\\"country\\": \\"$COUNTRY\\"}}}, '
)
def _production_block(files: dict[str, str]) -> str:
with tempfile.TemporaryDirectory() as tmp:
role_dir = Path(tmp) / ROLE
for rel, content in files.items():
path = role_dir / rel
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text(content, encoding="utf-8")
text, _ = generate_readme(role_dir, ROLE)
return text.split("### Production", 1)[1].split("## Credits", 1)[0]
class TestServiceProviderCountry(unittest.TestCase):
def test_stack_role_reading_the_country_in_vars_asks_for_it(self) -> None:
block = _production_block(
{ROLE_FILE_TEMPL_COMPOSE: "", ROLE_FILE_VARS_MAIN: READS_COUNTRY}
)
self.assertIn("COUNTRY=<your-country>", block)
self.assertIn('-e COUNTRY="$COUNTRY"', block)
self.assertIn(COUNTRY_VARS, block)
def test_role_reading_the_country_in_tasks_asks_for_it(self) -> None:
block = _production_block(
{ROLE_FILE_TEMPL_COMPOSE: "", ROLE_FILE_TASKS_MAIN: READS_COUNTRY}
)
self.assertIn("COUNTRY=<your-country>", block)
self.assertIn(COUNTRY_VARS, block)
def test_host_role_reading_the_country_asks_for_it(self) -> None:
block = _production_block({ROLE_FILE_VARS_MAIN: READS_COUNTRY})
self.assertIn("--host localhost", block)
self.assertIn("COUNTRY=<your-country>", block)
self.assertIn(COUNTRY_VARS, block)
def test_role_rendering_the_country_only_in_a_template_does_not_ask(
self,
) -> None:
block = _production_block(
{
ROLE_FILE_TEMPL_COMPOSE: "",
"templates/imprint.html.j2": READS_COUNTRY,
}
)
self.assertNotIn("COUNTRY", block)
self.assertNotIn("service_provider", block)
if __name__ == "__main__":
unittest.main()