From 1fcd39913b4cdf39e1c2c0bee7f3b71d0fce478f Mon Sep 17 00:00:00 2001 From: Brian Mesick Date: Wed, 17 Apr 2024 10:13:36 -0400 Subject: [PATCH] test: Update tests --- platform_plugin_aspects/tests/test_utils.py | 29 +++++++++++++++++++++ platform_plugin_aspects/utils.py | 5 +++- test_settings.py | 4 +-- 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/platform_plugin_aspects/tests/test_utils.py b/platform_plugin_aspects/tests/test_utils.py index 6373cff..a4322aa 100644 --- a/platform_plugin_aspects/tests/test_utils.py +++ b/platform_plugin_aspects/tests/test_utils.py @@ -196,3 +196,32 @@ def test_generate_guest_token_succesful(self, mock_superset_client): mock_superset_client.assert_called_once() self.assertEqual(token, "test-token") + + @patch("platform_plugin_aspects.utils.SupersetClient") + def test_generate_guest_token_loc(self, mock_superset_client): + """ + Test generate_guest_token works. + """ + response_mock = Mock(status_code=200) + mock_superset_client.return_value.session.post.return_value = response_mock + response_mock.json.return_value = { + "token": "test-token", + } + + filter_mock = Mock() + user_mock = Mock() + dashboards = [{"name": "test", "uuid": "1d6bf904-f53f-47fd-b1c9-6cd7e284d286", "allow_translations": True}] + + token = generate_guest_token( + user=user_mock, + course=COURSE_ID, + dashboards=dashboards, + filters=[filter_mock], + ) + + mock_superset_client.assert_called_once() + self.assertEqual(token, "test-token") + + # We should have one resource for en_US, one for es_419, and one untranslated + calls = mock_superset_client.return_value.session.post.call_args + self.assertEqual(len(calls[1]["json"]["resources"]), 3) diff --git a/platform_plugin_aspects/utils.py b/platform_plugin_aspects/utils.py index 4e811cf..ed7bf93 100644 --- a/platform_plugin_aspects/utils.py +++ b/platform_plugin_aspects/utils.py @@ -119,7 +119,10 @@ def generate_guest_token(user, course, dashboards, filters) -> str: if dashboard.get("allow_translations"): for locale in settings.SUPERSET_DASHBOARD_LOCALES: resources.append( - {"type": "dashboard", "id": get_localized_uuid(dashboard["uuid"], locale)} + { + "type": "dashboard", + "id": get_localized_uuid(dashboard["uuid"], locale), + } ) data = { diff --git a/test_settings.py b/test_settings.py index 8ab4b80..d13b797 100644 --- a/test_settings.py +++ b/test_settings.py @@ -33,8 +33,8 @@ # Disable caching in tests. CACHES = { - 'default': { - 'BACKEND': 'django.core.cache.backends.dummy.DummyCache', + "default": { + "BACKEND": "django.core.cache.backends.dummy.DummyCache", } }