Skip to content

Commit

Permalink
Add a check in config to set project type as playbook (#306)
Browse files Browse the repository at this point in the history
* Add a check in config to set project type as playbook when ansible-project is specified
  • Loading branch information
shatakshiiii authored Oct 18, 2024
1 parent a93ac24 commit 23c3fb8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/ansible_creator/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
22 changes: 22 additions & 0 deletions tests/units/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit 23c3fb8

Please sign in to comment.