Skip to content

Commit

Permalink
chore(tests): Remove ineffectual login (#27149)
Browse files Browse the repository at this point in the history
  • Loading branch information
john-bodley authored Apr 9, 2024
1 parent ae0f2ce commit 481a63d
Show file tree
Hide file tree
Showing 47 changed files with 857 additions and 802 deletions.
7 changes: 2 additions & 5 deletions tests/integration_tests/access_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
from superset.utils.core import get_user_id, get_username, override_user
from superset.utils.database import get_example_database

from .base_tests import SupersetTestCase
from tests.integration_tests.base_tests import SupersetTestCase

ROLE_TABLES_PERM_DATA = {
"role_name": "override_me",
Expand Down Expand Up @@ -103,15 +103,12 @@ def tearDownClass(cls):
db.session.delete(security_manager.find_role(SCHEMA_ACCESS_ROLE))
db.session.commit()

def setUp(self):
self.login("admin")

def tearDown(self):
self.logout()
override_me = security_manager.find_role("override_me")
override_me.permissions = []
db.session.commit()
db.session.close()
super().tearDown()


@pytest.mark.parametrize(
Expand Down
69 changes: 35 additions & 34 deletions tests/integration_tests/annotation_layers/api_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
START_STR,
END_STR,
)
from tests.integration_tests.constants import ADMIN_USERNAME

ANNOTATION_LAYERS_COUNT = 10
ANNOTATIONS_COUNT = 5
Expand All @@ -61,7 +62,7 @@ def test_get_annotation_layer(self):
.first()
)

self.login(username="admin")
self.login(ADMIN_USERNAME)
uri = f"api/v1/annotation_layer/{annotation_layer.id}"
rv = self.get_assert_metric(uri, "get")
assert rv.status_code == 200
Expand All @@ -78,7 +79,7 @@ def test_info_annotation(self):
"""
Annotation API: Test info
"""
self.login(username="admin")
self.login(ADMIN_USERNAME)
uri = "api/v1/annotation_layer/_info"
rv = self.get_assert_metric(uri, "info")
assert rv.status_code == 200
Expand All @@ -87,7 +88,7 @@ def test_info_security_query(self):
"""
Annotation API: Test info security
"""
self.login(username="admin")
self.login(ADMIN_USERNAME)
params = {"keys": ["permissions"]}
uri = f"api/v1/annotation_layer/_info?q={prison.dumps(params)}"
rv = self.get_assert_metric(uri, "info")
Expand All @@ -103,7 +104,7 @@ def test_get_annotation_layer_not_found(self):
Annotation Api: Test get annotation layer not found
"""
max_id = db.session.query(func.max(AnnotationLayer.id)).scalar()
self.login(username="admin")
self.login(ADMIN_USERNAME)
uri = f"api/v1/annotation_layer/{max_id + 1}"
rv = self.get_assert_metric(uri, "get")
assert rv.status_code == 404
Expand All @@ -113,7 +114,7 @@ def test_get_list_annotation_layer(self):
"""
Annotation Api: Test get list annotation layers
"""
self.login(username="admin")
self.login(ADMIN_USERNAME)
uri = "api/v1/annotation_layer/"
rv = self.get_assert_metric(uri, "get_list")

Expand All @@ -137,7 +138,7 @@ def test_get_list_annotation_layer_sorting(self):
"""
Annotation Api: Test sorting on get list annotation layers
"""
self.login(username="admin")
self.login(ADMIN_USERNAME)
uri = "api/v1/annotation_layer/"

order_columns = [
Expand All @@ -161,7 +162,7 @@ def test_get_list_annotation_layer_filter(self):
"""
Annotation Api: Test filters on get list annotation layers
"""
self.login(username="admin")
self.login(ADMIN_USERNAME)
arguments = {
"columns": ["name", "descr"],
"filters": [
Expand Down Expand Up @@ -203,7 +204,7 @@ def test_create_annotation_layer(self):
"""
Annotation Api: Test create annotation layer
"""
self.login(username="admin")
self.login(ADMIN_USERNAME)
annotation_layer_data = {
"name": "new3",
"descr": "description",
Expand All @@ -225,7 +226,7 @@ def test_create_incorrect_annotation_layer(self):
"""
Annotation Api: Test create incorrect annotation layer
"""
self.login(username="admin")
self.login(ADMIN_USERNAME)
annotation_layer_data = {}
uri = "api/v1/annotation_layer/"
rv = self.client.post(uri, json=annotation_layer_data)
Expand All @@ -238,7 +239,7 @@ def test_create_annotation_layer_uniqueness(self):
"""
Annotation Api: Test create annotation layer uniqueness
"""
self.login(username="admin")
self.login(ADMIN_USERNAME)
annotation_layer_data = {"name": "name3", "descr": "description"}
uri = "api/v1/annotation_layer/"
rv = self.client.post(uri, json=annotation_layer_data)
Expand All @@ -257,7 +258,7 @@ def test_update_annotation_layer(self):
.one_or_none()
)

self.login(username="admin")
self.login(ADMIN_USERNAME)
annotation_layer_data = {"name": "changed_name"}
uri = f"api/v1/annotation_layer/{annotation_layer.id}"
rv = self.client.put(uri, json=annotation_layer_data)
Expand All @@ -279,7 +280,7 @@ def test_update_annotation_layer_uniqueness(self):
.one_or_none()
)

self.login(username="admin")
self.login(ADMIN_USERNAME)
annotation_layer_data = {"name": "name3", "descr": "changed_description"}
uri = f"api/v1/annotation_layer/{annotation_layer.id}"
rv = self.client.put(uri, json=annotation_layer_data)
Expand All @@ -294,7 +295,7 @@ def test_update_annotation_layer_not_found(self):
"""
max_id = db.session.query(func.max(AnnotationLayer.id)).scalar()

self.login(username="admin")
self.login(ADMIN_USERNAME)
annotation_layer_data = {"name": "changed_name", "descr": "changed_description"}
uri = f"api/v1/annotation_layer/{max_id + 1}"
rv = self.client.put(uri, json=annotation_layer_data)
Expand All @@ -310,7 +311,7 @@ def test_delete_annotation_layer(self):
.filter(AnnotationLayer.name == "name1")
.one_or_none()
)
self.login(username="admin")
self.login(ADMIN_USERNAME)
uri = f"api/v1/annotation_layer/{annotation_layer.id}"
rv = self.client.delete(uri)
assert rv.status_code == 200
Expand All @@ -323,7 +324,7 @@ def test_delete_annotation_layer_not_found(self):
Annotation Api: Test delete annotation layer not found
"""
max_id = db.session.query(func.max(AnnotationLayer.id)).scalar()
self.login(username="admin")
self.login(ADMIN_USERNAME)
uri = f"api/v1/annotation_layer/{max_id + 1}"
rv = self.client.delete(uri)
assert rv.status_code == 404
Expand All @@ -337,7 +338,7 @@ def test_delete_annotation_layer_integrity(self):
AnnotationLayer.name == "layer_with_annotations"
)
child_layer = query_child_layer.one_or_none()
self.login(username="admin")
self.login(ADMIN_USERNAME)
uri = f"api/v1/annotation_layer/{child_layer.id}"
rv = self.client.delete(uri)
assert rv.status_code == 422
Expand All @@ -355,7 +356,7 @@ def test_bulk_delete_annotation_layer(self):
no_child_layers_ids = [
annotation_layer.id for annotation_layer in no_child_layers
]
self.login(username="admin")
self.login(ADMIN_USERNAME)
uri = f"api/v1/annotation_layer/?q={prison.dumps(no_child_layers_ids)}"
rv = self.client.delete(uri)
assert rv.status_code == 200
Expand All @@ -382,7 +383,7 @@ def test_bulk_delete_annotation_layer_not_found(self):
]
max_id = db.session.query(func.max(AnnotationLayer.id)).scalar()
all_annotation_layers_ids.append(max_id + 1)
self.login(username="admin")
self.login(ADMIN_USERNAME)
uri = f"api/v1/annotation_layer/?q={prison.dumps(all_annotation_layers_ids)}"
rv = self.client.delete(uri)
assert rv.status_code == 404
Expand All @@ -399,7 +400,7 @@ def test_get_annotation(self):
.one_or_none()
)

self.login(username="admin")
self.login(ADMIN_USERNAME)
uri = (
f"api/v1/annotation_layer/{annotation.layer_id}/annotation/{annotation.id}"
)
Expand All @@ -426,7 +427,7 @@ def test_get_annotation_not_found(self):
"""
layer = self.get_layer_with_annotation()
max_id = db.session.query(func.max(Annotation.id)).scalar()
self.login(username="admin")
self.login(ADMIN_USERNAME)
uri = f"api/v1/annotation_layer/{layer.id}/annotation/{max_id + 1}"
rv = self.get_assert_metric(uri, "get")
assert rv.status_code == 404
Expand All @@ -437,7 +438,7 @@ def test_get_list_annotation(self):
Annotation Api: Test get list of annotations
"""
layer = self.get_layer_with_annotation()
self.login(username="admin")
self.login(ADMIN_USERNAME)
uri = f"api/v1/annotation_layer/{layer.id}/annotation/"
rv = self.get_assert_metric(uri, "get_list")

Expand All @@ -461,7 +462,7 @@ def test_get_list_annotation_sorting(self):
Annotation Api: Test sorting on get list of annotations
"""
layer = self.get_layer_with_annotation()
self.login(username="admin")
self.login(ADMIN_USERNAME)

