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 ineffectual login #27149

Conversation

john-bodley
Copy link
Member

@john-bodley john-bodley commented Feb 17, 2024

SUMMARY

Whilst working on [SIP-99B] Proposal for (re)defining a "unit of work" I was running into an issue where (I thought) tests were failing due to an issue with the persistence of a logged in user whereas in actuality it was because I was missing the Public role.

The red herring was due to the slew of tests which don't interface with the test client "logging" in a user in the hope of persisting the logged in user to g.user. This is ineffectual outside of the client as the Flask globals only persist for the lifetime of the request, i.e.,

>>> from flask import g

>>> self.login(username="admin")
>>> print(g.user)
<flask_login.mixins.AnonymousUserMixin object at 0x160c48be0>

Flask-Login automatically restores g.user from that cookie if it is not in the session when dealing with requests from the client. The TL;DR is authenticating (logging in/logging out) the user is only effectual in the context of web requests via the client.

This PR removes any erroneous logins (and logouts)—determined by first eliminating all references and re-adding them for API related tests. It also cleans up any inconsistencies in how logging in occurs. I updated the login() method to remove the default admin username so now it's a required argument which aids with readability.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

TESTING INSTRUCTIONS

CI.

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

@john-bodley john-bodley force-pushed the john-bodley--tests-remove-ineffectual-login branch 3 times, most recently from 5db29f3 to 177efb5 Compare February 17, 2024 09:31
@john-bodley john-bodley force-pushed the john-bodley--tests-remove-ineffectual-login branch from 177efb5 to 5b4cf74 Compare February 17, 2024 09:37
@john-bodley john-bodley force-pushed the john-bodley--tests-remove-ineffectual-login branch 9 times, most recently from be6ffc1 to 9752ca0 Compare February 20, 2024 22:31
@john-bodley john-bodley force-pushed the john-bodley--tests-remove-ineffectual-login branch 5 times, most recently from 4f761b5 to b915d66 Compare February 21, 2024 03:01
@@ -196,7 +196,8 @@ def get_or_create(self, cls, criteria, **kwargs):
db.session.commit()
return obj

def login(self, username="admin", password="general"):
def login(self, username, password="general"):
Copy link
Member Author

Choose a reason for hiding this comment

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

Require the explicit username so it's evident who is logging in.

@john-bodley john-bodley force-pushed the john-bodley--tests-remove-ineffectual-login branch 2 times, most recently from d9fd234 to fc58d28 Compare February 21, 2024 07:11
Copy link

codecov bot commented Feb 21, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 67.44%. Comparing base (22e823b) to head (4d777bf).
Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #27149   +/-   ##
=======================================
  Coverage   67.43%   67.44%           
=======================================
  Files        1911     1911           
  Lines       74966    74966           
  Branches     8353     8353           
=======================================
+ Hits        50555    50558    +3     
+ Misses      22358    22355    -3     
  Partials     2053     2053           
Flag Coverage Δ
mysql 77.92% <ø> (+<0.01%) ⬆️
postgres 78.04% <ø> (+<0.01%) ⬆️
python 78.17% <ø> (+<0.01%) ⬆️
sqlite 77.47% <ø> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@john-bodley john-bodley force-pushed the john-bodley--tests-remove-ineffectual-login branch 5 times, most recently from 672d3ea to 5016a45 Compare February 24, 2024 08:56
@john-bodley john-bodley force-pushed the john-bodley--tests-remove-ineffectual-login branch 3 times, most recently from 3dbd03d to 21c4a0b Compare March 6, 2024 07:48
@john-bodley john-bodley force-pushed the john-bodley--tests-remove-ineffectual-login branch 8 times, most recently from 1811d2a to 7825fea Compare March 23, 2024 01:28
@@ -51,7 +56,11 @@ class TestSqlLabApi(SupersetTestCase):
clear=True,
)
def test_get_from_empty_bootsrap_data(self):
self.login(username="gamma_sqllab_no_data")
if utils.backend() == "postgres":
Copy link
Member Author

Choose a reason for hiding this comment

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

@michael-s-molina I've spent/wasted hours trying to get a few failing PostgreSQL tests to pass. The tests succeed when testing locally and/or remotely when I run either i) the specific test, or ii) the specific file, however they fail when run as part of the entire test suite.

My hypothesis is that there are a slew of non-idempotent tests and this change merely (re)highlighted how fragile aspects of our tests are.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, it's kind of frustrating that we have many non-idempotent tests. Given that we'll need a specific effort for fixing this problem globally, I'm ok with skipping the test. We do the same for many sqlite tests.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks @michael-s-molina. Also it's worth mentioning it's not like the test is being skipped globally, i.e., we have coverage on the said logic for MySQL and SQLite.

@john-bodley john-bodley force-pushed the john-bodley--tests-remove-ineffectual-login branch from 7825fea to 4d777bf Compare March 23, 2024 03:43
@john-bodley john-bodley force-pushed the john-bodley--tests-remove-ineffectual-login branch from 4d777bf to 73194b2 Compare April 9, 2024 16:35
@john-bodley john-bodley merged commit 481a63d into apache:master Apr 9, 2024
28 checks passed
@john-bodley john-bodley deleted the john-bodley--tests-remove-ineffectual-login branch April 9, 2024 16:52
EnxDev pushed a commit to EnxDev/superset that referenced this pull request Apr 15, 2024
qleroy pushed a commit to qleroy/superset that referenced this pull request Apr 28, 2024
jzhao62 pushed a commit to jzhao62/superset that referenced this pull request May 16, 2024
vinothkumar66 pushed a commit to vinothkumar66/superset that referenced this pull request Nov 11, 2024
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 4.1.0 labels Nov 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels size/XXL 🚢 4.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants