vincbeck commented on code in PR #65493:
URL: https://github.com/apache/airflow/pull/65493#discussion_r3118898320


##########
providers/hashicorp/tests/unit/hashicorp/secrets/test_vault.py:
##########
@@ -68,6 +70,175 @@ def test_get_connection(self, mock_hvac):
         connection = test_client.get_connection(conn_id="test_postgres")
         assert connection.get_uri() == 
"postgresql://airflow:airflow@host:5432/airflow?foo=bar&baz=taz"
 
+    
@mock.patch("airflow.providers.hashicorp._internal_client.vault_client.hvac")
+    def test_get_connection_team_value(self, mock_hvac):
+        mock_client = mock.MagicMock()
+        mock_hvac.Client.return_value = mock_client
+        mock_client.secrets.kv.v2.read_secret_version.return_value = {
+            "request_id": "94011e25-f8dc-ec29-221b-1f9c1d9ad2ae",
+            "lease_id": "",
+            "renewable": False,
+            "lease_duration": 0,
+            "data": {
+                "data": {
+                    "conn_type": "postgresql",
+                    "login": "airflow",
+                    "password": "airflow",
+                    "host": "host",
+                    "port": "5432",
+                    "schema": "airflow",
+                    "extra": '{"foo":"bar","baz":"taz"}',
+                },
+                "metadata": {
+                    "created_time": "2020-03-16T21:01:43.331126Z",
+                    "deletion_time": "",
+                    "destroyed": False,
+                    "version": 1,
+                },
+            },
+            "wrap_info": None,
+            "warnings": None,
+            "auth": None,
+        }
+
+        kwargs = {
+            "connections_path": "connections",
+            "mount_point": "airflow",
+            "auth_type": "token",
+            "url": "http://127.0.0.1:8200";,
+            "token": "s.7AU0I51yv1Q1lxOIg1F3ZRAS",
+        }
+
+        with conf_vars({("core", "multi_team"): "True"}):
+            test_client = VaultBackend(**kwargs)
+            connection = test_client.get_connection(conn_id="test_postgres", 
team_name="foo")
+        mock_client.secrets.kv.v2.read_secret_version.assert_called_with(
+            path=test_client.connections_path + "/foo/test_postgres",
+            mount_point="airflow",
+            version=None,
+            raise_on_deleted_version=True,
+        )
+        assert connection.get_uri() == 
"postgresql://airflow:airflow@host:5432/airflow?foo=bar&baz=taz"
+
+    
@mock.patch("airflow.providers.hashicorp._internal_client.vault_client.hvac")
+    def test_get_connection_no_team_separation(self, mock_hvac):
+        mock_client = mock.MagicMock()
+        mock_hvac.Client.return_value = mock_client
+        mock_client.secrets.kv.v2.read_secret_version.return_value = {
+            "request_id": "94011e25-f8dc-ec29-221b-1f9c1d9ad2ae",
+            "lease_id": "",
+            "renewable": False,
+            "lease_duration": 0,
+            "data": {
+                "data": {
+                    "conn_type": "postgresql",
+                    "login": "airflow",
+                    "password": "airflow",
+                    "host": "host",
+                    "port": "5432",
+                    "schema": "airflow",
+                    "extra": '{"foo":"bar","baz":"taz"}',
+                },
+                "metadata": {
+                    "created_time": "2020-03-16T21:01:43.331126Z",
+                    "deletion_time": "",
+                    "destroyed": False,
+                    "version": 1,
+                },
+            },
+            "wrap_info": None,
+            "warnings": None,
+            "auth": None,
+        }
+
+        kwargs = {
+            "connections_path": "connections",
+            "mount_point": "airflow",
+            "auth_type": "token",
+            "url": "http://127.0.0.1:8200";,
+            "token": "s.7AU0I51yv1Q1lxOIg1F3ZRAS",
+            "use_team_secrets_path": False,
+        }
+
+        with conf_vars({("core", "multi_team"): "True"}):

Review Comment:
   Same



##########
providers/hashicorp/tests/unit/hashicorp/secrets/test_vault.py:
##########
@@ -68,6 +70,175 @@ def test_get_connection(self, mock_hvac):
         connection = test_client.get_connection(conn_id="test_postgres")
         assert connection.get_uri() == 
