Skip to content

Commit

Permalink
fix: improve test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
pomegranited committed Mar 12, 2024
1 parent a82d845 commit c1c4e11
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
20 changes: 16 additions & 4 deletions platform_plugin_aspects/tests/test_xblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from opaque_keys.edx.locator import CourseLocator
from xblock.field_data import DictFieldData
from xblock.reference.user_service import XBlockUser

from ..xblock import SupersetXBlock

Expand All @@ -17,7 +18,11 @@ def make_an_xblock(user_role, **kwargs):
"""
course_id = CourseLocator("foo", "bar", "baz")
mock_user = Mock(
opt_attrs={"edx-platform.user_role": user_role},
spec=XBlockUser,
opt_attrs={
"edx-platform.username": user_role,
"edx-platform.user_role": user_role,
},
)

def service(block, service): # pylint: disable=unused-argument
Expand Down Expand Up @@ -47,14 +52,21 @@ class TestRender(TestCase):
Test the HTML rendering of the XBlock
"""

@patch("platform_plugin_aspects.utils._generate_guest_token")
def test_render_instructor(self, mock_generate_guest_token):
@patch("platform_plugin_aspects.utils.SupersetClient")
def test_render_instructor(self, mock_superset_client):
"""
Ensure staff can see the Superset dashboard.
"""
mock_generate_guest_token.return_value = ("test-token", "test-dashboard-uuid")
mock_superset_client.return_value = Mock(
session=Mock(
post=Mock(
return_value=Mock(json=Mock(return_value={"token": "test_token"}))
)
)
)
xblock = make_an_xblock("instructor")
student_view = xblock.student_view()
mock_superset_client.assert_called_once()
html = student_view.content
self.assertIsNotNone(html)
self.assertIn("superset-embedded-container", html)
Expand Down
6 changes: 2 additions & 4 deletions platform_plugin_aspects/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,9 @@ def _superset_user_data(user: XBlockUser) -> dict:
# Django User
if hasattr(user, "username"):
username = user.username
# XBlockUser
elif hasattr(user, "opt_attrs"):
username = user.opt_attrs.get("edx-platform.username")
else:
raise NotImplementedError(f"Unsupported user type {user}")
assert isinstance(user, XBlockUser)
username = user.opt_attrs.get("edx-platform.username")

return {
"username": username,
Expand Down
2 changes: 1 addition & 1 deletion platform_plugin_aspects/xblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def student_view(self, context=None):
return frag

@staticmethod
def workbench_scenarios():
def workbench_scenarios(): # pragma: no cover
"""Return a canned scenario for display in the workbench."""
return [
(
Expand Down

0 comments on commit c1c4e11

Please sign in to comment.