refactor: use UserService to remove deprecation warnings

from code and tests.
This commit is contained in:
Jillian Vogel
2021-12-17 14:04:40 +10:30
committed by Piotr Surowiec
parent e378e42bfa
commit f828d89feb
6 changed files with 30 additions and 23 deletions

View File

@@ -9,7 +9,6 @@ from django.conf import settings
from xblock.exceptions import NoSuchServiceError
from common.djangoapps.edxmako.shortcuts import render_to_string
from common.djangoapps.xblock_django.constants import ATTR_KEY_ANONYMOUS_USER_ID
def edxnotes(cls):
@@ -43,8 +42,7 @@ def edxnotes(cls):
# - the feature flag or `edxnotes` setting of the course is set to False
# - the user is not authenticated
try:
user_id = self.runtime.service(self, 'user').get_current_user().opt_attrs.get(ATTR_KEY_ANONYMOUS_USER_ID)
user = self.runtime.get_real_user(user_id)
user = self.runtime.service(self, 'user').get_user_by_anonymous_id()
except NoSuchServiceError:
user = None

View File

@@ -33,6 +33,7 @@ from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disa
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order
from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory # lint-amnesty, pylint: disable=wrong-import-order
from xmodule.tabs import CourseTab # lint-amnesty, pylint: disable=wrong-import-order
from xmodule.tests.helpers import StubUserService # lint-amnesty, pylint: disable=wrong-import-order
from . import helpers
from .decorators import edxnotes
@@ -81,7 +82,8 @@ class TestProblem:
self.system = MagicMock(is_author_mode=False)
self.scope_ids = MagicMock(usage_id="test_usage_id")
user = user or UserFactory()
self.runtime = MagicMock(course_id=course.id, get_real_user=lambda __: user)
user_service = StubUserService(user)
self.runtime = MagicMock(course_id=course.id, service=lambda _a, _b: user_service)
self.descriptor = MagicMock()
self.descriptor.runtime.modulestore.get_course.return_value = course