Skip to content

Commit

Permalink
Merge pull request #445 from statisticsnorway/feat/create-name-email-…
Browse files Browse the repository at this point in the history
…args

ssb-project create: support name and email args
  • Loading branch information
skykanin authored Jul 9, 2024
2 parents 7c0e944 + a033887 commit 2f7b028
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "ssb-project-cli"
version = "1.4.3"
version = "1.4.4"
description = "SSB Project CLI"
authors = ["Statistics Norway <[email protected]>"]
license = "MIT"
Expand Down
8 changes: 8 additions & 0 deletions src/ssb_project_cli/ssb_project/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ def create( # noqa: C901, S107
help="The git reference to check against. Supports branches, tags and commit hashes.",
),
] = None,
name: Annotated[
t.Optional[str], typer.Option("--name", help="Project author's full name.")
] = None,
email: Annotated[
t.Optional[str], typer.Option("--email", help="Project author's email.")
] = None,
no_kernel: Annotated[
bool,
typer.Option(
Expand All @@ -107,6 +113,8 @@ def create( # noqa: C901, S107
GITHUB_ORG_NAME,
template_git_url,
checkout,
name,
email,
verify_config,
handle_no_kernel_argument(no_kernel),
)
Expand Down
6 changes: 6 additions & 0 deletions src/ssb_project_cli/ssb_project/create/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ def create_project( # noqa: C901
github_org_name: str,
template_repo_url: str,
checkout: str | None,
name: str | None,
email: str | None,
verify_config: bool = True,
no_kernel: bool = False,
) -> None:
Expand All @@ -52,6 +54,8 @@ def create_project( # noqa: C901
github_org_name: Name of GitHub organization
template_repo_url: The Cookiecutter template URI.
checkout: The git reference to check against. Supports branches, tags and commit hashes.
name: The project author's name (optional).
email: The project author's email (optional).
verify_config: Determines if gitconfig is verified.
no_kernel: Determines if a kernel shall be generated or not.
"""
Expand Down Expand Up @@ -101,6 +105,8 @@ def create_project( # noqa: C901
template_repo_url,
checkout,
working_directory,
name=name,
email=email,
)
build_project(
project_directory,
Expand Down
28 changes: 22 additions & 6 deletions tests/unit/create_test/test_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ def test_create_copy_called(
False,
"",
None,
None,
None,
False,
)
assert mock_rmtree.call_count == 0
Expand All @@ -67,6 +69,8 @@ def test_default_checkout_value_set(
False,
STAT_TEMPLATE_REPO_URL,
None,
None,
None,
False,
)
assert _mock_build_project.call_args[-2][-3] == STAT_TEMPLATE_DEFAULT_REFERENCE
Expand All @@ -92,6 +96,8 @@ def test_rmtree_template_error(
False,
"",
None,
None,
None,
False,
)
assert mock_rmtree.call_count == 1
Expand All @@ -118,6 +124,8 @@ def test_rmtree_git_error(
False,
"",
None,
None,
None,
False,
)
assert mock_rmtree.call_count == 1
Expand All @@ -141,6 +149,8 @@ def test_specify_template_uri(
False,
"https://github.com/statisticsnorway/ssb-minimal-template",
None,
None,
None,
False,
)
assert mock_rmtree.call_count == 0
Expand Down Expand Up @@ -170,6 +180,8 @@ def test_project_is_lowercase_should_fail(
False,
"",
None,
None,
None,
False,
)

Expand All @@ -191,6 +203,8 @@ def test_project_dir_exists(mock_path_exists: Mock) -> None:
False,
"",
None,
None,
None,
False,
)
assert excinfo.value.code == 1
Expand All @@ -208,7 +222,7 @@ def test_is_valid_project_name() -> None:

@patch("ssb_project_cli.ssb_project.app.create_project", return_value=None)
def test_default_options_and_types(mock_create_project: Mock) -> None:
"""Check default options andt types retuned by the create typer CLI command."""
"""Check default options and types retuned by the create typer CLI command."""
# Check when all optional parameters are given
create(
"test_project",
Expand All @@ -219,26 +233,28 @@ def test_default_options_and_types(mock_create_project: Mock) -> None:
False,
"",
None,
None,
None,
False,
)
assert mock_create_project.call_count == 1
args, _ = mock_create_project.call_args
assert len(args) == 12
no_kernel = args[11]
assert len(args) == 14
no_kernel = args[13]
assert isinstance(no_kernel, bool) and not no_kernel

# Only mandatory parameters given, check default values and types of optional parameters.
create("test_project", "description", RepoPrivacy.internal)
assert mock_create_project.call_count == 2
args, _ = mock_create_project.call_args
assert len(args) == 12
assert len(args) == 14

add_github = args[3]
github_token = args[4]
verify_config = args[10]
verify_config = args[12]
template_repo_url = args[8]
checkout = args[9]
no_kernel = args[11]
no_kernel = args[13]
print(f"\ncheckout has type {type(checkout)} with content {checkout}")
assert (
isinstance(add_github, bool) and not add_github
Expand Down

0 comments on commit 2f7b028

Please sign in to comment.