From 845271454a55275b96ea99f15fc28a02b9edb7d6 Mon Sep 17 00:00:00 2001 From: John Bodley Date: Fri, 16 Feb 2024 15:22:27 +1300 Subject: [PATCH] chore(tests): Remove unnecessary explicit expunges --- tests/integration_tests/base_tests.py | 7 ++----- tests/integration_tests/core_tests.py | 7 +------ .../security/guest_token_security_tests.py | 4 ++-- tests/integration_tests/security_tests.py | 6 ++---- 4 files changed, 7 insertions(+), 17 deletions(-) diff --git a/tests/integration_tests/base_tests.py b/tests/integration_tests/base_tests.py index 81ad8ccc9f096..7b8d8506c3680 100644 --- a/tests/integration_tests/base_tests.py +++ b/tests/integration_tests/base_tests.py @@ -199,11 +199,8 @@ def get_or_create(self, cls, criteria, **kwargs): def login(self, username="admin", password="general"): return login(self.client, username, password) - def get_slice(self, slice_name: str, expunge_from_session: bool = True) -> Slice: - slc = db.session.query(Slice).filter_by(slice_name=slice_name).one() - if expunge_from_session: - db.session.expunge_all() - return slc + def get_slice(self, slice_name: str) -> Slice: + return db.session.query(Slice).filter_by(slice_name=slice_name).one() @staticmethod def get_table( diff --git a/tests/integration_tests/core_tests.py b/tests/integration_tests/core_tests.py index 4d3c35ec81cc0..573b096fc7038 100644 --- a/tests/integration_tests/core_tests.py +++ b/tests/integration_tests/core_tests.py @@ -199,7 +199,6 @@ def test_save_slice(self): url.format(tbl_id, copy_name, "saveas"), data={"form_data": json.dumps(form_data)}, ) - db.session.expunge_all() new_slice_id = resp.json["form_data"]["slice_id"] slc = db.session.query(Slice).filter_by(id=new_slice_id).one() @@ -221,7 +220,6 @@ def test_save_slice(self): url.format(tbl_id, new_slice_name, "overwrite"), data={"form_data": json.dumps(form_data)}, ) - db.session.expunge_all() slc = db.session.query(Slice).filter_by(id=new_slice_id).one() self.assertEqual(slc.slice_name, new_slice_name) self.assertEqual(slc.viz.form_data, form_data) @@ -240,10 +238,7 @@ def test_save_slice(self): def test_slice_data(self): # slice data should have some required attributes self.login(username="admin") - slc = self.get_slice( - slice_name="Top 10 Girl Name Share", - expunge_from_session=False, - ) + slc = self.get_slice(slice_name="Top 10 Girl Name Share") slc_data_attributes = slc.data.keys() assert "changed_on" in slc_data_attributes assert "modified" in slc_data_attributes diff --git a/tests/integration_tests/security/guest_token_security_tests.py b/tests/integration_tests/security/guest_token_security_tests.py index 44a4cdd3cec2d..a6aed7d6f9d1e 100644 --- a/tests/integration_tests/security/guest_token_security_tests.py +++ b/tests/integration_tests/security/guest_token_security_tests.py @@ -257,9 +257,9 @@ def setUp(self) -> None: ], } ) - self.chart = self.get_slice("Girls", expunge_from_session=False) + self.chart = self.get_slice("Girls") self.datasource = self.chart.datasource - self.other_chart = self.get_slice("Treemap", expunge_from_session=False) + self.other_chart = self.get_slice("Treemap") self.other_datasource = self.other_chart.datasource self.native_filter_datasource = ( db.session.query(SqlaTable).filter_by(table_name="dummy_sql_table").first() diff --git a/tests/integration_tests/security_tests.py b/tests/integration_tests/security_tests.py index 3ff2f3512196f..f0b0b5696bf16 100644 --- a/tests/integration_tests/security_tests.py +++ b/tests/integration_tests/security_tests.py @@ -1722,11 +1722,11 @@ def test_raise_for_access_rbac( mock_is_owner, ): births = self.get_dash_by_slug("births") - girls = self.get_slice("Girls", expunge_from_session=False) + girls = self.get_slice("Girls") birth_names = girls.datasource world_health = self.get_dash_by_slug("world_health") - treemap = self.get_slice("Treemap", expunge_from_session=False) + treemap = self.get_slice("Treemap") births.json_metadata = json.dumps( { @@ -1872,8 +1872,6 @@ def test_raise_for_access_rbac( } ) - db.session.expunge_all() - def test_get_user_roles(self): admin = security_manager.find_user("admin") with override_user(admin):