Skip to content

Commit

Permalink
test: Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bmtcril committed Apr 17, 2024
1 parent 93992f8 commit 1fcd399
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
29 changes: 29 additions & 0 deletions platform_plugin_aspects/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
5 changes: 4 additions & 1 deletion platform_plugin_aspects/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
4 changes: 2 additions & 2 deletions test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}
}

Expand Down

0 comments on commit 1fcd399

Please sign in to comment.