Skip to content

Commit

Permalink
Add more tests with mocked env variables
Browse files Browse the repository at this point in the history
  • Loading branch information
sunank200 committed Dec 17, 2024
1 parent fa54cd1 commit 3b50ab4
Showing 1 changed file with 37 additions and 2 deletions.
39 changes: 37 additions & 2 deletions tests/cli/commands/remote_commands/test_config_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from __future__ import annotations

import contextlib
import os
import re
from io import StringIO
from unittest import mock
Expand All @@ -25,6 +26,7 @@

from airflow.cli import cli_parser
from airflow.cli.commands.remote_commands import config_command
from airflow.cli.commands.remote_commands.config_command import ConfigChange, ConfigParameter

from tests_common.test_utils.config import conf_vars

Expand Down Expand Up @@ -283,8 +285,7 @@ def test_lint_with_specific_removed_configs(self, section, option, suggestion):
expected_message = f"Removed deprecated `{option}` configuration parameter from `{section}` section."
assert expected_message in normalized_output

if suggestion:
assert suggestion in normalized_output
assert suggestion in normalized_output

def test_lint_specific_section_option(self):
with mock.patch("airflow.configuration.conf.has_option", return_value=True):
Expand Down Expand Up @@ -414,3 +415,37 @@ def test_lint_detects_renamed_configs(self, renamed_configs):
else:
expected_message = f"`{old_option}` configuration parameter moved from `{old_section}` section to `{new_section}` section as `{new_option}`."
assert expected_message in normalized_output

@pytest.mark.parametrize(
"env_var, config_change, expected_message",
[
(
"AIRFLOW__CORE__CHECK_SLAS",
ConfigChange(
config=ConfigParameter("core", "check_slas"),
suggestion="The SLA feature is removed in Airflow 3.0, to be replaced with Airflow Alerts in future",
),
"Removed deprecated `check_slas` configuration parameter from `core` section.",
),
(
"AIRFLOW__CORE__STRICT_ASSET_URI_VALIDATION",
ConfigChange(
config=ConfigParameter("core", "strict_asset_uri_validation"),
suggestion="Asset URI with a defined scheme will now always be validated strictly, raising a hard error on validation failure.",
),
"Removed deprecated `strict_asset_uri_validation` configuration parameter from `core` section.",
),
],
)
def test_lint_detects_configs_with_env_vars(self, env_var, config_change, expected_message):
with mock.patch.dict(os.environ, {env_var: "some_value"}):
with mock.patch("airflow.configuration.conf.has_option", return_value=True):
with contextlib.redirect_stdout(StringIO()) as temp_stdout:
config_command.lint_config(cli_parser.get_parser().parse_args(["config", "lint"]))

output = temp_stdout.getvalue()

normalized_output = re.sub(r"\s+", " ", output.strip())

assert expected_message in normalized_output
assert config_change.suggestion in normalized_output

0 comments on commit 3b50ab4

Please sign in to comment.