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(sql_lab): Added Unit Test for stop query exception #17464

Merged
merged 2 commits into from
Nov 19, 2021

Conversation

AAfghahi
Copy link
Member

SUMMARY

This PR adds a unit test for the changes made here: #17292

It checks to make sure that we are getting a 422 error when an engine does not support cancel_query in sql_lab.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

TESTING INSTRUCTIONS

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

@codecov
Copy link

codecov bot commented Nov 17, 2021

Codecov Report

Merging #17464 (02d4253) into master (3f2129b) will decrease coverage by 0.20%.
The diff coverage is n/a.

❗ Current head 02d4253 differs from pull request most recent head 8d98d14. Consider uploading reports for the commit 8d98d14 to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master   #17464      +/-   ##
==========================================
- Coverage   76.94%   76.74%   -0.21%     
==========================================
  Files        1042     1042              
  Lines       56312    56312              
  Branches     7793     7793              
==========================================
- Hits        43329    43216     -113     
- Misses      12727    12840     +113     
  Partials      256      256              
Flag Coverage Δ
hive ?
mysql 81.97% <ø> (+0.02%) ⬆️
postgres 81.98% <ø> (+0.02%) ⬆️
presto ?
python 82.06% <ø> (-0.39%) ⬇️
sqlite 81.65% <ø> (+0.02%) ⬆️

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

Impacted Files Coverage Δ
superset/db_engines/hive.py 0.00% <0.00%> (-85.19%) ⬇️
superset/db_engine_specs/hive.py 69.49% <0.00%> (-16.99%) ⬇️
superset/db_engine_specs/presto.py 83.47% <0.00%> (-6.91%) ⬇️
superset/views/database/mixins.py 81.03% <0.00%> (-1.73%) ⬇️
superset/connectors/sqla/models.py 86.79% <0.00%> (-1.59%) ⬇️
superset/models/core.py 89.26% <0.00%> (-0.74%) ⬇️
superset/db_engine_specs/base.py 88.20% <0.00%> (-0.39%) ⬇️
superset/utils/core.py 89.61% <0.00%> (-0.12%) ⬇️
superset/views/core.py 77.43% <0.00%> (+0.45%) ⬆️
superset/utils/log.py 95.17% <0.00%> (+1.37%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3f2129b...8d98d14. Read the comment docs.

self.login(username="admin")

with mock.patch("superset.views.core.db") as mock_superset_db:
mock_superset_db.session.query().filter_by().one().return_value = query_mock
Copy link
Member

Choose a reason for hiding this comment

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

Oh, I didn't know you could use () instead of return_value. Nice!

Comment on lines 1559 to 1562
query_mock.sql = "SELECT *"
query_mock.database = 1
query_mock.schema = "superset"
query_mock.client_id = "foo"
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to mock these attributes?

Copy link
Member Author

Choose a reason for hiding this comment

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

No I deleted them.

query_mock.status = QueryStatus.RUNNING
self.login(username="admin")

with mock.patch("superset.views.core.db") as mock_superset_db:
Copy link
Member

Choose a reason for hiding this comment

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

Why not also patch the method with a decorator, like you did for cancel_query?

Copy link
Member Author

Choose a reason for hiding this comment

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

initially it was because it was giving me a 404 error and I saw this way of doing it repeated in various other integration tests. However, I played around with it, and if I @mock.patch(superset.views.core.db.session then I can use it as a decorator in the same way that I use cancel_query.

So i changed it to that, because ti does make it a lot more consistent and readable.

"/superset/stop_query/", data={"form_data": json.dumps(form_data)},
)

self.assertEqual(rv.status_code, 422)
Copy link
Member

Choose a reason for hiding this comment

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

Since me started using pylint naked asserts are preferred:

Suggested change
self.assertEqual(rv.status_code, 422)
assert rv.status_code == 422

Copy link
Member Author

Choose a reason for hiding this comment

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

changed! I forgot about this.

Copy link
Member

@betodealmeida betodealmeida left a comment

Choose a reason for hiding this comment

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

Awesome!

@hughhhh hughhhh merged commit 69c3cc7 into apache:master Nov 19, 2021
AAfghahi added a commit that referenced this pull request Jan 10, 2022
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 1.5.0 labels Mar 13, 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/S 🚢 1.5.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants