From d9379e8c9387243a2b5f7e08708206ac37d6ed16 Mon Sep 17 00:00:00 2001 From: Andrey Anshin Date: Mon, 31 Oct 2022 15:13:11 +0400 Subject: [PATCH] Reuse pytests parameters --- .../aws/secrets/test_systems_manager.py | 56 +++++++------------ 1 file changed, 20 insertions(+), 36 deletions(-) diff --git a/tests/providers/amazon/aws/secrets/test_systems_manager.py b/tests/providers/amazon/aws/secrets/test_systems_manager.py index 1c81ecc8c41c1..c10cc3944a1b7 100644 --- a/tests/providers/amazon/aws/secrets/test_systems_manager.py +++ b/tests/providers/amazon/aws/secrets/test_systems_manager.py @@ -26,6 +26,24 @@ from airflow.providers.amazon.aws.secrets.systems_manager import SystemsManagerParameterStoreBackend from tests.test_utils.config import conf_vars +URI_CONNECTION = pytest.param( + "postgres://my-login:my-pass@my-host:5432/my-schema?param1=val1¶m2=val2", id="uri-connection" +) +JSON_CONNECTION = pytest.param( + json.dumps( + { + "conn_type": "postgres", + "login": "my-login", + "password": "my-pass", + "host": "my-host", + "port": 5432, + "schema": "my-schema", + "extra": {"param1": "val1", "param2": "val2"}, + } + ), + id="json-connection", +) + class TestSsmSecrets: @mock.patch( @@ -38,24 +56,7 @@ def test_aws_ssm_get_connection(self, mock_get_value): assert conn.host == "host" @mock_ssm - @pytest.mark.parametrize( - "ssm_value", - [ - "postgres://my-login:my-pass@my-host:5432/my-schema?param1=val1¶m2=val2", - json.dumps( - { - "conn_type": "postgres", - "login": "my-login", - "password": "my-pass", - "host": "my-host", - "port": 5432, - "schema": "my-schema", - "extra": {"param1": "val1", "param2": "val2"}, - } - ), - ], - ids=["uri-conn", "json-conn"], - ) + @pytest.mark.parametrize("ssm_value", [JSON_CONNECTION, URI_CONNECTION]) def test_get_conn_value(self, ssm_value): param = { "Name": "/airflow/connections/test_postgres", @@ -80,24 +81,7 @@ def test_get_conn_value(self, ssm_value): assert test_conn.extra_dejson == {"param1": "val1", "param2": "val2"} @mock_ssm - @pytest.mark.parametrize( - "ssm_value", - [ - "postgres://my-login:my-pass@my-host:5432/my-schema?param1=val1¶m2=val2", - json.dumps( - { - "conn_type": "postgres", - "login": "my-login", - "password": "my-pass", - "host": "my-host", - "port": 5432, - "schema": "my-schema", - "extra": {"param1": "val1", "param2": "val2"}, - } - ), - ], - ids=["uri-conn", "json-conn"], - ) + @pytest.mark.parametrize("ssm_value", [JSON_CONNECTION, URI_CONNECTION]) def test_deprecated_get_conn_uri(self, ssm_value): param = { "Name": "/airflow/connections/test_postgres",