From d35da1fc733547533ceb883a35e7142069b3da26 Mon Sep 17 00:00:00 2001 From: Daniel Vaz Gaspar Date: Mon, 10 Jan 2022 13:00:39 +0000 Subject: [PATCH] fix: css template API response, less data (#17980) * fix: css template API response, less data * add test --- superset/css_templates/api.py | 4 +++- .../css_templates/api_tests.py | 20 +++++++++++++------ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/superset/css_templates/api.py b/superset/css_templates/api.py index 8f1134b36369..5cc36f400198 100644 --- a/superset/css_templates/api.py +++ b/superset/css_templates/api.py @@ -63,7 +63,9 @@ class CssTemplateRestApi(BaseSupersetModelRestApi): ] list_columns = [ "changed_on_delta_humanized", - "changed_by", + "changed_by.first_name", + "changed_by.id", + "changed_by.last_name", "created_on", "created_by.first_name", "created_by.id", diff --git a/tests/integration_tests/css_templates/api_tests.py b/tests/integration_tests/css_templates/api_tests.py index 840149481dc0..4e714318b3d3 100644 --- a/tests/integration_tests/css_templates/api_tests.py +++ b/tests/integration_tests/css_templates/api_tests.py @@ -38,7 +38,7 @@ def insert_css_template( ) -> CssTemplate: admin = self.get_user(created_by_username) css_template = CssTemplate( - template_name=template_name, css=css, created_by=admin + template_name=template_name, css=css, created_by=admin, changed_by=admin ) db.session.add(css_template) db.session.commit() @@ -75,15 +75,23 @@ def test_get_list_css_template(self): data = json.loads(rv.data.decode("utf-8")) assert data["count"] == len(css_templates) expected_columns = [ - "changed_on_delta_humanized", "changed_by", - "created_on", + "changed_on_delta_humanized", "created_by", - "template_name", + "created_on", "css", + "id", + "template_name", ] - for expected_column in expected_columns: - assert expected_column in data["result"][0] + result_columns = list(data["result"][0].keys()) + result_columns.sort() + assert expected_columns == result_columns + created_by_columns = list(data["result"][0]["created_by"].keys()) + created_by_columns.sort() + assert ["first_name", "id", "last_name"] == created_by_columns + changed_by_columns = list(data["result"][0]["changed_by"].keys()) + changed_by_columns.sort() + assert ["first_name", "id", "last_name"] == changed_by_columns @pytest.mark.usefixtures("create_css_templates") def test_get_list_sort_css_template(self):