|
1 | 1 | """Integration tests for infrahubctl commands.""" |
2 | 2 |
|
3 | 3 | import sys |
| 4 | +import tempfile |
| 5 | +from pathlib import Path |
4 | 6 | from unittest import mock |
5 | 7 |
|
6 | 8 | import pytest |
| 9 | +import yaml |
7 | 10 | from typer.testing import CliRunner |
8 | 11 |
|
9 | 12 | from infrahub_sdk.client import InfrahubClient |
@@ -288,3 +291,31 @@ def test_repo_list(self, mock_repositories_list) -> None: |
288 | 291 | result = runner.invoke(app, ["repository", "list", "--branch", "main"]) |
289 | 292 | assert result.exit_code == 0 |
290 | 293 | assert strip_color(result.stdout) == read_fixture("output.txt", "integration/test_infrahubctl/repository_list") |
| 294 | + |
| 295 | + def test_repo_init(self) -> None: |
| 296 | + with tempfile.TemporaryDirectory() as temp_dst, tempfile.NamedTemporaryFile( |
| 297 | + mode="w", suffix=".yml", delete=False, encoding="utf-8" |
| 298 | + ) as temp_yaml: |
| 299 | + dst = Path(temp_dst) |
| 300 | + yaml_path = Path(temp_yaml.name) |
| 301 | + |
| 302 | + answers = { |
| 303 | + "generators": True, |
| 304 | + "menus": True, |
| 305 | + "project_name": "test", |
| 306 | + "queries": True, |
| 307 | + "scripts": True, |
| 308 | + "tests": True, |
| 309 | + "transforms": True, |
| 310 | + } |
| 311 | + |
| 312 | + yaml.safe_dump(answers, temp_yaml) |
| 313 | + temp_yaml.close() |
| 314 | + runner.invoke(app, ["repository", "init", str(dst), "--data", str(yaml_path)]) |
| 315 | + |
| 316 | + coppied_answers = yaml.safe_load((dst / ".copier-answers.yml").read_text()) |
| 317 | + coppied_answers.pop("_src_path") |
| 318 | + |
| 319 | + assert coppied_answers == answers |
| 320 | + assert (dst / "generators").is_dir() |
| 321 | + assert (dst / "pyproject.toml").is_file() |
0 commit comments