mirror of
https://github.com/apache/superset.git
synced 2026-04-20 00:24:38 +00:00
fix: humanised changed on UTC on dashboards and charts (#10321)
* fix: API marshmallow3 drop utc for naive datetime fields * fix: API marshmallow3 drop utc for naive datetime fields * fix, tests * isort and test * black * add and fix test * fix comment
This commit is contained in:
committed by
GitHub
parent
ac85aebe4a
commit
74cb82e1ad
@@ -18,9 +18,11 @@
|
||||
"""Unit tests for Superset"""
|
||||
import json
|
||||
from typing import List, Optional
|
||||
from datetime import datetime
|
||||
from unittest import mock
|
||||
|
||||
import prison
|
||||
import humanize
|
||||
from sqlalchemy.sql import func
|
||||
|
||||
from tests.test_app import app
|
||||
@@ -543,6 +545,34 @@ class TestChartApi(SupersetTestCase, ApiOwnersTestCaseMixin):
|
||||
data = json.loads(rv.data.decode("utf-8"))
|
||||
self.assertEqual(data["count"], 33)
|
||||
|
||||
def test_get_charts_changed_on(self):
|
||||
"""
|
||||
Dashboard API: Test get charts changed on
|
||||
"""
|
||||
admin = self.get_user("admin")
|
||||
start_changed_on = datetime.now()
|
||||
chart = self.insert_chart("foo_a", [admin.id], 1, description="ZY_bar")
|
||||
|
||||
self.login(username="admin")
|
||||
|
||||
arguments = {
|
||||
"order_column": "changed_on_delta_humanized",
|
||||
"order_direction": "desc",
|
||||
}
|
||||
uri = f"api/v1/chart/?q={prison.dumps(arguments)}"
|
||||
|
||||
rv = self.get_assert_metric(uri, "get_list")
|
||||
self.assertEqual(rv.status_code, 200)
|
||||
data = json.loads(rv.data.decode("utf-8"))
|
||||
self.assertEqual(
|
||||
data["result"][0]["changed_on_delta_humanized"],
|
||||
humanize.naturaltime(datetime.now() - start_changed_on),
|
||||
)
|
||||
|
||||
# rollback changes
|
||||
db.session.delete(chart)
|
||||
db.session.commit()
|
||||
|
||||
def test_get_charts_filter(self):
|
||||
"""
|
||||
Chart API: Test get charts filter
|
||||
|
||||
@@ -18,8 +18,10 @@
|
||||
"""Unit tests for Superset"""
|
||||
import json
|
||||
from typing import List, Optional
|
||||
from datetime import datetime
|
||||
|
||||
import prison
|
||||
import humanize
|
||||
from sqlalchemy.sql import func
|
||||
|
||||
import tests.test_app
|
||||
@@ -111,7 +113,7 @@ class TestDashboardApi(SupersetTestCase, ApiOwnersTestCaseMixin):
|
||||
data = json.loads(rv.data.decode("utf-8"))
|
||||
self.assertIn("changed_on", data["result"])
|
||||
for key, value in data["result"].items():
|
||||
# We can't assert timestamp
|
||||
# We can't assert timestamp values
|
||||
if key != "changed_on":
|
||||
self.assertEqual(value, expected_result[key])
|
||||
# rollback changes
|
||||
@@ -152,6 +154,37 @@ class TestDashboardApi(SupersetTestCase, ApiOwnersTestCaseMixin):
|
||||
db.session.delete(dashboard)
|
||||
db.session.commit()
|
||||
|
||||
def test_get_dashboards_changed_on(self):
|
||||
"""
|
||||
Dashboard API: Test get dashboards changed on
|
||||
"""
|
||||
from datetime import datetime
|
||||
import humanize
|
||||
|
||||
admin = self.get_user("admin")
|
||||
start_changed_on = datetime.now()
|
||||
dashboard = self.insert_dashboard("title", "slug1", [admin.id])
|
||||
|
||||
self.login(username="admin")
|
||||
|
||||
arguments = {
|
||||
"order_column": "changed_on_delta_humanized",
|
||||
"order_direction": "desc",
|
||||
}
|
||||
uri = f"api/v1/dashboard/?q={prison.dumps(arguments)}"
|
||||
|
||||
rv = self.get_assert_metric(uri, "get_list")
|
||||
self.assertEqual(rv.status_code, 200)
|
||||
data = json.loads(rv.data.decode("utf-8"))
|
||||
self.assertEqual(
|
||||
data["result"][0]["changed_on_delta_humanized"],
|
||||
humanize.naturaltime(datetime.now() - start_changed_on),
|
||||
)
|
||||
|
||||
# rollback changes
|
||||
db.session.delete(dashboard)
|
||||
db.session.commit()
|
||||
|
||||
def test_get_dashboards_filter(self):
|
||||
"""
|
||||
Dashboard API: Test get dashboards filter
|
||||
@@ -214,9 +247,9 @@ class TestDashboardApi(SupersetTestCase, ApiOwnersTestCaseMixin):
|
||||
self.assertEqual(data["count"], 3)
|
||||
|
||||
expected_response = [
|
||||
{"slug": "ZY_bar", "dashboard_title": "foo_a",},
|
||||
{"slug": "slug1zy_", "dashboard_title": "foo_b",},
|
||||
{"slug": "slug1", "dashboard_title": "zy_foo",},
|
||||
{"slug": "ZY_bar", "dashboard_title": "foo_a"},
|
||||
{"slug": "slug1zy_", "dashboard_title": "foo_b"},
|
||||
{"slug": "slug1", "dashboard_title": "zy_foo"},
|
||||
]
|
||||
for index, item in enumerate(data["result"]):
|
||||
self.assertEqual(item["slug"], expected_response[index]["slug"])
|
||||
|
||||
Reference in New Issue
Block a user