order_columns = [
"short_descr",
Expand All @@ -483,7 +484,7 @@ def test_get_list_annotation_filter(self):
Annotation Api: Test filters on get list annotation layers
"""
layer = self.get_layer_with_annotation()
self.login(username="admin")
self.login(ADMIN_USERNAME)
arguments = {
"filters": [
{"col": "short_descr", "opr": "annotation_all_text", "value": "2"}
Expand Down Expand Up @@ -515,7 +516,7 @@ def test_create_annotation(self):
"""
layer = self.get_layer_with_annotation()

self.login(username="admin")
self.login(ADMIN_USERNAME)
annotation_data = {
"short_descr": "new",
"long_descr": "description",
Expand All @@ -542,7 +543,7 @@ def test_create_incorrect_annotation(self):
"""
layer = self.get_layer_with_annotation()

self.login(username="admin")
self.login(ADMIN_USERNAME)
annotation_data = {
"long_descr": "description",
}
Expand All @@ -565,7 +566,7 @@ def test_create_annotation_uniqueness(self):
"""
layer = self.get_layer_with_annotation()

self.login(username="admin")
self.login(ADMIN_USERNAME)
annotation_data = {
"short_descr": "short_descr2",
"long_descr": "description",
Expand Down Expand Up @@ -594,7 +595,7 @@ def test_update_annotation(self):
.one_or_none()
)

self.login(username="admin")
self.login(ADMIN_USERNAME)
annotation_data = {
"short_descr": "changed_name",
}
Expand All @@ -619,7 +620,7 @@ def test_update_annotation_null_datetime(self):
.one_or_none()
)

self.login(username="admin")
self.login(ADMIN_USERNAME)
annotation_data = {"start_dttm": None, "end_dttm": None}
uri = f"api/v1/annotation_layer/{layer.id}/annotation/{annotation.id}"
rv = self.client.put(uri, json=annotation_data)
Expand All @@ -644,7 +645,7 @@ def test_update_annotation_uniqueness(self):
.one_or_none()
)