"postgresql://airflow:airflow@host:5432/airflow?foo=bar&baz=taz"
 
+    
@mock.patch("airflow.providers.hashicorp._internal_client.vault_client.hvac")
+    def test_get_connection_team_value(self, mock_hvac):
+        mock_client = mock.MagicMock()
+        mock_hvac.Client.return_value = mock_client
+        mock_client.secrets.kv.v2.read_secret_version.return_value = {
+            "request_id": "94011e25-f8dc-ec29-221b-1f9c1d9ad2ae",
+            "lease_id": "",
+            "renewable": False,
+            "lease_duration": 0,
+            "data": {
+                "data": {
+                    "conn_type": "postgresql",
+                    "login": "airflow",
+                    "password": "airflow",
+                    "host": "host",
+                    "port": "5432",
+                    "schema": "airflow",
+                    "extra": '{"foo":"bar","baz":"taz"}',
+                },
+                "metadata": {
+                    "created_time": "2020-03-16T21:01:43.331126Z",
+                    "deletion_time": "",
+                    "destroyed": False,
+                    "version": 1,
+                },
+            },
+            "wrap_info": None,
+            "warnings": None,
+            "auth": None,
+        }
+
+        kwargs = {
+            "connections_path": "connections",
+            "mount_point": "airflow",
+            "auth_type": "token",
+            "url": "http://127.0.0.1:8200";,
+            "token": "s.7AU0I51yv1Q1lxOIg1F3ZRAS",
+        }
+
+        with conf_vars({("core", "multi_team"): "True"}):
+            test_client = VaultBackend(**kwargs)
+            connection = test_client.get_connection(conn_id="test_postgres", 
team_name="foo")
+        mock_client.secrets.kv.v2.read_secret_version.assert_called_with(
+            path=test_client.connections_path + "/foo/test_postgres",
+            mount_point="airflow",
+            version=None,
+            raise_on_deleted_version=True,
+        )
+        assert connection.get_uri() == 
"postgresql://airflow:airflow@host:5432/airflow?foo=bar&baz=taz"
+
+    
@mock.patch("airflow.providers.hashicorp._internal_client.vault_client.hvac")
+    def test_get_connection_no_team_separation(self, mock_hvac):

Review Comment:
   I am not sure this is possible but can you try to factorize these tests into 
one (one for connection, one for variable, etc) with 
`@pytest.mark.parametrize(`?



##########
providers/hashicorp/tests/unit/hashicorp/secrets/test_vault.py:
##########
@@ -68,6 +70,175 @@ def test_get_connection(self, mock_hvac):
         connection = test_client.get_connection(conn_id="test_postgres")
         assert connection.get_uri() == 
"postgresql://airflow:airflow@host:5432/airflow?foo=bar&baz=taz"
 
+    
@mock.patch("airflow.providers.hashicorp._internal_client.vault_client.hvac")
+    def test_get_connection_team_value(self, mock_hvac):
+        mock_client = mock.MagicMock()
+        mock_hvac.Client.return_value = mock_client
+        mock_client.secrets.kv.v2.read_secret_version.return_value = {
+            "request_id": "94011e25-f8dc-ec29-221b-1f9c1d9ad2ae",
+            "lease_id": "",
+            "renewable": False,
+            "lease_duration": 0,
+            "data": {
+                "data": {
+                    "conn_type": "postgresql",
+                    "login": "airflow",
+                    "password": "airflow",
+                    "host": "host",
+                    "port": "5432",
+                    "schema": "airflow",
+                    "extra": '{"foo":"bar","baz":"taz"}',
+                },
+                "metadata": {
+                    "created_time": "2020-03-16T21:01:43.331126Z",
+                    "deletion_time": "",
+                    "destroyed": False,
+                    "version": 1,
+                },
+            },
+            "wrap_info": None,
+            "warnings": None,
+            "auth": None,
+        }
+
+        kwargs = {
+            "connections_path": "connections",
+            "mount_point": "airflow",
+            "auth_type": "token",
+            "url": "http://127.0.0.1:8200";,
+            "token": "s.7AU0I51yv1Q1lxOIg1F3ZRAS",
+        }
+
+        with conf_vars({("core", "multi_team"): "True"}):

Review Comment:
   nit: please use decorator `@conf_vars(` instead, I find it easier and 
clearer to read



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to