From 23c3fb8c1d58f8f2c12c0eccf4d3808c6f0fee9b Mon Sep 17 00:00:00 2001 From: Shatakshi Mishra Date: Fri, 18 Oct 2024 18:36:34 +0530 Subject: [PATCH] Add a check in config to set project type as playbook (#306) * Add a check in config to set project type as playbook when ansible-project is specified --- src/ansible_creator/config.py | 3 +++ tests/units/test_basic.py | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/ansible_creator/config.py b/src/ansible_creator/config.py index 2cbe68e..d40d8ff 100644 --- a/src/ansible_creator/config.py +++ b/src/ansible_creator/config.py @@ -47,6 +47,9 @@ class Config: def __post_init__(self: Config) -> None: """Post process config values.""" + if self.project == "ansible-project": + object.__setattr__(self, "project", "playbook") + if self.collection: fqcn = self.collection.split(".", maxsplit=1) object.__setattr__(self, "namespace", fqcn[0]) diff --git a/tests/units/test_basic.py b/tests/units/test_basic.py index 508b7f8..f74338e 100644 --- a/tests/units/test_basic.py +++ b/tests/units/test_basic.py @@ -459,3 +459,25 @@ def test_coming_soon( stdout, stderr = capsys.readouterr() assert f"`{args}` command is coming soon" in stdout assert "Goodbye" in stderr + + +def test_config_post_init( + tmp_path: Path, + output: Output, +) -> None: + """Test for a check in post_init in Config class. + + Args: + tmp_path: Temporary directory path. + output: Output class object. + """ + config = Config( + creator_version="24.10.0", + output=output, + subcommand="init", + collection="foo.bar", + init_path=str(tmp_path / "test_path"), + project="ansible-project", + ) + config.__post_init__() + assert config.project == "playbook"