This is an automated email from the ASF dual-hosted git repository.
potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new a7a6a9d6ea remove creation of object that depends on sqlalchemy into
fixtures (#36258)
a7a6a9d6ea is described below
commit a7a6a9d6ea69418755c6a0829e474580cc751f00
Author: rom sharon <[email protected]>
AuthorDate: Sat Dec 16 17:47:26 2023 +0200
remove creation of object that depends on sqlalchemy into fixtures (#36258)
---
tests/always/test_connection.py | 56 ++++++++++++++++++++++++++++++-----------
tests/www/test_auth.py | 27 ++++++++++++++++----
2 files changed, 63 insertions(+), 20 deletions(-)
diff --git a/tests/always/test_connection.py b/tests/always/test_connection.py
index bfd7360eb3..2ba598fd62 100644
--- a/tests/always/test_connection.py
+++ b/tests/always/test_connection.py
@@ -37,6 +37,40 @@ from tests.test_utils.config import conf_vars
ConnectionParts = namedtuple("ConnectionParts", ["conn_type", "login",
"password", "host", "port", "schema"])
[email protected]()
+def get_connection1():
+ return Connection()
+
+
[email protected]()
+def get_connection2():
+ return Connection(host="apache.org", extra={})
+
+
[email protected]()
+def get_connection3():
+ return Connection(conn_type="foo", login="", password="p@$$")
+
+
[email protected]()
+def get_connection4():
+ return Connection(
+ conn_type="bar",
+ description="Sample Description",
+ host="example.org",
+ login="user",
+ password="p@$$",
+ schema="schema",
+ port=777,
+ extra={"foo": "bar", "answer": 42},
+ )
+
+
[email protected]()
+def get_connection5():
+ return Connection(uri="aws://")
+
+
class UriTestCaseConfig:
def __init__(
self,
@@ -795,24 +829,15 @@ class TestConnection:
@pytest.mark.parametrize(
"conn, expected_json",
[
- pytest.param(Connection(), "{}", id="empty"),
- pytest.param(Connection(host="apache.org", extra={}), '{"host":
"apache.org"}', id="empty-extra"),
+ pytest.param("get_connection1", "{}", id="empty"),
+ pytest.param("get_connection2", '{"host": "apache.org"}',
id="empty-extra"),
pytest.param(
- Connection(conn_type="foo", login="", password="p@$$"),
+ "get_connection3",
'{"conn_type": "foo", "login": "", "password": "p@$$"}',
id="some-fields",
),
pytest.param(
- Connection(
- conn_type="bar",
- description="Sample Description",
- host="example.org",
- login="user",
- password="p@$$",
- schema="schema",
- port=777,
- extra={"foo": "bar", "answer": 42},
- ),
+ "get_connection4",
json.dumps(
{
"conn_type": "bar",
@@ -828,14 +853,15 @@ class TestConnection:
id="all-fields",
),
pytest.param(
- Connection(uri="aws://"),
+ "get_connection5",
# During parsing URI some of the fields evaluated as an empty
strings
'{"conn_type": "aws", "host": "", "schema": ""}',
id="uri",
),
],
)
- def test_as_json_from_connection(self, conn: Connection, expected_json):
+ def test_as_json_from_connection(self, conn: Connection, expected_json,
request):
+ conn = request.getfixturevalue(conn)
result = conn.as_json()
assert result == expected_json
restored_conn = Connection.from_json(result)
diff --git a/tests/www/test_auth.py b/tests/www/test_auth.py
index bd2e963f86..d4000b707f 100644
--- a/tests/www/test_auth.py
+++ b/tests/www/test_auth.py
@@ -111,16 +111,31 @@ class TestHasAccessNoDetails:
assert result.status_code == 302
[email protected]()
+def get_connection():
+ return [Connection("conn_1"), Connection("conn_2")]
+
+
[email protected]()
+def get_pool():
+ return [Pool(pool="pool_1"), Pool(pool="pool_2")]
+
+
[email protected]()
+def get_variable():
+ return [Variable("var_1"), Variable("var_2")]
+
+
@pytest.mark.parametrize(
"decorator_name, is_authorized_method_name, items",
[
(
"has_access_connection",
"batch_is_authorized_connection",
- [Connection("conn_1"), Connection("conn_2")],
+ "get_connection",
),
- ("has_access_pool", "batch_is_authorized_pool", [Pool(pool="pool_1"),
Pool(pool="pool_2")]),
- ("has_access_variable", "batch_is_authorized_variable",
[Variable("var_1"), Variable("var_2")]),
+ ("has_access_pool", "batch_is_authorized_pool", "get_pool"),
+ ("has_access_variable", "batch_is_authorized_variable",
"get_variable"),
],
)
class TestHasAccessWithDetails:
@@ -133,8 +148,9 @@ class TestHasAccessWithDetails:
@patch("airflow.www.auth.get_auth_manager")
def test_has_access_with_details_when_authorized(
- self, mock_get_auth_manager, decorator_name,
is_authorized_method_name, items
+ self, mock_get_auth_manager, decorator_name,
is_authorized_method_name, items, request
):
+ items = request.getfixturevalue(items)
auth_manager = Mock()
is_authorized_method = Mock()
is_authorized_method.return_value = True
@@ -149,8 +165,9 @@ class TestHasAccessWithDetails:
@pytest.mark.db_test
@patch("airflow.www.auth.get_auth_manager")
def test_has_access_with_details_when_unauthorized(
- self, mock_get_auth_manager, app, decorator_name,
is_authorized_method_name, items
+ self, mock_get_auth_manager, app, decorator_name,
is_authorized_method_name, items, request
):
+ items = request.getfixturevalue(items)
auth_manager = Mock()
is_authorized_method = Mock()
is_authorized_method.return_value = False