AA-204: fixed up documentation and tests

This commit is contained in:
Daphne Li-Chen
2020-07-27 14:28:02 -04:00
parent af1a7ca2d8
commit 1d2dee8e25
3 changed files with 26 additions and 16 deletions

View File

@@ -8,8 +8,6 @@ from rest_framework.reverse import reverse
class GradedTotalSerializer(serializers.Serializer):
earned = serializers.FloatField()
first_attempted = serializers.CharField()
graded = serializers.BooleanField()
possible = serializers.FloatField()

View File

@@ -2,7 +2,6 @@
Tests for Progress Tab API in the Course Home API
"""
from datetime import datetime
import ddt
from django.urls import reverse
@@ -10,12 +9,12 @@ from django.urls import reverse
from course_modes.models import CourseMode
from lms.djangoapps.course_home_api.tests.utils import BaseCourseHomeTests
from lms.djangoapps.course_home_api.toggles import COURSE_HOME_MICROFRONTEND
from openedx.features.content_type_gating.models import ContentTypeGatingConfig
from openedx.core.djangoapps.user_api.preferences.api import set_user_preference
from openedx.core.djangoapps.waffle_utils.testutils import override_waffle_flag
from student.models import CourseEnrollment
from student.tests.factories import UserFactory
@override_waffle_flag(COURSE_HOME_MICROFRONTEND, active=True)
@ddt.ddt
class ProgressTabTestViews(BaseCourseHomeTests):
@@ -24,8 +23,7 @@ class ProgressTabTestViews(BaseCourseHomeTests):
"""
def setUp(self):
super().setUp()
self.url = reverse('course-home-progress-tab', args=[self.course.id])
ContentTypeGatingConfig.objects.create(enabled=True, enabled_as_of=datetime(2017, 1, 1))
self.url = reverse('course-home-progress-tab', args=[self.course.id])
@ddt.data(CourseMode.AUDIT, CourseMode.VERIFIED)
def test_get_authenticated_enrolled_user(self, enrollment_mode):
@@ -33,10 +31,10 @@ class ProgressTabTestViews(BaseCourseHomeTests):
response = self.client.get(self.url)
self.assertEqual(response.status_code, 200)
# Pulling out the date blocks to check learner has access.
self.assertNotEqual(response.data['courseware_summary'], None)
# Pulling out the courseware summary to check that the learner is able to see this info
self.assertIsNotNone(response.data['courseware_summary'])
for chapter in response.data['courseware_summary']:
self.assertNotEqual(chapter, None)
self.assertIsNotNone(chapter)
def test_get_authenticated_user_not_enrolled(self):
response = self.client.get(self.url)
@@ -61,7 +59,7 @@ class ProgressTabTestViews(BaseCourseHomeTests):
self.switch_to_staff() # needed for masquerade
# Sanity check on our normal user
self.assertEqual(self.client.get(self.url).data['user_timezone'], None)
self.assertIsNone(self.client.get(self.url).data['user_timezone'])
# Now switch users and confirm we get a different result
self.update_masquerade(username=user.username)

View File

@@ -11,7 +11,7 @@ from opaque_keys.edx.keys import CourseKey
from lms.djangoapps.course_home_api.progress.v1.serializers import ProgressTabSerializer
from student.models import CourseEnrollment, UserTestGroup
from student.models import CourseEnrollment
from lms.djangoapps.course_api.blocks.transformers.blocks_api import BlocksAPITransformer
from lms.djangoapps.courseware.context_processor import user_timezone_locale_prefs
from lms.djangoapps.courseware.courses import get_course_with_access
@@ -39,10 +39,6 @@ class ProgressTabView(RetrieveAPIView):
Body consists of the following fields:
user: Serialized User object. The serialization has the following fields:
username: (str) The username of the user
email: (str) the email of the user
is_staff: (bool) boolean indicating whether the user has staff permisions or not
course_blocks:
blocks: List of serialized Course Block objects. Each serialization has the following fields:
id: (str) The usage ID of the block.
@@ -55,11 +51,29 @@ class ProgressTabView(RetrieveAPIView):
xBlock on the web LMS.
children: (list) If the block has child blocks, a list of IDs of
the child blocks.
courseware_summary: List of serialized Chapters. each Chapter has the following fields:
display_name: (str) a str of what the name of the Chapter is for displaying on the site
subsections: List of serialized Subsections, each has the following fields:
display_name: (str) a str of what the name of the Subsection is for displaying on the site
due: (str) a DateTime string for when the Subsection is due
format: (str) the format, if any, of the Subsection (Homework, Exam, etc)
graded: (bool) whether or not the Subsection is graded
graded_total: an object containing the following fields
earned: (float) the amount of points the user earned
possible: (float) the amount of points the user could have earned
percent_graded: (float) the percentage of the points the user received for the subsection
show_correctness: (str) a str representing whether to show the problem/practice scores based on due date
show_grades: (bool) a bool for whether to show grades based on the access the user has
url: (str) the absolute path url to the Subsection
enrollment_mode: (str) a str representing the enrollment the user has ('audit', 'verified', ...)
user_timezone: (str) The user's preferred timezone
**Returns**
* 200 on success with above fields.
* 302 if the user is not enrolled.
* 403 if the user is not authenticated.
* 404 if the course is not available or cannot be seen.
"""
@@ -102,8 +116,8 @@ class ProgressTabView(RetrieveAPIView):
data = {
'course_blocks': course_blocks,
'enrollment_mode': enrollment_mode,
'courseware_summary': courseware_summary,
'enrollment_mode': enrollment_mode,
'user_timezone': user_timezone,
}
context = self.get_serializer_context()