-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: DBTP-1375 - platform helper version get-platform-helper-for-proj…
…ect no longer validates config (#575)
- Loading branch information
Showing
9 changed files
with
266 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,76 @@ | ||
import pytest | ||
import re | ||
from pathlib import Path | ||
from unittest.mock import patch | ||
|
||
import yaml | ||
from unittest.mock import patch | ||
from click.testing import CliRunner | ||
|
||
from dbt_platform_helper.commands.version import get_platform_helper_for_project | ||
from dbt_platform_helper.constants import PLATFORM_CONFIG_FILE | ||
from dbt_platform_helper.commands.version import VersionCommand | ||
|
||
|
||
@pytest.mark.usefixtures("create_valid_platform_config_file") | ||
class TestVersionCommandWithValidConfig: | ||
@patch("dbt_platform_helper.commands.version.get_required_platform_helper_version") | ||
def test_calls_versioning_function_and_prints_returned_version( | ||
self, | ||
mock_get_required_platform_helper_version, | ||
): | ||
mock_get_required_platform_helper_version.return_value = "1.2.3" | ||
|
||
command = VersionCommand().command | ||
result = CliRunner().invoke(command, []) | ||
|
||
assert len(mock_get_required_platform_helper_version.mock_calls) == 1 | ||
assert mock_get_required_platform_helper_version.mock_calls[0].args == (None,) | ||
assert result.exit_code == 0 | ||
assert re.match(r"\s*1\.2\.3\s*", result.output) | ||
|
||
@patch("dbt_platform_helper.commands.version.get_required_platform_helper_version") | ||
def test_calls_versioning_function_and_prints_returned_version_with_pipeline_override( | ||
self, | ||
mock_get_required_platform_helper_version, | ||
): | ||
mock_get_required_platform_helper_version.return_value = "1.2.3" | ||
|
||
@patch("dbt_platform_helper.commands.version.get_required_platform_helper_version") | ||
def test_calls_versioning_function_and_prints_returned_version( | ||
mock_get_required_platform_helper_version, | ||
fakefs, | ||
valid_platform_config, | ||
): | ||
fakefs.create_file(Path(PLATFORM_CONFIG_FILE), contents=yaml.dump(valid_platform_config)) | ||
mock_get_required_platform_helper_version.return_value = "1.2.3" | ||
command = VersionCommand().command | ||
result = CliRunner().invoke(command, ["--pipeline", "main"]) | ||
|
||
result = CliRunner().invoke(get_platform_helper_for_project, []) | ||
assert len(mock_get_required_platform_helper_version.mock_calls) == 1 | ||
assert mock_get_required_platform_helper_version.mock_calls[0].args == ("main",) | ||
assert result.exit_code == 0 | ||
assert re.match(r"\s*1\.2\.3\s*", result.output) | ||
|
||
assert len(mock_get_required_platform_helper_version.mock_calls) == 1 | ||
assert mock_get_required_platform_helper_version.mock_calls[0].args == (None,) | ||
assert result.exit_code == 0 | ||
assert re.match(r"\s*1\.2\.3\s*", result.output) | ||
def test_fail_if_pipeline_option_is_not_a_pipeline(self): | ||
command = VersionCommand().command | ||
result = CliRunner().invoke(command, ["--pipeline", "bogus"]) | ||
|
||
assert result.exit_code != 0 | ||
assert "'bogus' is not one of" in result.output | ||
assert "'main'" in result.output | ||
|
||
@patch("dbt_platform_helper.commands.version.get_required_platform_helper_version") | ||
def test_calls_versioning_function_and_prints_returned_version_with_pipeline_override( | ||
mock_get_required_platform_helper_version, | ||
fakefs, | ||
valid_platform_config, | ||
): | ||
fakefs.create_file(Path(PLATFORM_CONFIG_FILE), contents=yaml.dump(valid_platform_config)) | ||
mock_get_required_platform_helper_version.return_value = "1.2.3" | ||
|
||
result = CliRunner().invoke(get_platform_helper_for_project, ["--pipeline", "main"]) | ||
@pytest.mark.usefixtures("create_invalid_platform_config_file") | ||
@patch("dbt_platform_helper.utils.versioning._get_latest_release", return_value="10.9.9") | ||
class TestVersionCommandWithInvalidConfig: | ||
def test_works_given_invalid_config(self, mock_latest_release): | ||
command = VersionCommand().command | ||
result = CliRunner().invoke(command, []) | ||
|
||
assert len(mock_get_required_platform_helper_version.mock_calls) == 1 | ||
assert mock_get_required_platform_helper_version.mock_calls[0].args == ("main",) | ||
assert result.exit_code == 0 | ||
assert re.match(r"\s*1\.2\.3\s*", result.output) | ||
assert result.exit_code == 0 | ||
assert result.output == "1.2.3\n" | ||
|
||
def test_pipeline_override_given_invalid_config(self, mock_latest_release): | ||
command = VersionCommand().command | ||
result = CliRunner().invoke(command, ["--pipeline", "prod-main"]) | ||
|
||
def test_fail_if_pipeline_option_is_not_a_pipeline( | ||
fakefs, | ||
valid_platform_config, | ||
): | ||
fakefs.create_file(Path(PLATFORM_CONFIG_FILE), contents=yaml.dump(valid_platform_config)) | ||
assert result.exit_code == 0 | ||
assert result.output == "9.0.9\n" | ||
|
||
result = CliRunner().invoke(get_platform_helper_for_project, ["--pipeline", "bogus"]) | ||
def test_fails_if_pipeline_option_is_not_a_pipeline_given_invalid_config( | ||
self, mock_latest_release | ||
): | ||
command = VersionCommand().command | ||
result = CliRunner().invoke(command, ["--pipeline", "bogus"]) | ||
|
||
assert result.exit_code != 0 | ||
assert "'bogus' is not one of" in result.output | ||
assert "'main'" in result.output | ||
assert result.exit_code != 0 | ||
assert "'bogus' is not " in result.output | ||
assert "'prod-main'" in result.output |
Oops, something went wrong.