mirror of
https://github.com/apache/superset.git
synced 2026-04-12 12:47:53 +00:00
chore: Migrate /superset/tables/* to API v1 (#22501)
This commit is contained in:
@@ -1782,6 +1782,66 @@ class TestDatabaseApi(SupersetTestCase):
|
||||
)
|
||||
self.assertEqual(rv.status_code, 400)
|
||||
|
||||
def test_database_tables(self):
|
||||
"""
|
||||
Database API: Test database tables
|
||||
"""
|
||||
self.login(username="admin")
|
||||
database = db.session.query(Database).filter_by(database_name="examples").one()
|
||||
|
||||
schema_name = self.default_schema_backend_map[database.backend]
|
||||
rv = self.client.get(
|
||||
f"api/v1/database/{database.id}/tables/?q={prison.dumps({'schema_name': schema_name})}"
|
||||
)
|
||||
|
||||
self.assertEqual(rv.status_code, 200)
|
||||
if database.backend == "postgresql":
|
||||
response = json.loads(rv.data.decode("utf-8"))
|
||||
schemas = [
|
||||
s[0] for s in database.get_all_table_names_in_schema(schema_name)
|
||||
]
|
||||
self.assertEquals(response["count"], len(schemas))
|
||||
for option in response["result"]:
|
||||
self.assertEquals(option["extra"], None)
|
||||
self.assertEquals(option["type"], "table")
|
||||
self.assertTrue(option["value"] in schemas)
|
||||
|
||||
def test_database_tables_not_found(self):
|
||||
"""
|
||||
Database API: Test database tables not found
|
||||
"""
|
||||
self.logout()
|
||||
self.login(username="gamma")
|
||||
example_db = get_example_database()
|
||||
uri = f"api/v1/database/{example_db.id}/tables/?q={prison.dumps({'schema_name': 'non_existent'})}"
|
||||
rv = self.client.get(uri)
|
||||
self.assertEqual(rv.status_code, 404)
|
||||
|
||||
def test_database_tables_invalid_query(self):
|
||||
"""
|
||||
Database API: Test database tables with invalid query
|
||||
"""
|
||||
self.login("admin")
|
||||
database = db.session.query(Database).first()
|
||||
rv = self.client.get(
|
||||
f"api/v1/database/{database.id}/tables/?q={prison.dumps({'force': 'nop'})}"
|
||||
)
|
||||
self.assertEqual(rv.status_code, 400)
|
||||
|
||||
@mock.patch("superset.security.manager.SupersetSecurityManager.can_access_database")
|
||||
def test_database_tables_unexpected_error(self, mock_can_access_database):
|
||||
"""
|
||||
Database API: Test database tables with unexpected error
|
||||
"""
|
||||
self.login(username="admin")
|
||||
database = db.session.query(Database).filter_by(database_name="examples").one()
|
||||
mock_can_access_database.side_effect = Exception("Test Error")
|
||||
|
||||
rv = self.client.get(
|
||||
f"api/v1/database/{database.id}/tables/?q={prison.dumps({'schema_name': 'main'})}"
|
||||
)
|
||||
self.assertEqual(rv.status_code, 422)
|
||||
|
||||
def test_test_connection(self):
|
||||
"""
|
||||
Database API: Test test connection
|
||||
|
||||
Reference in New Issue
Block a user