You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by di...@apache.org on 2022/08/22 13:18:21 UTC
[superset] 32/36: chore: support trailing slashes in database api (#21123)
This is an automated email from the ASF dual-hosted git repository.
diegopucci pushed a commit to branch chore/drill-to-detail-modal-tests
in repository https://gitbox.apache.org/repos/asf/superset.git
commit cf8cc0ec2c083ae4bb2b249e095543eec2b97e59
Author: Diego Medina <di...@gmail.com>
AuthorDate: Mon Aug 22 04:15:04 2022 -0300
chore: support trailing slashes in database api (#21123)
---
docs/static/resources/openapi.json | 4 +--
superset-frontend/src/SqlLab/actions/sqlLab.js | 2 +-
superset-frontend/src/views/CRUD/hooks.ts | 4 +--
superset/databases/api.py | 6 ++--
.../templates/superset/models/database/macros.html | 2 +-
tests/integration_tests/databases/api_tests.py | 34 +++++++++++-----------
6 files changed, 26 insertions(+), 26 deletions(-)
diff --git a/docs/static/resources/openapi.json b/docs/static/resources/openapi.json
index 330c629063..9020e4ba7d 100644
--- a/docs/static/resources/openapi.json
+++ b/docs/static/resources/openapi.json
@@ -13293,7 +13293,7 @@
]
}
},
- "/api/v1/database/test_connection": {
+ "/api/v1/database/test_connection/": {
"post": {
"description": "Tests a database connection",
"requestBody": {
@@ -13343,7 +13343,7 @@
]
}
},
- "/api/v1/database/validate_parameters": {
+ "/api/v1/database/validate_parameters/": {
"post": {
"description": "Validates parameters used to connect to a database",
"requestBody": {
diff --git a/superset-frontend/src/SqlLab/actions/sqlLab.js b/superset-frontend/src/SqlLab/actions/sqlLab.js
index 6391ce82c9..6c44646710 100644
--- a/superset-frontend/src/SqlLab/actions/sqlLab.js
+++ b/superset-frontend/src/SqlLab/actions/sqlLab.js
@@ -375,7 +375,7 @@ export function validateQuery(query) {
};
return SupersetClient.post({
- endpoint: `/api/v1/database/${query.dbId}/validate_sql`,
+ endpoint: `/api/v1/database/${query.dbId}/validate_sql/`,
body: JSON.stringify(postPayload),
headers: { 'Content-Type': 'application/json' },
})
diff --git a/superset-frontend/src/views/CRUD/hooks.ts b/superset-frontend/src/views/CRUD/hooks.ts
index 2160a68f8d..49dce7d080 100644
--- a/superset-frontend/src/views/CRUD/hooks.ts
+++ b/superset-frontend/src/views/CRUD/hooks.ts
@@ -641,7 +641,7 @@ export const testDatabaseConnection = (
addSuccessToast: (arg0: string) => void,
) => {
SupersetClient.post({
- endpoint: 'api/v1/database/test_connection',
+ endpoint: 'api/v1/database/test_connection/',
body: JSON.stringify(connection),
headers: { 'Content-Type': 'application/json' },
}).then(
@@ -675,7 +675,7 @@ export function useDatabaseValidation() {
const getValidation = useCallback(
(database: Partial<DatabaseObject> | null, onCreate = false) =>
SupersetClient.post({
- endpoint: '/api/v1/database/validate_parameters',
+ endpoint: '/api/v1/database/validate_parameters/',
body: JSON.stringify(database),
headers: { 'Content-Type': 'application/json' },
})
diff --git a/superset/databases/api.py b/superset/databases/api.py
index ca8e38aaf2..a6160b0d2f 100644
--- a/superset/databases/api.py
+++ b/superset/databases/api.py
@@ -662,7 +662,7 @@ class DatabaseRestApi(BaseSupersetModelRestApi):
self.incr_stats("success", self.select_star.__name__)
return self.response(200, result=result)
- @expose("/test_connection", methods=["POST"])
+ @expose("/test_connection/", methods=["POST"])
@protect()
@statsd_metrics
@event_logger.log_this_with_context(
@@ -778,7 +778,7 @@ class DatabaseRestApi(BaseSupersetModelRestApi):
},
)
- @expose("/<int:pk>/validate_sql", methods=["POST"])
+ @expose("/<int:pk>/validate_sql/", methods=["POST"])
@protect()
@statsd_metrics
@event_logger.log_this_with_context(
@@ -1121,7 +1121,7 @@ class DatabaseRestApi(BaseSupersetModelRestApi):
return self.response(200, databases=response)
- @expose("/validate_parameters", methods=["POST"])
+ @expose("/validate_parameters/", methods=["POST"])
@protect()
@statsd_metrics
@event_logger.log_this_with_context(
diff --git a/superset/templates/superset/models/database/macros.html b/superset/templates/superset/models/database/macros.html
index f1d07220ef..f1f7a36cde 100644
--- a/superset/templates/superset/models/database/macros.html
+++ b/superset/templates/superset/models/database/macros.html
@@ -22,7 +22,7 @@
.append('<button id="testconn" class="btn btn-sm btn-primary">{{ _("Test Connection") }}</button>');
$("#testconn").click(function(e) {
e.preventDefault();
- var url = "/api/v1/database/test_connection";
+ var url = "/api/v1/database/test_connection/";
var csrf_token = "{{ csrf_token() if csrf_token else '' }}";
$.ajaxSetup({
diff --git a/tests/integration_tests/databases/api_tests.py b/tests/integration_tests/databases/api_tests.py
index fe9228ebf4..8ff12b2406 100644
--- a/tests/integration_tests/databases/api_tests.py
+++ b/tests/integration_tests/databases/api_tests.py
@@ -1359,7 +1359,7 @@ class TestDatabaseApi(SupersetTestCase):
"sqlalchemy_uri": example_db.safe_sqlalchemy_uri(),
"server_cert": None,
}
- url = "api/v1/database/test_connection"
+ url = "api/v1/database/test_connection/"
rv = self.post_assert_metric(url, data, "test_connection")
self.assertEqual(rv.status_code, 200)
self.assertEqual(rv.headers["Content-Type"], "application/json; charset=utf-8")
@@ -1388,7 +1388,7 @@ class TestDatabaseApi(SupersetTestCase):
"impersonate_user": False,
"server_cert": None,
}
- url = "api/v1/database/test_connection"
+ url = "api/v1/database/test_connection/"
rv = self.post_assert_metric(url, data, "test_connection")
self.assertEqual(rv.status_code, 422)
self.assertEqual(rv.headers["Content-Type"], "application/json; charset=utf-8")
@@ -1454,7 +1454,7 @@ class TestDatabaseApi(SupersetTestCase):
"impersonate_user": False,
"server_cert": None,
}
- url = "api/v1/database/test_connection"
+ url = "api/v1/database/test_connection/"
rv = self.post_assert_metric(url, data, "test_connection")
self.assertEqual(rv.status_code, 400)
response = json.loads(rv.data.decode("utf-8"))
@@ -1513,7 +1513,7 @@ class TestDatabaseApi(SupersetTestCase):
"impersonate_user": False,
"server_cert": None,
}
- url = "api/v1/database/test_connection"
+ url = "api/v1/database/test_connection/"
rv = self.post_assert_metric(url, data, "test_connection")
assert rv.status_code == 422
@@ -2121,7 +2121,7 @@ class TestDatabaseApi(SupersetTestCase):
def test_validate_parameters_invalid_payload_format(self):
self.login(username="admin")
- url = "api/v1/database/validate_parameters"
+ url = "api/v1/database/validate_parameters/"
rv = self.client.post(url, data="INVALID", content_type="text/plain")
response = json.loads(rv.data.decode("utf-8"))
@@ -2146,7 +2146,7 @@ class TestDatabaseApi(SupersetTestCase):
def test_validate_parameters_invalid_payload_schema(self):
self.login(username="admin")
- url = "api/v1/database/validate_parameters"
+ url = "api/v1/database/validate_parameters/"
payload = {"foo": "bar"}
rv = self.client.post(url, json=payload)
response = json.loads(rv.data.decode("utf-8"))
@@ -2190,7 +2190,7 @@ class TestDatabaseApi(SupersetTestCase):
def test_validate_parameters_missing_fields(self):
self.login(username="admin")
- url = "api/v1/database/validate_parameters"
+ url = "api/v1/database/validate_parameters/"
payload = {
"configuration_method": ConfigurationMethod.SQLALCHEMY_FORM,
"engine": "postgresql",
@@ -2241,7 +2241,7 @@ class TestDatabaseApi(SupersetTestCase):
is_port_open.return_value = True
self.login(username="admin")
- url = "api/v1/database/validate_parameters"
+ url = "api/v1/database/validate_parameters/"
payload = {
"engine": "postgresql",
"parameters": defaultdict(dict),
@@ -2265,7 +2265,7 @@ class TestDatabaseApi(SupersetTestCase):
def test_validate_parameters_invalid_port(self):
self.login(username="admin")
- url = "api/v1/database/validate_parameters"
+ url = "api/v1/database/validate_parameters/"
payload = {
"engine": "postgresql",
"parameters": defaultdict(dict),
@@ -2324,7 +2324,7 @@ class TestDatabaseApi(SupersetTestCase):
is_hostname_valid.return_value = False
self.login(username="admin")
- url = "api/v1/database/validate_parameters"
+ url = "api/v1/database/validate_parameters/"
payload = {
"engine": "postgresql",
"parameters": defaultdict(dict),
@@ -2384,7 +2384,7 @@ class TestDatabaseApi(SupersetTestCase):
is_hostname_valid.return_value = True
self.login(username="admin")
- url = "api/v1/database/validate_parameters"
+ url = "api/v1/database/validate_parameters/"
payload = {
"engine": "postgresql",
"parameters": defaultdict(dict),
@@ -2467,7 +2467,7 @@ class TestDatabaseApi(SupersetTestCase):
pytest.skip("Only presto and PG are implemented")
self.login(username="admin")
- uri = f"api/v1/database/{example_db.id}/validate_sql"
+ uri = f"api/v1/database/{example_db.id}/validate_sql/"
rv = self.client.post(uri, json=request_payload)
response = json.loads(rv.data.decode("utf-8"))
self.assertEqual(rv.status_code, 200)
@@ -2493,7 +2493,7 @@ class TestDatabaseApi(SupersetTestCase):
pytest.skip("Only presto and PG are implemented")
self.login(username="admin")
- uri = f"api/v1/database/{example_db.id}/validate_sql"
+ uri = f"api/v1/database/{example_db.id}/validate_sql/"
rv = self.client.post(uri, json=request_payload)
response = json.loads(rv.data.decode("utf-8"))
self.assertEqual(rv.status_code, 200)
@@ -2525,7 +2525,7 @@ class TestDatabaseApi(SupersetTestCase):
}
self.login(username="admin")
uri = (
- f"api/v1/database/{self.get_nonexistent_numeric_id(Database)}/validate_sql"
+ f"api/v1/database/{self.get_nonexistent_numeric_id(Database)}/validate_sql/"
)
rv = self.client.post(uri, json=request_payload)
self.assertEqual(rv.status_code, 404)
@@ -2546,7 +2546,7 @@ class TestDatabaseApi(SupersetTestCase):
}
self.login(username="admin")
uri = (
- f"api/v1/database/{self.get_nonexistent_numeric_id(Database)}/validate_sql"
+ f"api/v1/database/{self.get_nonexistent_numeric_id(Database)}/validate_sql/"
)
rv = self.client.post(uri, json=request_payload)
response = json.loads(rv.data.decode("utf-8"))
@@ -2571,7 +2571,7 @@ class TestDatabaseApi(SupersetTestCase):
example_db = get_example_database()
- uri = f"api/v1/database/{example_db.id}/validate_sql"
+ uri = f"api/v1/database/{example_db.id}/validate_sql/"
rv = self.client.post(uri, json=request_payload)
response = json.loads(rv.data.decode("utf-8"))
self.assertEqual(rv.status_code, 422)
@@ -2624,7 +2624,7 @@ class TestDatabaseApi(SupersetTestCase):
example_db = get_example_database()
- uri = f"api/v1/database/{example_db.id}/validate_sql"
+ uri = f"api/v1/database/{example_db.id}/validate_sql/"
rv = self.client.post(uri, json=request_payload)
response = json.loads(rv.data.decode("utf-8"))