Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(tests): Remove unnecessary explicit Flask-SQLAlchemy session expunges #27136

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions tests/integration_tests/base_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems weird that we were expunging all objects from the session and not just the chart in question.

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(
Expand Down
7 changes: 1 addition & 6 deletions tests/integration_tests/core_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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)
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 2 additions & 4 deletions tests/integration_tests/security_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
{
Expand Down Expand Up @@ -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):
Expand Down
Loading