Skip to content

Commit

Permalink
vdk-control-cli: use test_utils.assert_click_status for assertions (#477
Browse files Browse the repository at this point in the history
)

test_utils.assert_click_status works better since it's provides more
detailed error message and stack trace to root cause the error.

Signed-off-by: Antoni Ivanov <[email protected]>
  • Loading branch information
antoniivanov authored Nov 5, 2021
1 parent 40d4b64 commit 43f2a8f
Showing 1 changed file with 15 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ def test_deploy(httpserver: PluginHTTPServer, tmpdir: LocalPath):
"reason",
],
)
assert (
result.exit_code == 0
), f"result exit code is not 0, result output: {result.output}, exc: {result.exc_info}"
test_utils.assert_click_status(result, 0)

result = runner.invoke(
deploy,
Expand All @@ -78,9 +76,7 @@ def test_deploy(httpserver: PluginHTTPServer, tmpdir: LocalPath):
"reason",
],
)
assert (
result.exit_code == 0
), f"result exit code is not 0, result output: {result.output}, exc: {result.exc_info}"
test_utils.assert_click_status(result, 0)

assert os.path.exists(f"{test_job_path}.zip") is False

Expand All @@ -102,9 +98,7 @@ def test_deploy(httpserver: PluginHTTPServer, tmpdir: LocalPath):
"reason",
],
)
assert (
result.exit_code == 0
), f"result exit code is not 0, result output: {result.output}, exc: {result.exc_info}"
test_utils.assert_click_status(result, 0)

result = runner.invoke(
deploy,
Expand All @@ -123,9 +117,7 @@ def test_deploy(httpserver: PluginHTTPServer, tmpdir: LocalPath):
"json",
],
)
assert (
result.exit_code == 0
), f"result exit code is not 0, result output: {result.output}, exc: {result.exc_info}"
test_utils.assert_click_status(result, 0)
try:
json_result = json.loads(result.output)
except JSONDecodeError as error:
Expand Down Expand Up @@ -167,9 +159,7 @@ def test_deploy_reason(httpserver: PluginHTTPServer, tmpdir: LocalPath):
],
)

assert (
result.exit_code == 0
), f"result exit code is not 0, result output: {result.output}, exc: {result.exc_info}"
test_utils.assert_click_status(result, 0)


def test_deploy_enable_disable(httpserver: PluginHTTPServer, tmpdir: LocalPath):
Expand All @@ -184,16 +174,12 @@ def test_deploy_enable_disable(httpserver: PluginHTTPServer, tmpdir: LocalPath):
result = runner.invoke(
deploy, ["--enable", "-n", "test-job", "-t", "test-team", "-u", rest_api_url]
)
assert (
result.exit_code == 0
), f"result exit code is not 0, result output: {result.output}, exc: {result.exc_info}"
test_utils.assert_click_status(result, 0)

result = runner.invoke(
deploy, ["--disable", "-n", "test-job", "-t", "test-team", "-u", rest_api_url]
)
assert (
result.exit_code == 0
), f"result exit code is not 0, result output: {result.output}, exc: {result.exc_info}"
test_utils.assert_click_status(result, 0)


def test_deploy_show(httpserver: PluginHTTPServer, tmpdir: LocalPath):
Expand All @@ -216,9 +202,7 @@ def test_deploy_show(httpserver: PluginHTTPServer, tmpdir: LocalPath):
result = runner.invoke(
deploy, ["--show", "-n", "test-job", "-t", "test-team", "-u", rest_api_url]
)
assert (
result.exit_code == 0
), f"result exit code is not 0, result output: {result.output}, exc: {result.exc_info}"
test_utils.assert_click_status(result, 0)
assert (
"11a403ba" in result.output
), f"expected data not found in output: {result.output} "
Expand All @@ -234,9 +218,7 @@ def test_deploy_without_url(httpserver: PluginHTTPServer, tmpdir: LocalPath):
runner = CliRunner()
result = runner.invoke(deploy, ["--show", "-n", "test-job", "-t", "test-team"])

assert (
result.exit_code == 2
), f"result exit code is not 2, result output: {result.output}, exc: {result.exc_info}"
test_utils.assert_click_status(result, 2)
assert "what" in result.output and "why" in result.output


Expand All @@ -246,9 +228,7 @@ def test_deploy_with_empty_url(httpserver: PluginHTTPServer, tmpdir: LocalPath):
deploy, ["--show", "-n", "test-job", "-t", "test-team", "-u", ""]
)

assert (
result.exit_code == 2
), f"result exit code is not 2, result output: {result.output}, exc: {result.exc_info}"
test_utils.assert_click_status(result, 2)
assert "what" in result.output and "why" in result.output


Expand Down Expand Up @@ -283,9 +263,7 @@ def test_deploy_show_with_json_output(httpserver: PluginHTTPServer, tmpdir: Loca
"json",
],
)
assert (
result.exit_code == 0
), f"result exit code is not 0, result output: {result.output}, exc: {result.exc_info}"
test_utils.assert_click_status(result, 0)

try:
json_result = json.loads(result.output)
Expand Down Expand Up @@ -329,9 +307,7 @@ def test_deploy_show_with_json_output_and_no_deployments(
"json",
],
)
assert (
result.exit_code == 0
), f"result exit code is not 0, result output: {result.output}, exc: {result.exc_info}"
test_utils.assert_click_status(result, 0)

try:
json_result = json.loads(result.output)
Expand All @@ -355,9 +331,7 @@ def test_deploy_show_with_missing_output_and_no_deployments(
result = runner.invoke(
deploy, ["--show", "-n", "test-job", "-t", "test-team", "-u", rest_api_url]
)
assert (
result.exit_code == 0
), f"result exit code is not 0, result output: {result.output}, exc: {result.exc_info}"
test_utils.assert_click_status(result, 0)
assert (
"No deployments." in result.output
), f"expected data not found in output: {result.output}"
Expand All @@ -383,9 +357,7 @@ def test_deploy_show_with_invalid_output(
"invalid",
],
)
assert (
result.exit_code == 2
), f"result exit code is not 0, result output: {result.output}, exc: {result.exc_info}"
test_utils.assert_click_status(result, 2)
assert (
"Error: Invalid value for '--output'" in result.output
), f"expected data not found in output: {result.output}"
Expand All @@ -411,9 +383,7 @@ def test_deploy_failed_team_validation(httpserver: PluginHTTPServer, tmpdir: Loc
"reason",
],
)
assert (
result.exit_code == 2
), f"result exit code is not 0, result output: {result.output}, exc: {result.exc_info}"
test_utils.assert_click_status(result, 2)
assert "what" in result.output and "why" in result.output


Expand Down

0 comments on commit 43f2a8f

Please sign in to comment.