Skip to content

Commit

Permalink
refactor: move codebase build confirmation test to domain test file
Browse files Browse the repository at this point in the history
  • Loading branch information
rav-pradhan committed Nov 5, 2024
1 parent cbadbbe commit 17af315
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 38 deletions.
25 changes: 24 additions & 1 deletion tests/platform_helper/domain/test_codebase.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def test_codebase_build_does_not_trigger_build_without_an_application():
]
)

@pytest.mark.focus
@patch("subprocess.run")
def test_codebase_build_does_not_trigger_without_a_valid_commit_hash(mock_subprocess_run):
mocks = CodebaseMocks()
Expand All @@ -60,4 +61,26 @@ def test_codebase_build_does_not_trigger_without_a_valid_commit_hash(mock_subpro
fg="red",
),
]
)
)

@pytest.mark.focus
@patch("click.confirm")
@patch("subprocess.run")
def test_codebase_build_does_not_trigger_build_without_confirmation(
mock_subprocess_run, mock_click_confirm
):
mocks = CodebaseMocks()
codebase = Codebase(**mocks.params())

mock_subprocess_run.return_value.stderr = ""
mock_click_confirm.return_value = False

codebase.build("test-application", "application", "ab1c234")

mocks.echo_fn.assert_has_calls(
[
call(
"""Your build was not triggered.""",
),
]
)
62 changes: 25 additions & 37 deletions tests/platform_helper/test_command_codebase.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,6 @@ def test_codebase_build_aborts_with_a_nonexistent_commit_hash(
mock_codebase_object_instance.build.side_effect = SystemExit(1)
os.environ["AWS_PROFILE"] = "foo"

# # Set up the environment variable
# with patch.dict(os.environ, {"AWS_PROFILE": "foo"}):
# # Mock the AWS session
# mock_aws_session = MagicMock()
# mock_get_aws_session_or_abort.return_value = mock_aws_session

# Simulate subprocess.run returning a command error

# Invoke the CLI command
result = CliRunner().invoke(
build,
[
Expand All @@ -205,35 +196,32 @@ def test_codebase_build_aborts_with_a_nonexistent_commit_hash(

mock_codebase_object_instance.build.assert_called_once_with("test-application", "application", "nonexistent-commit-hash")
assert result.exit_code == 1
# assert (
# """The commit hash "nonexistent-commit-hash" either does not exist or you need to run `git fetch`."""
# in result.output
# )

@patch("click.confirm")
@patch("subprocess.run")
@patch("dbt_platform_helper.commands.codebase.get_aws_session_or_abort")
def test_codebase_build_does_not_trigger_build_without_confirmation(
self, get_aws_session_or_abort, mock_subprocess_run, mock_click_confirm
):
from dbt_platform_helper.commands.codebase import build

mock_subprocess_run.return_value.stderr = ""
mock_click_confirm.return_value = False

result = CliRunner().invoke(
build,
[
"--app",
"test-application",
"--codebase",
"application",
"--commit",
"ab1c23d",
],
)

assert """Your build was not triggered.""" in result.output
# @patch("dbt_platform_helper.commands.codebase.Codebase")
# def test_codebase_build_does_not_trigger_build_without_confirmation(
# self, mock_codebase_object
# ):

# # mock_subprocess_run.return_value.stderr = ""
# # mock_click_confirm.return_value = False

# mock_codebase_object_instance = mock_codebase_object.return_value
# mock_codebase_object_instance.build. =
# os.environ["AWS_PROFILE"] = "foo"

# result = CliRunner().invoke(
# build,
# [
# "--app",
# "test-application",
# "--codebase",
# "application",
# "--commit",
# "ab1c23d",
# ],
# )

# assert """Your build was not triggered.""" in result.output


class TestCodebaseDeploy:
Expand Down

0 comments on commit 17af315

Please sign in to comment.