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 0f6f29b65a Migrate remaining WWW tests to `pytest` (#28331)
0f6f29b65a is described below
commit 0f6f29b65a5abcf86ca5427170bbd1683e9719de
Author: Andrey Anshin <[email protected]>
AuthorDate: Tue Dec 13 20:33:42 2022 +0400
Migrate remaining WWW tests to `pytest` (#28331)
---
tests/www/views/test_views_custom_user_views.py | 95 ++++++++-----------------
1 file changed, 31 insertions(+), 64 deletions(-)
diff --git a/tests/www/views/test_views_custom_user_views.py
b/tests/www/views/test_views_custom_user_views.py
index b7d2fafab0..71ab551ab7 100644
--- a/tests/www/views/test_views_custom_user_views.py
+++ b/tests/www/views/test_views_custom_user_views.py
@@ -17,10 +17,8 @@
# under the License.
from __future__ import annotations
-import unittest
-
+import pytest
from flask_appbuilder import SQLA
-from parameterized import parameterized
from airflow import settings
from airflow.security import permissions
@@ -28,14 +26,37 @@ from airflow.www import app as application
from tests.test_utils.api_connexion_utils import create_user, delete_role
from tests.test_utils.www import check_content_in_response,
check_content_not_in_response, client_with_login
-
-class TestSecurity(unittest.TestCase):
+PERMISSIONS_TESTS_PARAMS = [
+ (
+ "/resetpassword/form?pk={user.id}",
+ (permissions.ACTION_CAN_READ, permissions.RESOURCE_PASSWORD),
+ "Reset Password Form",
+ ),
+ (
+ "/resetmypassword/form",
+ (permissions.ACTION_CAN_READ, permissions.RESOURCE_MY_PASSWORD),
+ "Reset Password Form",
+ ),
+ (
+ "/users/userinfo/",
+ (permissions.ACTION_CAN_READ, permissions.RESOURCE_MY_PROFILE),
+ "Your user information",
+ ),
+ ("/userinfoeditview/form", (permissions.ACTION_CAN_EDIT,
permissions.RESOURCE_MY_PROFILE), "Edit User"),
+ ("/users/add", (permissions.ACTION_CAN_CREATE, permissions.RESOURCE_USER),
"Add User"),
+ ("/users/list/", (permissions.ACTION_CAN_READ, permissions.RESOURCE_USER),
"List Users"),
+ ("/users/show/{user.id}", (permissions.ACTION_CAN_READ,
permissions.RESOURCE_USER), "Show User"),
+ ("/users/edit/{user.id}", (permissions.ACTION_CAN_EDIT,
permissions.RESOURCE_USER), "Edit User"),
+]
+
+
+class TestSecurity:
@classmethod
- def setUpClass(cls):
+ def setup_class(cls):
settings.configure_orm()
cls.session = settings.Session
- def setUp(self):
+ def setup_method(self):
# We cannot reuse the app in tests (on class level) as in Flask 2.2
this causes
# an exception because app context teardown is removed and if even
single request is run via app
# it cannot be re-intialized again by passing it as constructor to SQLA
@@ -53,35 +74,8 @@ class TestSecurity(unittest.TestCase):
for role_name in ["role_edit_one_dag"]:
delete_role(self.app, role_name)
- @parameterized.expand(
- [
- (
- "/resetpassword/form?pk={user.id}",
- (permissions.ACTION_CAN_READ, permissions.RESOURCE_PASSWORD),
- "Reset Password Form",
- ),
- (
- "/resetmypassword/form",
- (permissions.ACTION_CAN_READ,
permissions.RESOURCE_MY_PASSWORD),
- "Reset Password Form",
- ),
- (
- "/users/userinfo/",
- (permissions.ACTION_CAN_READ, permissions.RESOURCE_MY_PROFILE),
- "Your user information",
- ),
- (
- "/userinfoeditview/form",
- (permissions.ACTION_CAN_EDIT, permissions.RESOURCE_MY_PROFILE),
- "Edit User",
- ),
- ("/users/add", (permissions.ACTION_CAN_CREATE,
permissions.RESOURCE_USER), "Add User"),
- ("/users/list/", (permissions.ACTION_CAN_READ,
permissions.RESOURCE_USER), "List Users"),
- ("/users/show/{user.id}", (permissions.ACTION_CAN_READ,
permissions.RESOURCE_USER), "Show User"),
- ("/users/edit/{user.id}", (permissions.ACTION_CAN_EDIT,
permissions.RESOURCE_USER), "Edit User"),
- ]
- )
- def test_user_model_view_with_access(self, url, permission, expected_text):
+ @pytest.mark.parametrize("url, _, expected_text", PERMISSIONS_TESTS_PARAMS)
+ def test_user_model_view_with_access(self, url, expected_text, _):
user_without_access = create_user(
self.app,
username="no_access",
@@ -98,34 +92,7 @@ class TestSecurity(unittest.TestCase):
response = client.get(url.replace("{user.id}",
str(user_without_access.id)), follow_redirects=True)
check_content_not_in_response(expected_text, response)
- @parameterized.expand(
- [
- (
- "/resetpassword/form?pk={user.id}",
- (permissions.ACTION_CAN_READ, permissions.RESOURCE_PASSWORD),
- "Reset Password Form",
- ),
- (
- "/resetmypassword/form",
- (permissions.ACTION_CAN_READ,
permissions.RESOURCE_MY_PASSWORD),
- "Reset Password Form",
- ),
- (
- "/users/userinfo/",
- (permissions.ACTION_CAN_READ, permissions.RESOURCE_MY_PROFILE),
- "Your user information",
- ),
- (
- "/userinfoeditview/form",
- (permissions.ACTION_CAN_EDIT, permissions.RESOURCE_MY_PROFILE),
- "Edit User",
- ),
- ("/users/add", (permissions.ACTION_CAN_CREATE,
permissions.RESOURCE_USER), "Add User"),
- ("/users/list/", (permissions.ACTION_CAN_READ,
permissions.RESOURCE_USER), "List Users"),
- ("/users/show/{user.id}", (permissions.ACTION_CAN_READ,
permissions.RESOURCE_USER), "Show User"),
- ("/users/edit/{user.id}", (permissions.ACTION_CAN_EDIT,
permissions.RESOURCE_USER), "Edit User"),
- ]
- )
+ @pytest.mark.parametrize("url, permission, expected_text",
PERMISSIONS_TESTS_PARAMS)
def test_user_model_view_without_access(self, url, permission,
expected_text):
user_with_access = create_user(