fix: Remove debugging flag that is no longer necessary and refactor
This commit is contained in:
@@ -8,11 +8,12 @@ from django.conf import settings
|
||||
from django.urls import reverse
|
||||
from edx_toggles.toggles.testutils import override_waffle_flag
|
||||
from milestones.tests.utils import MilestonesTestCaseMixin
|
||||
from mock import patch
|
||||
from rest_framework.test import APIClient # pylint: disable=unused-import
|
||||
|
||||
from common.djangoapps.student.models import CourseEnrollment # pylint: disable=unused-import
|
||||
from common.djangoapps.student.tests.factories import UserFactory # pylint: disable=unused-import
|
||||
from lms.djangoapps.course_goals.toggles import RECORD_USER_ACTIVITY_FLAG
|
||||
from lms.djangoapps.course_goals.toggles import COURSE_GOALS_NUMBER_OF_DAYS_GOALS
|
||||
from lms.djangoapps.mobile_api.testutils import MobileAPITestCase, MobileAuthTestMixin, MobileCourseAccessTestMixin
|
||||
from lms.djangoapps.mobile_api.utils import API_V1, API_V05
|
||||
from xmodule.html_module import CourseInfoBlock
|
||||
@@ -229,7 +230,7 @@ class TestHandouts(MobileAPITestCase, MobileAuthTestMixin, MobileCourseAccessTes
|
||||
self.login_and_enroll()
|
||||
|
||||
|
||||
@override_waffle_flag(RECORD_USER_ACTIVITY_FLAG, active=True)
|
||||
@override_waffle_flag(COURSE_GOALS_NUMBER_OF_DAYS_GOALS, active=True)
|
||||
class TestCourseGoalsUserActivityAPI(MobileAPITestCase, SharedModuleStoreTestCase):
|
||||
"""
|
||||
Testing the Course Goals User Activity API.
|
||||
@@ -278,3 +279,21 @@ class TestCourseGoalsUserActivityAPI(MobileAPITestCase, SharedModuleStoreTestCas
|
||||
|
||||
response = self.client.post(self.apiUrl, post_data)
|
||||
assert response.status_code == 400
|
||||
|
||||
@override_waffle_flag(COURSE_GOALS_NUMBER_OF_DAYS_GOALS, active=False)
|
||||
@patch('lms.djangoapps.mobile_api.course_info.views.log')
|
||||
def test_flag_disabled(self, mock_logger):
|
||||
'''
|
||||
Test the API behavior when the goals flag is disabled
|
||||
'''
|
||||
post_data = {
|
||||
'user_id': self.user.id,
|
||||
'course_key': self.course.id,
|
||||
}
|
||||
|
||||
response = self.client.post(self.apiUrl, post_data)
|
||||
assert response.status_code == 200
|
||||
mock_logger.warning.assert_called_with(
|
||||
'For this mobile request, user activity is not enabled for this user {} and course {}'.format(
|
||||
str(self.user.id), str(self.course.id))
|
||||
)
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
Views for course info API
|
||||
"""
|
||||
|
||||
import logging
|
||||
|
||||
from django.contrib.auth import get_user_model
|
||||
from opaque_keys import InvalidKeyError
|
||||
from opaque_keys.edx.keys import CourseKey
|
||||
@@ -12,11 +14,13 @@ from rest_framework.views import APIView
|
||||
from common.djangoapps.static_replace import make_static_urls_absolute
|
||||
from lms.djangoapps.courseware.courses import get_course_info_section_module
|
||||
from lms.djangoapps.course_goals.models import UserActivity
|
||||
from lms.djangoapps.course_goals.toggles import COURSE_GOALS_NUMBER_OF_DAYS_GOALS
|
||||
from openedx.core.lib.xblock_utils import get_course_update_items
|
||||
|
||||
from ..decorators import mobile_course_access, mobile_view
|
||||
|
||||
User = get_user_model()
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@mobile_view()
|
||||
@@ -153,6 +157,12 @@ class CourseGoalsRecordUserActivity(APIView):
|
||||
status=status.HTTP_400_BAD_REQUEST,
|
||||
)
|
||||
|
||||
if not COURSE_GOALS_NUMBER_OF_DAYS_GOALS.is_enabled(course_key):
|
||||
log.warning('For this mobile request, user activity is not enabled for this user {} and course {}'.format(
|
||||
str(user_id), str(course_key))
|
||||
)
|
||||
return Response(status=(200))
|
||||
|
||||
# Populate user activity for tracking progress towards a user's course goals
|
||||
UserActivity.record_user_activity(user, course_key)
|
||||
return Response(status=(200))
|
||||
|
||||
@@ -11,7 +11,6 @@ from rest_framework import status
|
||||
from rest_framework.response import Response
|
||||
|
||||
from lms.djangoapps.course_goals.models import UserActivity
|
||||
from lms.djangoapps.course_goals.toggles import RECORD_USER_ACTIVITY_FLAG
|
||||
from lms.djangoapps.courseware.courses import get_course_with_access
|
||||
from lms.djangoapps.courseware.courseware_access_exception import CoursewareAccessException
|
||||
from lms.djangoapps.courseware.exceptions import CourseAccessRedirect
|
||||
@@ -43,11 +42,10 @@ def mobile_course_access(depth=0):
|
||||
depth=depth,
|
||||
check_if_enrolled=True,
|
||||
)
|
||||
if RECORD_USER_ACTIVITY_FLAG.is_enabled():
|
||||
# Record user activity for tracking progress towards a user's course goals (for mobile app)
|
||||
UserActivity.record_user_activity(
|
||||
request.user, course_id, request=request, only_if_mobile_app=True
|
||||
)
|
||||
# Record user activity for tracking progress towards a user's course goals (for mobile app)
|
||||
UserActivity.record_user_activity(
|
||||
request.user, course_id, request=request, only_if_mobile_app=True
|
||||
)
|
||||
except CoursewareAccessException as error:
|
||||
return Response(data=error.to_json(), status=status.HTTP_404_NOT_FOUND)
|
||||
except CourseAccessRedirect as error:
|
||||
|
||||
Reference in New Issue
Block a user