def test_andamio_qa(tmp_path: Path, supported_odoo_version: float): """PRUEBA que Andamio-QA funcione bien con una copia de andamio.""" copy( ".", tmp_path, data={"odoo_version": supported_odoo_version}, force=True, vcs_ref="HEAD", ) qa_run = docker["container", "run", "--rm", "--privileged", f"-v{tmp_path}:{tmp_path}:z", "-v/var/run/docker.sock:/var/run/docker.sock:z", f"-w{tmp_path}", "-eADDON_CATEGORIES=-p", "-eCOMPOSE_FILE=test.yaml", f"-eODOO_MAJOR={int(supported_odoo_version)}", f"-eODOO_MINOR={supported_odoo_version:.1f}", "dued/andamio-qa", ] try: qa_run["secrets-setup"] & FG qa_run["networks-autocreate"] & FG qa_run["build"] & FG qa_run["closed-prs"] & FG qa_run["flake8"] & FG qa_run["pylint"] & FG qa_run["addons-install"] & FG qa_run["coverage"] & FG finally: qa_run["shutdown"] & FG docker["system", "prune", "--all", "--force", "--volumes"]
def test_doodba_qa(tmp_path: Path, supported_odoo_version: float): """Test Doodba QA works fine with a scaffolding copy.""" copy( ".", tmp_path, data={"odoo_version": supported_odoo_version}, force=True, vcs_ref="HEAD", ) qa_run = docker[ "container", "run", "--rm", "--privileged", f"-v{tmp_path}:{tmp_path}:z", "-v/var/run/docker.sock:/var/run/docker.sock:z", f"-w{tmp_path}", "-eADDON_CATEGORIES=-p", "-eCOMPOSE_FILE=test.yaml", f"-eODOO_MAJOR={int(supported_odoo_version)}", f"-eODOO_MINOR={supported_odoo_version:.1f}", "tecnativa/doodba-qa", ] try: qa_run["secrets-setup"] & FG qa_run["networks-autocreate"] & FG qa_run["build"] & FG qa_run["closed-prs"] & FG qa_run["flake8"] & FG qa_run["pylint"] & FG qa_run["addons-install"] & FG qa_run["coverage"] & FG finally: qa_run["shutdown"] & FG invoke["-r", tmp_path, "stop", "--purge"] & FG
def test_alt_domains_rules(tmp_path: Path, cloned_template: Path): """Asegurese de que las redirecciones de dominios alternativos sean buenas para Traefik.""" copy( str(cloned_template), str(tmp_path), vcs_ref="HEAD", force=True, data={ "domain_prod": "www.ejemplo.com", "domain_prod_alternatives": [ "old.ejemplo.com", "ejemplo.com", "ejemplo.org", "www.ejemplo.org", ], }, ) with local.cwd(tmp_path): git("add", "prod.yaml") pre_commit("run", "-a", retcode=1) expected = Path("tests", "samples", "alt-domains", "prod.yaml").read_text() generated = (tmp_path / "prod.yaml").read_text() generated_scalar = yaml.load(generated) # Cualquiera de estos caracteres en una etiqueta traefik es un error casi seguro error_chars = ("\n", "'", '"') for service in generated_scalar["services"].values(): for key, value in service.get("labels", {}).items(): if not key.startswith("traefik."): continue for char in error_chars: assert char not in key assert char not in str(value) assert generated == expected
def test_pre_commit_config(tmp_path: Path, cloned_template: Path, supported_odoo_version: float): """Prueba que .pre-commit-config.yaml tiene configuraciones específicas OK.""" copy( str(cloned_template), str(tmp_path), vcs_ref="HEAD", force=True, data={"odoo_version": supported_odoo_version}, ) pre_commit_config = yaml.load( (tmp_path / ".pre-commit-config.yaml").read_text()) is_py3 = supported_odoo_version >= 11 found = 0 should_find = 1 for repo in pre_commit_config["repos"]: if repo["repo"] == "https://github.com/pre-commit/pre-commit-hooks": found += 1 if is_py3: assert {"id": "debug-statements"} in repo["hooks"] assert { "id": "fix-encoding-pragma", "args": ["--remove"] } in repo["hooks"] else: assert {"id": "debug-statements"} not in repo["hooks"] assert { "id": "fix-encoding-pragma", "args": ["--remove"] } not in repo["hooks"] assert {"id": "fix-encoding-pragma"} in repo["hooks"] assert found == should_find
def test_code_workspace_file(tmp_path: Path, cloned_template: Path): """The file is generated as expected.""" copy( str(cloned_template), str(tmp_path), vcs_ref="HEAD", force=True, ) assert (tmp_path / f"doodba.{tmp_path.name}.code-workspace").is_file() (tmp_path / f"doodba.{tmp_path.name}.code-workspace").rename( tmp_path / "doodba.other1.code-workspace" ) with local.cwd(tmp_path): invoke("write-code-workspace-file") assert (tmp_path / "doodba.other1.code-workspace").is_file() assert not (tmp_path / f"doodba.{tmp_path.name}.code-workspace").is_file() # Do a stupid and dirty git clone to check it's sorted fine git("clone", cloned_template, Path("odoo", "custom", "src", "zzz")) invoke("write-code-workspace-file", "-c", "doodba.other2.code-workspace") assert not (tmp_path / f"doodba.{tmp_path.name}.code-workspace").is_file() assert (tmp_path / "doodba.other1.code-workspace").is_file() assert (tmp_path / "doodba.other2.code-workspace").is_file() with (tmp_path / "doodba.other2.code-workspace").open() as fp: workspace_definition = json.load(fp) assert workspace_definition == { "folders": [ {"path": "odoo/custom/src/zzz"}, {"path": "odoo/custom/src/private"}, {"path": "."}, ] }
def test_alt_domains_rules(tmp_path: Path, cloned_template: Path): """Make sure alt domains redirections are good for Traefik.""" copy( str(cloned_template), str(tmp_path), vcs_ref="HEAD", force=True, data={ "domain_prod": "www.example.com", "domain_prod_alternatives": [ "old.example.com", "example.com", "example.org", "www.example.org", ], }, ) with local.cwd(tmp_path): git("add", "prod.yaml") pre_commit("run", "-a", retcode=1) expected = Path("tests", "samples", "alt-domains", "prod.yaml").read_text() generated = (tmp_path / "prod.yaml").read_text() generated_scalar = yaml.load(generated) # Any of these characters in a traefik label is an error almost for sure error_chars = ("\n", "'", '"') for service in generated_scalar["services"].values(): for key, value in service.get("labels", {}).items(): if not key.startswith("traefik."): continue for char in error_chars: assert char not in key assert char not in str(value) assert generated == expected
def test_no_pytest_settings(tmp_path: Path, cloned_template: Path): """Test that a template can be rendered from zero with different input data.""" with local.cwd(cloned_template): copy( ".", str(tmp_path), vcs_ref="test", force=True, data={ "project_name": "docker-test", "project_owner": "Test", "dockerhub_image": "test/test", "pytest": False, }, ) with local.cwd(tmp_path): # Check that files exist assert Path(".github", "workflows", "ci.yml").exists() assert Path(".copier-answers.image-template.yml").exists() # Tests shouldn't exist assert not Path("pytest.ini").exists() assert not Path("pyproject.toml").exists() assert not Path("tests/conftest.py").exists() # Validate CI config with Path(".github", "workflows", "ci.yml").open("r") as f: content = f.read() yaml_data = yaml.safe_load(content) # Validate according to Github Actions expected syntax validate_schema(yaml_data, cloned_template)
def test_exclude_recursive_negate(tmp_path): """Copy is done properly when copy_me.txt is the sole file copied.""" src = f"{PROJECT_TEMPLATE}_exclude_negate" copy(src, tmp_path) assert (tmp_path / "copy_me.txt").exists() assert (tmp_path / "copy_me.txt").is_file() assert not (tmp_path / "do_not_copy_me.txt").exists()
def test_mqt_configs_synced(tmp_path: Path, cloned_template: Path, any_odoo_version: float): """Make sure configs from MQT are in sync.""" copy( str(cloned_template), str(tmp_path), vcs_ref="test", force=True, data={"odoo_version": any_odoo_version}, ) tmp_oca_path = tmp_path / ".." / "oca-addons-repo-files" tmp_oca_path.mkdir() copy( str(Path("vendor", "oca-addons-repo-template")), tmp_oca_path, vcs_ref="HEAD", force=True, data={ "odoo_version": any_odoo_version if any_odoo_version >= 13 else "13.0" }, exclude=["**", "!.pylintrc*"], ) good_diffs = Path("tests", "samples", "mqt-diffs") for conf in (".pylintrc", ".pylintrc-mandatory"): good = (good_diffs / f"v{any_odoo_version}-{conf}.diff").read_text() tested = diff(tmp_path / conf, tmp_oca_path / conf, retcode=1) assert good == tested
def test_default_settings(tmp_path: Path, cloned_template: Path): """Test that a template can be rendered from zero.""" with local.cwd(cloned_template): copy( ".", str(tmp_path), vcs_ref="test", force=True, data={ "project_name": "docker-test", "project_owner": "Test", "dockerhub_image": "test/test", }, ) with local.cwd(tmp_path): # Check that files exist assert Path(".github", "workflows", "ci.yml").exists() assert Path(".copier-answers.image-template.yml").exists() # Tests are included by default assert Path("pytest.ini").exists() assert Path("pyproject.toml").exists() assert Path("tests/conftest.py").exists() # Validate CI config with Path(".github", "workflows", "ci.yml").open("r") as f: content = f.read() yaml_data = yaml.safe_load(content) # Ensure project data propagated assert ( yaml_data["jobs"]["build-push"]["env"]["DOCKERHUB_IMAGE_NAME"] == "test/test" ) # Validate according to Github Actions expected syntax validate_schema(yaml_data, cloned_template)
def test_default_settings(tmp_path: Path, any_odoo_version: float, cloned_template: Path): """Prueba que una plantilla renderizada de cero este OK para cada version. No se dan parámetros aparte de odoo_version. Esto prueba que los andamios funcionan bien con respuestas predeterminadas. """ dst = tmp_path / f"v{any_odoo_version:.1f}" with local.cwd(cloned_template): copy( ".", str(dst), vcs_ref="test", force=True, data={"odoo_version": any_odoo_version}, ) with local.cwd(dst): # TODO When copier runs pre-commit before extracting diff, make sure # here that it works as expected Path(dst, "odoo", "auto", "addons").rmdir() Path(dst, "odoo", "auto").rmdir() git("add", ".") git("commit", "-am", "Hello World", retcode=1) # pre-commit fails git("commit", "-am", "Hello World") # El resultado coincide con lo que esperamos. diff( "--context=3", "--exclude=.git", "--recursive", local.cwd / "tests" / "default_settings" / f"v{any_odoo_version:.1f}", dst, )
def test_pre_commit_autoinstall(tmp_path: Path, supported_odoo_version: float): """Test that pre-commit is automatically (un)installed in alien repos. This test is slower because it has to download and build OCI images and download git code, so it's only executed against these Odoo versions: - 10.0 because it's Python 2 and has no pre-commit configurations in OCA. - 13.0 because it's Python 3 and has pre-commit configurations in OCA. """ if supported_odoo_version not in {10.0, 13.0}: pytest.skip("this test is only tested with other odoo versions") copy( ".", str(tmp_path), vcs_ref="HEAD", force=True, data={"odoo_version": supported_odoo_version}, ) with local.cwd(tmp_path): with (tmp_path / "odoo" / "custom" / "src" / "addons.yaml").open("w") as fd: yaml.dump({"server-tools": "*"}, fd) # User can download git code from any folder with local.cwd(tmp_path / "odoo" / "custom" / "src" / "private"): invoke("git-aggregate") # Check pre-commit is properly (un)installed pre_commit_present = supported_odoo_version >= 13.0 server_tools_git = ( tmp_path / "odoo" / "custom" / "src" / "server-tools" / ".git" ) assert server_tools_git.is_dir() assert ( server_tools_git / "hooks" / "pre-commit" ).is_file() == pre_commit_present # Remove source code, it can use a lot of disk space rmtree(tmp_path)
def test_default_settings(tmp_path: Path, any_odoo_version: float, cloned_template: Path): """Test that a template rendered from zero is OK for each version. No params are given apart from odoo_version. This tests that scaffoldings render fine with default answers. """ dst = tmp_path / f"v{any_odoo_version:.1f}" with local.cwd(cloned_template): copy( ".", str(dst), vcs_ref="test", force=True, data={"odoo_version": any_odoo_version}, ) with local.cwd(dst): # TODO When copier runs pre-commit before extracting diff, make sure # here that it works as expected Path(dst, "odoo", "auto", "addons").rmdir() Path(dst, "odoo", "auto").rmdir() git("add", ".") git("commit", "-am", "Hello World", retcode=1) # pre-commit fails git("commit", "-am", "Hello World") # The result matches what we expect diff( "--context=3", "--exclude=.git", "--recursive", local.cwd / "tests" / "default_settings" / f"v{any_odoo_version:.1f}", dst, )
def test_prod_alt_domains(tmp_path: Path, any_odoo_version: float, cloned_template: Path): """Test prod alt domains are produced properly.""" copy( src_path=str(cloned_template), dst_path=str(tmp_path), vcs_ref="test", force=True, data={ "odoo_version": any_odoo_version, "domain_prod": "main.example.com", "domain_prod_alternatives": ["alt0.example.com", "alt1.example.com"], }, ) prod = yaml.safe_load((tmp_path / "prod.yaml").read_text()) assert ("${DOMAIN_PROD}" in prod["services"]["odoo"]["labels"] ["traefik.longpolling.frontend.rule"]) assert ("${DOMAIN_PROD}" in prod["services"]["odoo"]["labels"]["traefik.www.frontend.rule"]) assert ("${DOMAIN_PROD_ALT_0}" in prod["services"]["odoo"]["labels"] ["traefik.alt-0.frontend.redirect.regex"]) assert ("${DOMAIN_PROD}" in prod["services"]["odoo"]["labels"] ["traefik.alt-0.frontend.redirect.replacement"]) assert ( "${DOMAIN_PROD_ALT_1}" in prod["services"]["odoo"]["labels"]["traefik.alt-1.frontend.rule"]) assert ("${DOMAIN_PROD_ALT_1}" in prod["services"]["odoo"]["labels"] ["traefik.alt-1.frontend.redirect.regex"]) assert ("${DOMAIN_PROD}" in prod["services"]["odoo"]["labels"] ["traefik.alt-1.frontend.redirect.replacement"]) assert ( "${DOMAIN_PROD_ALT_1}" in prod["services"]["odoo"]["labels"]["traefik.alt-1.frontend.rule"])
def test_pre_commit_autoinstall(tmp_path: Path, supported_odoo_version: float): """Testea que pre-commit se (des)instala automaticamente en repos alien. Esta prueba es más lenta porque tiene que descargar y construir imágenes OCI y descargar código git, por lo que solo se ejecuta en estas versiones de Odoo: - 10.0 porque es Python 2 y no tiene configuraciones de confirmación previa en OCA. - 13.0 porque es Python 3 y tiene configuraciones de confirmación previa en OCA.. """ if supported_odoo_version not in {10.0, 13.0}: pytest.skip("esta prueba solo se testea con otras versiones de odoo") copy( ".", str(tmp_path), vcs_ref="HEAD", force=True, data={"odoo_version": supported_odoo_version}, ) with local.cwd(tmp_path): with (tmp_path / "odoo" / "custom" / "src" / "addons.yaml").open("w") as fd: yaml.dump({"server-tools": "*"}, fd) # El usuario puede descargar el código git desde cualquier carpeta with local.cwd(tmp_path / "odoo" / "custom" / "src" / "private"): invoke("git-aggregate") # Check pre-commit está correctamente (des)instalado pre_commit_present = supported_odoo_version >= 13.0 server_tools_git = (tmp_path / "odoo" / "custom" / "src" / "server-tools" / ".git") assert server_tools_git.is_dir() assert (server_tools_git / "hooks" / "pre-commit").is_file() == pre_commit_present # Elimine el código fuente, puede usar mucho espacio en disco rmtree(tmp_path)
def test_backup_config( backup_deletion: bool, backup_dst: Union[None, str], cloned_template: Path, smtp_relay_host: Union[None, str], supported_odoo_version: float, tmp_path: Path, ): """Test that backup deletion setting is respected.""" data = { "backup_deletion": backup_deletion, "backup_dst": backup_dst, "odoo_version": supported_odoo_version, "smtp_relay_host": smtp_relay_host, } # Remove parameter if False, to test this is the properly default value if not backup_deletion: del data["backup_deletion"] with local.cwd(tmp_path): copy( src_path=str(cloned_template), dst_path=".", vcs_ref="test", force=True, data=data, ) prod = yaml.safe_load(docker_compose("-f", "prod.yaml", "config")) # Check backup service existence if not backup_dst: assert "backup" not in prod["services"] return # Check selected duplicity image if backup_dst == "s3://example": assert prod["services"]["backup"][ "image"] == "tecnativa/duplicity:postgres-s3" else: assert prod["services"]["backup"][ "image"] == "tecnativa/duplicity:postgres" # Check SMTP configuration if smtp_relay_host: assert "smtp" in prod["services"] assert prod["services"]["backup"]["environment"][ "SMTP_HOST"] == "smtplocal" assert "EMAIL_FROM" in prod["services"]["backup"]["environment"] assert "EMAIL_TO" in prod["services"]["backup"]["environment"] else: assert "smtp" not in prod["services"] assert "SMTP_HOST" not in prod["services"]["backup"]["environment"] assert "EMAIL_FROM" not in prod["services"]["backup"]["environment"] assert "EMAIL_TO" not in prod["services"]["backup"]["environment"] # Check backup deletion if backup_deletion: assert (prod["services"]["backup"]["environment"]["JOB_800_WHAT"] == "dup --force remove-older-than 3M $$DST") assert prod["services"]["backup"]["environment"][ "JOB_800_WHEN"] == "weekly" else: assert "JOB_800_WHAT" not in prod["services"]["backup"]["environment"] assert "JOB_800_WHEN" not in prod["services"]["backup"]["environment"]
def test_doodba_main_domain_label(cloned_template: Path, tmp_path: Path): """Make sure the doodba.domain.main label is correct.""" copy( str(cloned_template), str(tmp_path), vcs_ref="test", force=True, data={ "domains_prod": [ { "hosts": ["not0.prod.example.com", "not1.prod.example.com"], "redirect_to": "yes.prod.example.com", }, { "hosts": ["not3.prod.example.com", "not4.prod.example.com"], "path_prefixes": ["/insecure/"], "entrypoints": ["web-insecure"], }, { "hosts": ["yes.prod.example.com", "not5.prod.example.com"] }, ], "domains_test": [ { "hosts": ["not0.test.example.com", "not1.test.example.com"], "redirect_to": "yes.test.example.com", }, { "hosts": ["not3.test.example.com", "not4.test.example.com"], "path_prefixes": ["/insecure/"], "entrypoints": ["web-insecure"], }, { "hosts": ["yes.test.example.com", "not5.test.example.com"] }, ], }, ) with local.cwd(tmp_path): prod_config = yaml.load(docker_compose("-f", "prod.yaml", "config")) test_config = yaml.load(docker_compose("-f", "test.yaml", "config")) assert (prod_config["services"]["odoo"]["labels"]["doodba.domain.main"] == "yes.prod.example.com") assert (test_config["services"]["odoo"]["labels"]["doodba.domain.main"] == "yes.test.example.com") # These labels must be present to avoid that Traefik 1 builds its own # main domain assumption and tries to download its Let's Encrypt certs, # which would possibly fail and hit LE's rate limits # TODO Remove asserts when dropping Traefik 1 support assert (prod_config["services"]["odoo"]["labels"]["traefik.domain"] == "yes.prod.example.com") assert (test_config["services"]["odoo"]["labels"]["traefik.domain"] == "yes.test.example.com")
def test_template_update_badge(tmp_path: Path, cloned_template: Path): """Pruebe que la insignia de actualizacion de plantilla este formateada correctamente.""" tag = "v99999.0.0-99999-bye-bye" with local.cwd(cloned_template): git("tag", "--delete", "test") git("tag", "--force", tag) copy(str(cloned_template), str(tmp_path), vcs_ref=tag, force=True) expected = "[![ultimo andamio actualizado](https://img.shields.io/badge/ultimo%20andamio%20actualizado-v99999.0.0--99999--bye--bye-informational)](https://github.com/dued/andamio-base/tree/v99999.0.0-99999-bye-bye)" assert expected in (tmp_path / "README.md").read_text()
def test_template_update_badge(tmp_path: Path, cloned_template: Path): """Test that the template update badge is properly formatted.""" tag = "v99999.0.0-99999-bye-bye" with local.cwd(cloned_template): git("tag", "--delete", "test") git("tag", "--force", tag) copy(str(cloned_template), str(tmp_path), vcs_ref=tag, force=True) expected = "[![Last template update](https://img.shields.io/badge/last%20template%20update-v99999.0.0--99999--bye--bye-informational)](https://github.com/Tecnativa/doodba-copier-template/tree/v99999.0.0-99999-bye-bye)" assert expected in (tmp_path / "README.md").read_text()
def test_cidr_whitelist_rules( tmp_path: Path, cloned_template: Path, supported_odoo_version: float ): """Make sure CIDR whitelist redirections are good for Traefik.""" copy( str(cloned_template), str(tmp_path), vcs_ref="HEAD", force=True, data={ "odoo_version": supported_odoo_version, "project_name": "test-cidr-whitelist", "cidr_whitelist": ["123.123.123.123/24", "456.456.456.456"], "domains_prod": [{"hosts": ["www.example.com"]}], "domains_test": [{"hosts": ["demo.example.com"]}], }, ) # TODO Use Traefik to test this, instead of asserting labels key = ("test-cidr-whitelist-%.1f" % supported_odoo_version).replace(".", "-") with local.cwd(tmp_path): git("add", "prod.yaml", "test.yaml") pre_commit("run", "-a", retcode=None) prod = yaml.safe_load(docker_compose("-f", "prod.yaml", "config")) test = yaml.safe_load(docker_compose("-f", "test.yaml", "config")) # Assert prod.yaml assert ( prod["services"]["odoo"]["labels"][ f"traefik.http.middlewares.{key}-prod-whitelist.IPWhiteList.sourceRange" ] == "123.123.123.123/24, 456.456.456.456" ) assert f"{key}-prod-whitelist" in prod["services"]["odoo"]["labels"][ f"traefik.http.routers.{key}-prod-main-0.middlewares" ].split(", ") assert f"{key}-prod-whitelist" in prod["services"]["odoo"]["labels"][ f"traefik.http.routers.{key}-prod-longpolling-0.middlewares" ].split(", ") assert f"{key}-prod-whitelist" in prod["services"]["odoo"]["labels"][ f"traefik.http.routers.{key}-prod-forbiddenCrawlers-0.middlewares" ].split(", ") # Assert test.yaml assert ( test["services"]["smtp"]["labels"][ f"traefik.http.middlewares.{key}-test-whitelist.IPWhiteList.sourceRange" ] == "123.123.123.123/24, 456.456.456.456" ) assert f"{key}-test-whitelist" in test["services"]["odoo"]["labels"][ f"traefik.http.routers.{key}-test-forbiddenCrawlers-0.middlewares" ].split(", ") assert f"{key}-test-whitelist" in test["services"]["odoo"]["labels"][ f"traefik.http.routers.{key}-test-longpolling-0.middlewares" ].split(", ") assert f"{key}-test-whitelist" in test["services"]["smtp"]["labels"][ f"traefik.http.routers.{key}-test-mailhog-0.middlewares" ].split(", ")
def test_no_vscode_in_private(tmp_path: Path): """Make sure .vscode folders are git-ignored in private folder.""" copy(".", str(tmp_path), vcs_ref="HEAD", force=True) with local.cwd(tmp_path): git("add", ".") git("commit", "--no-verify", "-am", "hello world") vscode = tmp_path / "odoo" / "custom" / "src" / "private" / ".vscode" vscode.mkdir() (vscode / "something").touch() assert not git("status", "--porcelain")
def test_dotdocker_ignore_content(tmp_path: Path, cloned_template: Path): """Everything inside .docker must be ignored.""" copy( str(cloned_template), str(tmp_path), vcs_ref="HEAD", force=True, ) with local.cwd(tmp_path): git("add", ".") git("commit", "-am", "hello", retcode=1) git("commit", "-am", "hello") (tmp_path / ".docker" / "some-file").touch() assert not git("status", "--porcelain")
def test_license_whitespace_prefix(tmp_path: Path, cloned_template: Path, project_license): dst = tmp_path / "dst" copy( str(cloned_template), str(dst), vcs_ref="test", force=True, data={"project_license": project_license}, ) assert (dst / "LICENSE").read_text().startswith(" ")
def test_no_python_write_bytecode_in_devel( tmp_path: Path, cloned_template: Path, supported_odoo_version: float ): copy( str(cloned_template), str(tmp_path), vcs_ref="HEAD", force=True, data={"odoo_version": supported_odoo_version}, ) devel = yaml.safe_load((tmp_path / "devel.yaml").read_text()) assert devel["services"]["odoo"]["environment"]["PYTHONDONTWRITEBYTECODE"] == 1
def test_gitlab_badges(tmp_path: Path): """Las insignias de Gitlab estan formateadas correctamente en README.""" copy( ".", str(tmp_path), vcs_ref="HEAD", force=True, data={"gitlab_url": "https://gitlab.ejemplo.com/dued/mi-badged-odoo"}, ) expected_badges = dedent(""" [![pipeline status](https://gitlab.ejemplo.com/dued/mi-badged-odoo/badges/13.0/pipeline.svg)](https://gitlab.ejemplo.com/dued/mi-badged-odoo/commits/13.0) [![coverage report](https://gitlab.ejemplo.com/dued/mi-badged-odoo/badges/13.0/coverage.svg)](https://gitlab.ejemplo.com/dued/mi-badged-odoo/commits/13.0) """) assert expected_badges.strip() in (tmp_path / "README.md").read_text()
def test_doodba_main_domain_label(cloned_template: Path, tmp_path: Path): """Make sure the doodba.domain.main label is correct.""" copy( str(cloned_template), str(tmp_path), vcs_ref="test", force=True, data={ "domains_prod": [ { "hosts": ["not0.prod.example.com", "not1.prod.example.com"], "redirect_to": "yes.prod.example.com", }, { "hosts": ["not3.prod.example.com", "not4.prod.example.com"], "path_prefixes": ["/insecure/"], "entrypoints": ["web-insecure"], }, { "hosts": ["yes.prod.example.com", "not5.prod.example.com"] }, ], "domains_test": [ { "hosts": ["not0.test.example.com", "not1.test.example.com"], "redirect_to": "yes.test.example.com", }, { "hosts": ["not3.test.example.com", "not4.test.example.com"], "path_prefixes": ["/insecure/"], "entrypoints": ["web-insecure"], }, { "hosts": ["yes.test.example.com", "not5.test.example.com"] }, ], }, ) with local.cwd(tmp_path): prod_config = yaml.load(docker_compose("-f", "prod.yaml", "config")) test_config = yaml.load(docker_compose("-f", "test.yaml", "config")) assert (prod_config["services"]["odoo"]["labels"]["doodba.domain.main"] == "yes.prod.example.com") assert (test_config["services"]["odoo"]["labels"]["doodba.domain.main"] == "yes.test.example.com")
def test_cidr_whitelist_rules(tmp_path: Path, cloned_template: Path): """Make sure CIDR whitelist redirections are good for Traefik.""" copy( str(cloned_template), str(tmp_path), vcs_ref="HEAD", force=True, data={"cidr_whitelist": ["123.123.123.123/24", "456.456.456.456"]}, ) with local.cwd(tmp_path): git("add", "prod.yaml", "test.yaml") pre_commit("run", "-a", retcode=1) expected = Path("tests", "samples", "cidr-whitelist") assert (tmp_path / "prod.yaml").read_text() == (expected / "prod.yaml").read_text() assert (tmp_path / "test.yaml").read_text() == (expected / "test.yaml").read_text()
def run(): # pragma:no cover if len(sys.argv) == 1 or sys.argv[1] == "help": parser.print_help(sys.stderr) print() sys.exit(1) if sys.argv[1] == "version": sys.stdout.write(__version__) print() sys.exit(1) args = parser.parse_args() kwargs = vars(args) data = {"make_secret": lambda: sha512(urandom(48)).hexdigest()} copy(kwargs.pop("source"), kwargs.pop("dest"), data=data, **kwargs)
def test_gitlab_badges(tmp_path: Path): """Gitlab badges are properly formatted in README.""" copy( ".", str(tmp_path), vcs_ref="HEAD", force=True, data={ "gitlab_url": "https://gitlab.example.com/Tecnativa/my-badged-odoo" }, ) expected_badges = dedent(""" [![pipeline status](https://gitlab.example.com/Tecnativa/my-badged-odoo/badges/13.0/pipeline.svg)](https://gitlab.example.com/Tecnativa/my-badged-odoo/commits/13.0) [![coverage report](https://gitlab.example.com/Tecnativa/my-badged-odoo/badges/13.0/coverage.svg)](https://gitlab.example.com/Tecnativa/my-badged-odoo/commits/13.0) """) assert expected_badges.strip() in (tmp_path / "README.md").read_text()
def test_cidr_whitelist_rules(tmp_path: Path, cloned_template: Path): """Asegurese de que las redirecciones de la lista blanca CIDR sean buenas para Traefik.""" copy( str(cloned_template), str(tmp_path), vcs_ref="HEAD", force=True, data={"cidr_whitelist": ["123.123.123.123/24", "456.456.456.456"]}, ) with local.cwd(tmp_path): git("add", "prod.yaml", "test.yaml") pre_commit("run", "-a", retcode=1) expected = Path("tests", "samples", "cidr-whitelist") assert (tmp_path / "prod.yaml").read_text() == (expected / "prod.yaml").read_text() assert (tmp_path / "test.yaml").read_text() == (expected / "test.yaml").read_text()
def test_mqt_configs_synced(tmp_path: Path, cloned_template: Path, any_odoo_version: float): """Make sure configs from MQT are in sync.""" copy( str(cloned_template), str(tmp_path), vcs_ref="test", force=True, data={"odoo_version": any_odoo_version}, ) mqt = Path("vendor", "maintainer-quality-tools", "sample_files", "pre-commit-13.0") good_diffs = Path("tests", "samples", "mqt-diffs") for conf in (".pylintrc", ".pylintrc-mandatory"): good = (good_diffs / f"v{any_odoo_version}-{conf}.diff").read_text() tested = diff(tmp_path / conf, mqt / conf, retcode=1) assert good == tested