Skip to content

Commit

Permalink
fixed patching of new versions function
Browse files Browse the repository at this point in the history
  • Loading branch information
a-gleeson committed Jan 10, 2025
1 parent ead018b commit 5e65879
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 46 deletions.
55 changes: 12 additions & 43 deletions dbt_platform_helper/domain/config_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,14 @@
import boto3
import click

import dbt_platform_helper.domain.versions as versions
from dbt_platform_helper.constants import CODEBASE_PIPELINES_KEY
from dbt_platform_helper.constants import ENVIRONMENTS_KEY
from dbt_platform_helper.constants import PLATFORM_CONFIG_FILE
from dbt_platform_helper.providers.aws.opensearch import OpensearchProvider
from dbt_platform_helper.providers.aws.redis import RedisProvider
from dbt_platform_helper.providers.aws.opensearch import OpensearchProviderDuck
from dbt_platform_helper.providers.aws.redis import RedisProviderDuck
from dbt_platform_helper.utils.messages import abort_with_error

"""
get_supported_versions=get_supported_aws_versions(
RedisProviderDuck(
boto3.client("elasticache")
)
),
)
def validate_supported_opensearch_versions(self, config):
return self._validate_extension_supported_versions(
config=config,
extension_type="opensearch",
version_key="engine",
get_supported_versions=get_supported_aws_versions(
OpensearchProviderDuck(
boto3.client("opensearch")
)
),
)
"""


class ConfigValidator:

Expand All @@ -49,7 +29,7 @@ def run_validations(self, config: dict):
validation(config)

def _validate_extension_supported_versions(
self, config, extension_type, version_key, get_supported_versions
self, config, aws_provider, extension_type, version_key
):
extensions = config.get("extensions", {})
if not extensions:
Expand All @@ -61,7 +41,8 @@ def _validate_extension_supported_versions(
if extension.get("type") == extension_type
]

supported_extension_versions = get_supported_versions()
# In this format so it can be monkey patched initially via mock_get_aws_supported_versions fixture
supported_extension_versions = versions.get_supported_aws_versions(aws_provider)
extensions_with_invalid_version = []

for extension in extensions_for_type:
Expand Down Expand Up @@ -93,29 +74,17 @@ def _validate_extension_supported_versions(
def validate_supported_redis_versions(self, config):
return self._validate_extension_supported_versions(
config=config,
extension_type="redis",
version_key="engine",
# get_supported_versions=get_supported_aws_versions(
# RedisProviderDuck(
# boto3.client("opensearch")
# )),
get_supported_versions=RedisProvider(
boto3.client("elasticache")
).get_supported_redis_versions,
aws_provider=RedisProviderDuck(boto3.client("elasticache")),
extension_type="redis", # TODO this is information which can live in the RedisProvider
version_key="engine", # TODO this is information which can live in the RedisProvider
)

def validate_supported_opensearch_versions(self, config):
return self._validate_extension_supported_versions(
config=config,
extension_type="opensearch",
version_key="engine",
# get_supported_versions=get_supported_aws_versions(
# OpensearchProviderDuck(
# boto3.client("opensearch")
# )),
get_supported_versions=OpensearchProvider(
boto3.client("opensearch")
).get_supported_opensearch_versions,
aws_provider=OpensearchProviderDuck(boto3.client("opensearch")),
extension_type="opensearch", # TODO this is information which can live in the OpensearchProvider
version_key="engine", # TODO this is information which can live in the OpensearchProvider
)

def validate_environment_pipelines(self, config):
Expand Down
16 changes: 16 additions & 0 deletions tests/platform_helper/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -728,3 +728,19 @@ def mock_return_value(self):
return ["6.2", "7.0", "7.1"]

monkeypatch.setattr(RedisProvider, "get_supported_redis_versions", mock_return_value)


# TODO - stop gap until validation.py is refactored into a class, then it will be an easier job of just passing in a mock_redis_provider into the constructor for the config_provider. For now autouse is needed.

import dbt_platform_helper.domain.versions as versions


@pytest.fixture(autouse=True)
def mock_get_aws_supported_versions(request, monkeypatch):
if "skip_supported_versions_fixture" in request.keywords:
return

def mock_return_value(self):
return ["6.2", "7.0", "7.1"]

monkeypatch.setattr(versions, "get_supported_aws_versions", mock_return_value)
5 changes: 2 additions & 3 deletions tests/platform_helper/providers/test_config_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,20 +335,19 @@ def test_validate_database_copy_fails_if_cross_account_with_incorrect_account_id
}
},
},
"redis version for environment prod is not in the list of supported redis versions: ['7.1']. Provided Version: invalid",
"redis version for environment prod is not in the list of supported redis versions: ['6.2', '7.0', '7.1']. Provided Version: invalid",
),
],
)
def test_validate_extension_supported_versions(config, expected_response, capsys):

mock_redis_provider = MagicMock()
mock_redis_provider.get_supported_redis_versions.return_value = ["7.1"]

ConfigValidator()._validate_extension_supported_versions(
config=config,
aws_provider=mock_redis_provider,
extension_type="redis",
version_key="engine",
get_supported_versions=mock_redis_provider.get_supported_redis_versions,
)

captured = capsys.readouterr()
Expand Down

0 comments on commit 5e65879

Please sign in to comment.