chore(tests): Remove ineffectual login (#27149)

This commit is contained in:
John Bodley
2024-04-09 09:52:02 -07:00
committed by GitHub
parent ae0f2ce3c1
commit 481a63da55
47 changed files with 857 additions and 802 deletions

View File

@@ -54,6 +54,7 @@ from superset.utils.core import backend
from superset.utils.database import get_example_database
from superset.views.database.views import DatabaseView
from tests.integration_tests.conftest import with_feature_flags
from tests.integration_tests.constants import ADMIN_USERNAME, GAMMA_USERNAME
from tests.integration_tests.fixtures.birth_names_dashboard import (
load_birth_names_dashboard_with_slices,
load_birth_names_data,
@@ -91,6 +92,7 @@ class TestCore(SupersetTestCase):
def tearDown(self):
db.session.query(Query).delete()
app.config["PREVENT_UNSAFE_DB_CONNECTIONS"] = self.original_unsafe_db_setting
super().tearDown()
def insert_dashboard_created_by(self, username: str) -> Dashboard:
user = self.get_user(username)
@@ -122,19 +124,19 @@ class TestCore(SupersetTestCase):
self.assertIn("User confirmation needed", resp)
def test_dashboard_endpoint(self):
self.login()
self.login(ADMIN_USERNAME)
resp = self.client.get("/superset/dashboard/-1/")
assert resp.status_code == 404
@pytest.mark.usefixtures("load_birth_names_dashboard_with_slices")
def test_slice_endpoint(self):
self.login(username="admin")
self.login(ADMIN_USERNAME)
resp = self.client.get("/superset/slice/-1/")
assert resp.status_code == 404
@pytest.mark.usefixtures("load_birth_names_dashboard_with_slices")
def test_viz_cache_key(self):
self.login(username="admin")
self.login(ADMIN_USERNAME)
slc = self.get_slice("Top 10 Girl Name Share")
viz = slc.viz
@@ -173,7 +175,7 @@ class TestCore(SupersetTestCase):
@pytest.mark.usefixtures("load_energy_table_with_slice")
def test_save_slice(self):
self.login(username="admin")
self.login(ADMIN_USERNAME)
slice_name = f"Energy Sankey"
slice_id = self.get_slice(slice_name).id
copy_name_prefix = "Test Sankey"
@@ -237,7 +239,7 @@ class TestCore(SupersetTestCase):
@pytest.mark.usefixtures("load_birth_names_dashboard_with_slices")
def test_slice_data(self):
# slice data should have some required attributes
self.login(username="admin")
self.login(ADMIN_USERNAME)
slc = self.get_slice(slice_name="Top 10 Girl Name Share")
slc_data_attributes = slc.data.keys()
assert "changed_on" in slc_data_attributes
@@ -247,7 +249,7 @@ class TestCore(SupersetTestCase):
@pytest.mark.usefixtures("load_energy_table_with_slice")
def test_slices(self):
# Testing by hitting the two supported end points for all slices
self.login(username="admin")
self.login(ADMIN_USERNAME)
Slc = Slice
urls = []
for slc in db.session.query(Slc).all():
@@ -261,14 +263,14 @@ class TestCore(SupersetTestCase):
self.assertEqual(resp.status_code, 200)
def test_add_slice(self):
self.login(username="admin")
self.login(ADMIN_USERNAME)
# assert that /chart/add responds with 200
url = "/chart/add"
resp = self.client.get(url)
self.assertEqual(resp.status_code, 200)
def test_get_user_slices(self):
self.login(username="admin")
self.login(ADMIN_USERNAME)
userid = security_manager.find_user("admin").id
url = f"/sliceasync/api/read?_flt_0_created_by={userid}"
resp = self.client.get(url)
@@ -325,10 +327,10 @@ class TestCore(SupersetTestCase):
# Disable for password store for later tests
models.custom_password_store = None
def test_databaseview_edit(self, username="admin"):
def test_databaseview_edit(self):
# validate that sending a password-masked uri does not over-write the decrypted
# uri
self.login(username=username)
self.login(ADMIN_USERNAME)
database = superset.utils.database.get_example_database()
sqlalchemy_uri_decrypted = database.sqlalchemy_uri_decrypted
url = f"databaseview/edit/{database.id}"
@@ -349,7 +351,7 @@ class TestCore(SupersetTestCase):
"load_energy_table_with_slice",
)
def test_warm_up_cache(self):
self.login()
self.login(ADMIN_USERNAME)
slc = self.get_slice("Top 10 Girl Name Share")
data = self.get_json_resp(f"/superset/warm_up_cache?slice_id={slc.id}")
self.assertEqual(
@@ -374,7 +376,7 @@ class TestCore(SupersetTestCase):
@pytest.mark.usefixtures("load_birth_names_dashboard_with_slices")
def test_warm_up_cache_error(self) -> None:
self.login()
self.login(ADMIN_USERNAME)
slc = self.get_slice("Pivot Table v2")
with mock.patch.object(
@@ -397,7 +399,7 @@ class TestCore(SupersetTestCase):
@pytest.mark.usefixtures("load_birth_names_dashboard_with_slices")
def test_cache_logging(self):
self.login("admin")
self.login(ADMIN_USERNAME)
store_cache_keys = app.config["STORE_CACHE_KEYS_IN_METADATA_DB"]
app.config["STORE_CACHE_KEYS_IN_METADATA_DB"] = True
slc = self.get_slice("Top 10 Girl Name Share")
@@ -409,7 +411,7 @@ class TestCore(SupersetTestCase):
@with_feature_flags(KV_STORE=False)
def test_kv_disabled(self):
self.login(username="admin")
self.login(ADMIN_USERNAME)
resp = self.client.get("/kv/10001/")
self.assertEqual(404, resp.status_code)
@@ -420,7 +422,7 @@ class TestCore(SupersetTestCase):
@with_feature_flags(KV_STORE=True)
def test_kv_enabled(self):
self.login(username="admin")
self.login(ADMIN_USERNAME)
resp = self.client.get("/kv/10001/")
self.assertEqual(404, resp.status_code)
@@ -437,7 +439,7 @@ class TestCore(SupersetTestCase):
self.assertEqual(json.loads(value), json.loads(resp.data.decode("utf-8")))
def test_gamma(self):
self.login(username="gamma")
self.login(GAMMA_USERNAME)
assert "Charts" in self.get_resp("/chart/list/")
assert "Dashboards" in self.get_resp("/dashboard/list/")
@@ -445,13 +447,13 @@ class TestCore(SupersetTestCase):
if superset.utils.database.get_example_database().backend == "presto":
# TODO: make it work for presto
return
self.login()
self.login(ADMIN_USERNAME)
sql = "SELECT '{{ 1+1 }}' as test"
data = self.run_sql(sql, "fdaklj3ws")
self.assertEqual(data["data"][0]["test"], "2")
def test_fetch_datasource_metadata(self):
self.login(username="admin")
self.login(ADMIN_USERNAME)
url = "/superset/fetch_datasource_metadata?" "datasourceKey=1__table"
resp = self.get_json_resp(url)
keys = [
@@ -468,7 +470,7 @@ class TestCore(SupersetTestCase):
@pytest.mark.usefixtures("load_birth_names_dashboard_with_slices")
def test_slice_id_is_always_logged_correctly_on_web_request(self):
# explore case
self.login("admin")
self.login(ADMIN_USERNAME)
slc = db.session.query(Slice).filter_by(slice_name="Girls").one()
qry = db.session.query(models.Log).filter_by(slice_id=slc.id)
self.get_resp(slc.slice_url)
@@ -545,7 +547,7 @@ class TestCore(SupersetTestCase):
form_data = {
"viz_type": "dist_bar",
}
self.login(username="admin")
self.login(ADMIN_USERNAME)
rv = self.client.post(
"/superset/explore_json/",
data={"form_data": json.dumps(form_data)},
@@ -570,7 +572,7 @@ class TestCore(SupersetTestCase):
"groupby": ["gender"],
"row_limit": 100,
}
self.login(username="admin")
self.login(ADMIN_USERNAME)
rv = self.client.post(
"/superset/explore_json/",
data={"form_data": json.dumps(form_data)},
@@ -646,7 +648,7 @@ class TestCore(SupersetTestCase):
"x_ticks_layout": "auto",
}
self.login(username="admin")
self.login(ADMIN_USERNAME)
rv = self.client.post(
"/superset/explore_json/",
data={"form_data": json.dumps(form_data)},
@@ -695,7 +697,7 @@ class TestCore(SupersetTestCase):
}
app._got_first_request = False
async_query_manager_factory.init_app(app)
self.login(username="admin")
self.login(ADMIN_USERNAME)
rv = self.client.post(
"/superset/explore_json/",
data={"form_data": json.dumps(form_data)},
@@ -734,7 +736,7 @@ class TestCore(SupersetTestCase):
}
app._got_first_request = False
async_query_manager_factory.init_app(app)
self.login(username="admin")
self.login(ADMIN_USERNAME)
rv = self.client.post(
"/superset/explore_json/?results=true",
data={"form_data": json.dumps(form_data)},
@@ -774,7 +776,7 @@ class TestCore(SupersetTestCase):
mock_cache.return_value = MockCache()
mock_force_cached.return_value = False
self.login(username="admin")
self.login(ADMIN_USERNAME)
rv = self.client.get("/superset/explore_json/data/valid-cache-key")
data = json.loads(rv.data.decode("utf-8"))
@@ -815,7 +817,7 @@ class TestCore(SupersetTestCase):
self.assertEqual(rv.status_code, 401)
def test_explore_json_data_invalid_cache_key(self):
self.login(username="admin")
self.login(ADMIN_USERNAME)
cache_key = "invalid-cache-key"
rv = self.client.get(f"/superset/explore_json/data/{cache_key}")
data = json.loads(rv.data.decode("utf-8"))
@@ -938,7 +940,7 @@ class TestCore(SupersetTestCase):
"""
# feature flags are cached
cache_manager.cache.clear()
self.login()
self.login(ADMIN_USERNAME)
encoded = json.dumps(
{"FOO": lambda x: 1, "super": "set"},
@@ -970,8 +972,7 @@ class TestCore(SupersetTestCase):
The tabstateview endpoint GET should be able to take name or title
for backward compatibility
"""
username = "admin"
self.login(username)
self.login(ADMIN_USERNAME)
# create a tab
data = {
@@ -993,8 +994,7 @@ class TestCore(SupersetTestCase):
self.assertEqual(payload["label"], "Untitled Query foo")
def test_tabstate_update(self):
username = "admin"
self.login(username)
self.login(ADMIN_USERNAME)
# create a tab
data = {
"queryEditor": json.dumps(
@@ -1141,7 +1141,7 @@ class TestCore(SupersetTestCase):
slice = db.session.query(Slice).first()
url = f"/explore/?form_data=%7B%22slice_id%22%3A%20{slice.id}%7D"
self.login()
self.login(ADMIN_USERNAME)
data = self.get_resp(url)
self.assertIn("Error message", data)
@@ -1151,7 +1151,7 @@ class TestCore(SupersetTestCase):
slice = db.session.query(Slice).first()
url = f"/explore/?form_data=%7B%22slice_id%22%3A%20{slice.id}%7D"
self.login()
self.login(ADMIN_USERNAME)
data = self.get_resp(url)
self.assertIn("Error message", data)
@@ -1168,7 +1168,7 @@ class TestCore(SupersetTestCase):
dash = db.session.query(Dashboard).first()
url = f"/superset/dashboard/{dash.id}/"
self.login()
self.login(ADMIN_USERNAME)
data = self.get_resp(url)
self.assertIn("Error message", data)
@@ -1178,14 +1178,14 @@ class TestCore(SupersetTestCase):
dash = db.session.query(Dashboard).first()
url = f"/superset/dashboard/{dash.id}/"
self.login()
self.login(ADMIN_USERNAME)
data = self.get_resp(url)
self.assertIn("Error message", data)
@pytest.mark.usefixtures("load_energy_table_with_slice")
@mock.patch("superset.commands.explore.form_data.create.CreateFormDataCommand.run")
def test_explore_redirect(self, mock_command: mock.Mock):
self.login(username="admin")
self.login(ADMIN_USERNAME)
random_key = "random_key"
mock_command.return_value = random_key
slice_name = f"Energy Sankey"
@@ -1215,7 +1215,7 @@ class TestCore(SupersetTestCase):
def test_dashboard_permalink(self, get_dashboard_permalink_mock, request_mock):
request_mock.query_string = b"standalone=3"
get_dashboard_permalink_mock.return_value = {"dashboardId": 1}
self.login()
self.login(ADMIN_USERNAME)
resp = self.client.get("superset/dashboard/p/123/")
expected_url = "/superset/dashboard/1?permalink_key=123&standalone=3"