Skip to content

Commit

Permalink
fix deploy command tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sh-rp committed Oct 15, 2024
1 parent b7a1713 commit 9d4eec1
Showing 1 changed file with 41 additions and 36 deletions.
77 changes: 41 additions & 36 deletions tests/cli/test_deploy_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from dlt.cli.exceptions import CliCommandInnerException
from dlt.pipeline.exceptions import CannotRestorePipelineException
from dlt.cli.deploy_command_helpers import get_schedule_description
from dlt.cli.exceptions import CliCommandException

from tests.utils import TEST_STORAGE_ROOT, reset_providers, test_storage

Expand Down Expand Up @@ -47,13 +48,14 @@ def test_deploy_command_no_repo(
)

# test wrapper
rc = _dlt.deploy_command_wrapper(
"debug_pipeline.py",
deployment_method,
deploy_command.COMMAND_DEPLOY_REPO_LOCATION,
**deployment_args
)
assert rc == -3
with pytest.raises(CliCommandException) as ex:
_dlt.deploy_command_wrapper(
"debug_pipeline.py",
deployment_method,
deploy_command.COMMAND_DEPLOY_REPO_LOCATION,
**deployment_args
)
assert ex._excinfo[1].error_code == -4


@pytest.mark.parametrize("deployment_method,deployment_args", DEPLOY_PARAMS)
Expand All @@ -80,13 +82,13 @@ def test_deploy_command(
**deployment_args
)
assert "Your current repository has no origin set" in py_ex.value.args[0]
rc = _dlt.deploy_command_wrapper(
"debug_pipeline.py",
deployment_method,
deploy_command.COMMAND_DEPLOY_REPO_LOCATION,
**deployment_args
)
assert rc == -5
with pytest.raises(CliCommandInnerException):
_dlt.deploy_command_wrapper(
"debug_pipeline.py",
deployment_method,
deploy_command.COMMAND_DEPLOY_REPO_LOCATION,
**deployment_args
)

# we have a repo that was never run
Remote.create(repo, "origin", "[email protected]:rudolfix/dlt-cmd-test-2.git")
Expand All @@ -97,18 +99,19 @@ def test_deploy_command(
deploy_command.COMMAND_DEPLOY_REPO_LOCATION,
**deployment_args
)
rc = _dlt.deploy_command_wrapper(
"debug_pipeline.py",
deployment_method,
deploy_command.COMMAND_DEPLOY_REPO_LOCATION,
**deployment_args
)
assert rc == -2
with pytest.raises(CliCommandException) as ex:
rc = _dlt.deploy_command_wrapper(
"debug_pipeline.py",
deployment_method,
deploy_command.COMMAND_DEPLOY_REPO_LOCATION,
**deployment_args
)
assert ex._excinfo[1].error_code == -3

# run the script with wrong credentials (it is postgres there)
venv = Venv.restore_current()
# mod environ so wrong password is passed to override secrets.toml
pg_credentials = os.environ.pop("DESTINATION__POSTGRES__CREDENTIALS")
pg_credentials = os.environ.pop("DESTINATION__POSTGRES__CREDENTIALS", "")
# os.environ["DESTINATION__POSTGRES__CREDENTIALS__PASSWORD"] = "password"
with pytest.raises(CalledProcessError):
venv.run_script("debug_pipeline.py")
Expand All @@ -121,13 +124,14 @@ def test_deploy_command(
**deployment_args
)
assert "The last pipeline run ended with error" in py_ex2.value.args[0]
rc = _dlt.deploy_command_wrapper(
"debug_pipeline.py",
deployment_method,
deploy_command.COMMAND_DEPLOY_REPO_LOCATION,
**deployment_args
)
assert rc == -2
with pytest.raises(CliCommandException) as ex:
_dlt.deploy_command_wrapper(
"debug_pipeline.py",
deployment_method,
deploy_command.COMMAND_DEPLOY_REPO_LOCATION,
**deployment_args
)
assert ex._excinfo[1].error_code == -3

os.environ["DESTINATION__POSTGRES__CREDENTIALS"] = pg_credentials
# also delete secrets so credentials are not mixed up on CI
Expand Down Expand Up @@ -172,10 +176,11 @@ def test_deploy_command(
**deployment_args
)
with echo.always_choose(False, always_choose_value=True):
rc = _dlt.deploy_command_wrapper(
"no_pipeline.py",
deployment_method,
deploy_command.COMMAND_DEPLOY_REPO_LOCATION,
**deployment_args
)
assert rc == -4
with pytest.raises(CliCommandException) as ex:
_dlt.deploy_command_wrapper(
"no_pipeline.py",
deployment_method,
deploy_command.COMMAND_DEPLOY_REPO_LOCATION,
**deployment_args
)
assert ex._excinfo[0].error_code == -5

0 comments on commit 9d4eec1

Please sign in to comment.