chore: Migrate /superset/queries/<last_updated_ms> to API v1 (#22611)

This commit is contained in:
Diego Medina
2023-01-27 15:20:56 -03:00
committed by GitHub
parent d00ba15c78
commit 14878a160f
9 changed files with 1172 additions and 77 deletions

View File

@@ -52,6 +52,7 @@ class TestQueryApi(SupersetTestCase):
rows: int = 100,
tab_name: str = "",
status: str = "success",
changed_on: datetime = datetime(2020, 1, 1),
) -> Query:
database = db.session.query(Database).get(database_id)
user = db.session.query(security_manager.user_model).get(user_id)
@@ -67,7 +68,7 @@ class TestQueryApi(SupersetTestCase):
rows=rows,
tab_name=tab_name,
status=status,
changed_on=datetime(2020, 1, 1),
changed_on=changed_on,
)
db.session.add(query)
db.session.commit()
@@ -394,6 +395,60 @@ class TestQueryApi(SupersetTestCase):
db.session.delete(query)
db.session.commit()
def test_get_updated_since(self):
"""
Query API: Test get queries updated since timestamp
"""
now = datetime.utcnow()
client_id = self.get_random_string()
admin = self.get_user("admin")
example_db = get_example_database()
old_query = self.insert_query(
example_db.id,
admin.id,
self.get_random_string(),
sql="SELECT col1, col2 from table1",
select_sql="SELECT col1, col2 from table1",
executed_sql="SELECT col1, col2 from table1 LIMIT 100",
changed_on=now - timedelta(days=3),
)
updated_query = self.insert_query(
example_db.id,
admin.id,
client_id,
sql="SELECT col1, col2 from table1",
select_sql="SELECT col1, col2 from table1",
executed_sql="SELECT col1, col2 from table1 LIMIT 100",
changed_on=now - timedelta(days=1),
)
self.login(username="admin")
timestamp = datetime.timestamp(now - timedelta(days=2)) * 1000
uri = f"api/v1/query/updated_since?q={prison.dumps({'last_updated_ms': timestamp})}"
rv = self.client.get(uri)
self.assertEqual(rv.status_code, 200)
expected_result = updated_query.to_dict()
data = json.loads(rv.data.decode("utf-8"))
self.assertEqual(len(data["result"]), 1)
for key, value in data["result"][0].items():
# We can't assert timestamp
if key not in (
"changedOn",
"changed_on",
"end_time",
"start_running_time",
"start_time",
"id",
):
self.assertEqual(value, expected_result[key])
# rollback changes
db.session.delete(old_query)
db.session.delete(updated_query)
db.session.commit()
@mock.patch("superset.sql_lab.cancel_query")
@mock.patch("superset.views.core.db.session")
def test_stop_query_not_found(