-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adds endpoints for fetchGuestToken
* generate_superset_context : adds a superset_guest_token_url to the context * generate_superset_token : called when ^ hit instead of on render. * adds a plugin url and view * removes superset_token from the context * adds/updates tests
- Loading branch information
1 parent
da0bb9c
commit 01737d6
Showing
14 changed files
with
304 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
""" | ||
Test views. | ||
""" | ||
|
||
from unittest.mock import patch | ||
|
||
from django.contrib.auth import get_user_model | ||
from django.test import TestCase | ||
from django.urls import reverse | ||
|
||
COURSE_ID = "course-v1:org+course+run" | ||
User = get_user_model() | ||
|
||
|
||
class ViewsTestCase(TestCase): | ||
""" | ||
Test cases for the plugin views and URLs. | ||
""" | ||
|
||
def setUp(self): | ||
""" | ||
Set up data used by multiple tests. | ||
""" | ||
super().setUp() | ||
self.superset_guest_token_url = reverse( | ||
"superset_guest_token", | ||
kwargs={"course_id": COURSE_ID}, | ||
) | ||
self.user = User.objects.create( | ||
username="user", | ||
email="[email protected]", | ||
) | ||
self.user.set_password("password") | ||
self.user.save() | ||
|
||
def test_guest_token_requires_authorization(self): | ||
""" | ||
Unauthenticated hits to the endpoint redirect to login. | ||
""" | ||
response = self.client.post(self.superset_guest_token_url) | ||
self.assertEqual(response.status_code, 302) | ||
self.assertIn("login", response.url) | ||
|
||
@patch("platform_plugin_aspects.views.generate_guest_token") | ||
def test_guest_token(self, mock_generate_guest_token): | ||
mock_generate_guest_token.return_value = ("test-token", "test-dashboard-uuid") | ||
self.client.login(username="user", password="password") | ||
response = self.client.post(self.superset_guest_token_url, follow=True) | ||
self.assertEqual(response.status_code, 200) | ||
self.assertEqual(response.json().get("guestToken"), "test-token") | ||
mock_generate_guest_token.assert_called_once() |
Oops, something went wrong.