-
Notifications
You must be signed in to change notification settings - Fork 13.8k
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
feat: validate_parameters for GSheets #15578
feat: validate_parameters for GSheets #15578
Conversation
10d7a37
to
3ec3646
Compare
tests/unit_tests/conftest.py
Outdated
|
||
import pytest | ||
|
||
from superset.app import create_app |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please put the imports inside the fixture since loading superset will do a lot of unnecessary loadings
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, good catch. Will fix it. But keep in mind that just importing create_app
doesn't do any initialization, and the import is reasonably quick.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, good catch. Will fix it. But keep in mind that just importing
create_app
doesn't do any initialization, and the import is reasonably quick.
superset package will load superset extension and then it will load others and initialize many objects there
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, for sure. I was talking about how long it used to take before we moved things into create_app
— then it would take many seconds to import anything from Superset.
3ec3646
to
178ccf8
Compare
Codecov Report
@@ Coverage Diff @@
## master #15578 +/- ##
==========================================
- Coverage 76.95% 76.73% -0.22%
==========================================
Files 976 976
Lines 51293 51318 +25
Branches 6907 6907
==========================================
- Hits 39471 39378 -93
- Misses 11603 11721 +118
Partials 219 219
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice to see the first unit test 👍
tests/unit_tests/conftest.py
Outdated
|
||
import pytest | ||
|
||
from superset.app import create_app |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, good catch. Will fix it. But keep in mind that just importing
create_app
doesn't do any initialization, and the import is reasonably quick.
superset package will load superset extension and then it will load others and initialize many objects there
@@ -33,6 +36,12 @@ | |||
SYNTAX_ERROR_REGEX = re.compile('SQLError: near "(?P<server_error>.*?)": syntax error') | |||
|
|||
|
|||
class GSheetsParametersType(TypedDict): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
be careful, TypedDict added in 3.8 so ... maybe the name should be changed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, this is a backport so we can use it in 3.7: https://github.com/python/typing/blob/master/typing_extensions/README.rst
""" | ||
|
||
|
||
def test_validate_parameters_simple(mocker, app_context): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I recommend putting all the tests under a Class so you can organize them more easily the tests: skip, mark or annotate the class with a fixture that will be applied for all the tests there
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not clearly documented but when we switched to pytest
we decided to stop using classes and adopt a functional approach. There's some discussion here: #12680 (comment)
@@ -33,6 +36,12 @@ | |||
SYNTAX_ERROR_REGEX = re.compile('SQLError: near "(?P<server_error>.*?)": syntax error') | |||
|
|||
|
|||
class GSheetsParametersType(TypedDict): | |||
credentials_info: Dict[str, Any] | |||
query: Dict[str, Any] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gshees doesn't need query
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But it does! The user can definitely pass options to it via the query string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the query string for each individual url in the catalog?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it's to pass parameters to configure the engine, eg:
gsheets://?list_all_sheets=1
This makes the dropdown show not only sheets in the catalog, but all of the user's sheets.
This can be done in the "extra" session as well, to be clear.
superset/db_engine_specs/gsheets.py
Outdated
class GSheetsParametersType(TypedDict): | ||
credentials_info: Dict[str, Any] | ||
query: Dict[str, Any] | ||
catalog: Dict[str, str] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we name this table_catalog
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure!
# specific language governing permissions and limitations | ||
# under the License. | ||
|
||
import pytest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@betodealmeida we could look at using pytest-flask.
* feat: validate_parameters for GSheets * Move import inside fixture * Update deps * Rename parameter
* feat: validate_parameters for GSheets * Move import inside fixture * Update deps * Rename parameter
* feat: validate_parameters for GSheets * Move import inside fixture * Update deps * Rename parameter
SUMMARY
Add a method to the GSheets DB engine spec to validate parameters from the new DB modal. This is currently not used, since GSheets is not exposed to the new modal.
The validation takes a payload that looks like this:
It checks each URL to see if it's accessible, using the credentials if present, and returns a SIP-40 error payload indicating any URLs not are not accessible.
Shoutout to @ofekisr for decoupling unit tests from integration tests! The tests I added are unit tests, though they still require an app context. I created a small fixture to provide that, and added the
pytest-mock
plugin since it helps keeping tests cleaner.BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
N/A
TESTING INSTRUCTIONS
Currently this method is a no-op, but I added unit tests and did manual integration test.
$ pytest tests/unit_tests ... 3 passed, 19 warnings in 2.68s
ADDITIONAL INFORMATION