Skip to content

Commit

Permalink
improve asserts and test recommendations
Browse files Browse the repository at this point in the history
  • Loading branch information
a-gleeson committed Mar 6, 2025
1 parent 7feb005 commit 29d21f3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 16 deletions.
3 changes: 3 additions & 0 deletions dbt_platform_helper/domain/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from dbt_platform_helper.domain.versioning import PlatformHelperVersioning
from dbt_platform_helper.platform_exception import PlatformException
from dbt_platform_helper.providers.config import ConfigProvider
from dbt_platform_helper.providers.io import ClickIOProvider
from dbt_platform_helper.providers.yaml_file import YamlFileProvider
from dbt_platform_helper.utils.tool_versioning import get_aws_versions
Expand Down Expand Up @@ -43,11 +44,13 @@ def __init__(
),
get_aws_versions=get_aws_versions,
get_copilot_versions=get_copilot_versions,
config: ConfigProvider = ConfigProvider(),
):
self.io = io
self.platform_helper_versioning_domain = platform_helper_versioning_domain
self.get_aws_versions = get_aws_versions
self.get_copilot_versions = get_copilot_versions
self.config = config

def validate(self):
if Path("copilot").exists():
Expand Down
42 changes: 26 additions & 16 deletions tests/platform_helper/domain/test_config.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from unittest.mock import ANY
from unittest.mock import MagicMock
from unittest.mock import Mock
from unittest.mock import call
Expand All @@ -22,7 +23,7 @@ def __init__(self, *args, **kwargs):
)
self.platform_helper_version_status = kwargs.get(
"platform_helper_version_status",
(PlatformHelperVersionStatus(SemanticVersion(1, 0, 0), SemanticVersion(1, 0, 0))),
(PlatformHelperVersionStatus(SemanticVersion(0, 1, 0), SemanticVersion(1, 0, 0))),
)
self.platform_helper_versioning_domain._get_version_status.return_value = (
self.platform_helper_version_status
Expand Down Expand Up @@ -72,6 +73,7 @@ def test_validate(self, fakefs):
print(repr(call_args))

yes = "\033[92m✔\033[0m"
no = "\033[91m✖\033[0m"
expected_tool_version_table = PrettyTable()
expected_tool_version_table.field_names = [
"Tool",
Expand Down Expand Up @@ -99,23 +101,31 @@ def test_validate(self, fakefs):
expected_tool_version_table.add_row(
[
"dbt-platform-helper",
"0.1.0",
"1.0.0",
"1.0.0",
yes,
no,
]
)

assert repr(config_mocks.io.info.call_args[0][0]) == repr(expected_tool_version_table)
# config_mocks.io.info.assert_has_calls(
# [
# call(
# expected_tool_version_table
# )
# # call("\nRecommendations:\n"),
# # call(" - recommendation"),
# # call("")
# ], any_order=True
# )
assert repr(config_mocks.io.info.call_args_list[0][0][0]) == repr(
expected_tool_version_table
)
config_mocks.io.info.assert_has_calls(
[
call(
ANY, # tested above due to PrettyTable being difficult to compare
),
call("\nRecommendations:\n"),
call(
" - Upgrade dbt-platform-helper to version 1.0.0 `pip install --upgrade dbt-platform-helper==1.0.0`."
),
call(
" Post upgrade, run `platform-helper copilot make-addons` to update your addon templates."
),
call(""),
],
any_order=True,
)

config_mocks.platform_helper_versioning_domain._get_version_status.assert_called_with(
include_project_versions=True
Expand All @@ -125,7 +135,7 @@ def test_validate(self, fakefs):
{
"warnings": [],
"errors": [
"Cannot get dbt-platform-helper version from 'platform-config.yml'.\nCreate a section in the root of 'platform-config.yml':\n\ndefault_versions:\n platform-helper: 1.0.0\n"
"Cannot get dbt-platform-helper version from 'platform-config.yml'.\nCreate a section in the root of 'platform-config.yml':\n\ndefault_versions:\n platform-helper: 0.1.0\n"
],
}
)
Expand Down Expand Up @@ -157,7 +167,7 @@ def test_no_platform_config(self, fakefs):
{
"warnings": [],
"errors": [
"Cannot get dbt-platform-helper version from 'platform-config.yml'.\nCreate a section in the root of 'platform-config.yml':\n\ndefault_versions:\n platform-helper: 1.0.0\n"
"Cannot get dbt-platform-helper version from 'platform-config.yml'.\nCreate a section in the root of 'platform-config.yml':\n\ndefault_versions:\n platform-helper: 0.1.0\n"
],
}
)
Expand Down

0 comments on commit 29d21f3

Please sign in to comment.