Skip to content

Commit

Permalink
test: add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ttqureshi committed Nov 4, 2024
1 parent fe9f7ae commit 1f00bf5
Show file tree
Hide file tree
Showing 3 changed files with 594 additions and 20 deletions.
56 changes: 56 additions & 0 deletions xblocks_contrib/lti/tests/helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
"""
Utility methods for unit tests.
"""


import pytest
from path import Path as path
from xblock.reference.user_service import UserService, XBlockUser


class StubUserService(UserService):
"""
Stub UserService for testing the sequence block.
"""

def __init__(self,
user=None,
user_is_staff=False,
user_role=None,
anonymous_user_id=None,
deprecated_anonymous_user_id=None,
request_country_code=None,
**kwargs):
self.user = user
self.user_is_staff = user_is_staff
self.user_role = user_role
self.anonymous_user_id = anonymous_user_id
self.deprecated_anonymous_user_id = deprecated_anonymous_user_id
self.request_country_code = request_country_code
self._django_user = user
super().__init__(**kwargs)

def get_current_user(self):
"""
Implements abstract method for getting the current user.
"""
user = XBlockUser()
if self.user and self.user.is_authenticated:
user.opt_attrs['edx-platform.anonymous_user_id'] = self.anonymous_user_id
user.opt_attrs['edx-platform.deprecated_anonymous_user_id'] = self.deprecated_anonymous_user_id
user.opt_attrs['edx-platform.request_country_code'] = self.request_country_code
user.opt_attrs['edx-platform.user_is_staff'] = self.user_is_staff
user.opt_attrs['edx-platform.user_id'] = self.user.id
user.opt_attrs['edx-platform.user_role'] = self.user_role
user.opt_attrs['edx-platform.username'] = self.user.username
else:
user.opt_attrs['edx-platform.username'] = 'anonymous'
user.opt_attrs['edx-platform.request_country_code'] = self.request_country_code
user.opt_attrs['edx-platform.is_authenticated'] = False
return user

def get_user_by_anonymous_id(self, uid=None): # pylint: disable=unused-argument
"""
Return the original user passed into the service.
"""
return self.user
2 changes: 1 addition & 1 deletion xblocks_contrib/lti/tests/test_lti20_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from lti_2_util import LTIError
from lti import LTIBlock
from xmodule.tests.helpers import StubUserService
from .helpers import StubUserService

from . import get_test_system

Expand Down
Loading

0 comments on commit 1f00bf5

Please sign in to comment.