self.login(username="admin")
self.login(ADMIN_USERNAME)
annotation_layer_data = {
"short_descr": "short_descr3",
"long_descr": "changed_description",
Expand All @@ -667,7 +668,7 @@ def test_update_annotation_not_found(self):
layer = self.get_layer_with_annotation()
max_id = db.session.query(func.max(Annotation.id)).scalar()

self.login(username="admin")
self.login(ADMIN_USERNAME)
annotation_layer_data = {
"short_descr": "changed_name",
}
Expand All @@ -686,7 +687,7 @@ def test_delete_annotation(self):
.filter(Annotation.short_descr == "short_descr1")
.one_or_none()
)
self.login(username="admin")
self.login(ADMIN_USERNAME)
uri = f"api/v1/annotation_layer/{layer.id}/annotation/{annotation.id}"
rv = self.client.delete(uri)
assert rv.status_code == 200
Expand All @@ -700,7 +701,7 @@ def test_delete_annotation_not_found(self):
"""
layer = self.get_layer_with_annotation()
max_id = db.session.query(func.max(Annotation.id)).scalar()
self.login(username="admin")
self.login(ADMIN_USERNAME)
uri = f"api/v1/annotation_layer/{layer.id}/annotation{max_id + 1}"
rv = self.client.delete(uri)
assert rv.status_code == 404
Expand All @@ -717,7 +718,7 @@ def test_bulk_delete_annotation(self):

annotations = query_annotations.all()
annotations_ids = [annotation.id for annotation in annotations]
self.login(username="admin")
self.login(ADMIN_USERNAME)
uri = f"api/v1/annotation_layer/{layer.id}/annotation/?q={prison.dumps(annotations_ids)}"
rv = self.client.delete(uri)
assert rv.status_code == 200
Expand All @@ -743,7 +744,7 @@ def test_bulk_delete_annotation_not_found(self):
max_id = db.session.query(func.max(Annotation.id)).scalar()

annotations_ids.append(max_id + 1)
self.login(username="admin")
self.login(ADMIN_USERNAME)
uri = f"api/v1/annotation_layer/{layer.id}/annotation/?q={prison.dumps(annotations_ids)}"
rv = self.client.delete(uri)
assert rv.status_code == 404
9 changes: 5 additions & 4 deletions tests/integration_tests/async_events/api_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

from superset.extensions import async_query_manager
from tests.integration_tests.base_tests import SupersetTestCase
from tests.integration_tests.constants import ADMIN_USERNAME
from tests.integration_tests.test_app import app


Expand All @@ -35,7 +36,7 @@ def fetch_events(self, last_id: Optional[str] = None):
def test_events(self, mock_uuid4):
app._got_first_request = False
async_query_manager.init_app(app)
self.login(username="admin")
self.login(ADMIN_USERNAME)
with mock.patch.object(async_query_manager._redis, "xrange") as mock_xrange:
rv = self.fetch_events()
response = json.loads(rv.data.decode("utf-8"))
Expand All @@ -49,7 +50,7 @@ def test_events(self, mock_uuid4):
def test_events_last_id(self, mock_uuid4):
app._got_first_request = False
async_query_manager.init_app(app)
self.login(username="admin")
self.login(ADMIN_USERNAME)
with mock.patch.object(async_query_manager._redis, "xrange") as mock_xrange:
rv = self.fetch_events("1607471525180-0")
response = json.loads(rv.data.decode("utf-8"))
Expand All @@ -63,7 +64,7 @@ def test_events_last_id(self, mock_uuid4):
def test_events_results(self, mock_uuid4):
app._got_first_request = False
async_query_manager.init_app(app)
self.login(username="admin")
self.login(ADMIN_USERNAME)
with mock.patch.object(async_query_manager._redis, "xrange") as mock_xrange:
mock_xrange.return_value = [
(
Expand Down Expand Up @@ -116,7 +117,7 @@ def test_events_no_login(self):
assert rv.status_code == 401

def test_events_no_token(self):
self.login(username="admin")
self.login(ADMIN_USERNAME)
self.client.set_cookie(app.config["GLOBAL_ASYNC_QUERIES_JWT_COOKIE_NAME"], "")
rv = self.fetch_events()
assert rv.status_code == 401
Loading

0 comments on commit 481a63d

Please sign in to comment.