From 57e41da89ebf55233b938a3c616254321b2ff614 Mon Sep 17 00:00:00 2001 From: Fernando Date: Tue, 24 Oct 2023 23:04:54 -0400 Subject: [PATCH] fix: style and some test and docs improvements --- lms/djangoapps/ora_staff_grader/constants.py | 2 +- lms/djangoapps/ora_staff_grader/ora_api.py | 7 +++--- .../ora_staff_grader/serializers.py | 12 +++++----- .../tests/test_serializers.py | 20 ++++++++--------- lms/djangoapps/ora_staff_grader/views.py | 22 +++++++++---------- 5 files changed, 33 insertions(+), 30 deletions(-) diff --git a/lms/djangoapps/ora_staff_grader/constants.py b/lms/djangoapps/ora_staff_grader/constants.py index 1ff67d79d26e..d57f52540108 100644 --- a/lms/djangoapps/ora_staff_grader/constants.py +++ b/lms/djangoapps/ora_staff_grader/constants.py @@ -3,7 +3,7 @@ # Query params PARAM_ORA_LOCATION = "oraLocation" PARAM_SUBMISSION_ID = "submissionUUID" -PARAM_ASSESSMENT_TYPE = "assessmentType" +PARAM_ASSESSMENT_FILTER = "assessmentFilter" # Error codes ERR_UNKNOWN = "ERR_UNKNOWN" diff --git a/lms/djangoapps/ora_staff_grader/ora_api.py b/lms/djangoapps/ora_staff_grader/ora_api.py index 1e54e9ccc728..c97ea4819d4e 100644 --- a/lms/djangoapps/ora_staff_grader/ora_api.py +++ b/lms/djangoapps/ora_staff_grader/ora_api.py @@ -12,6 +12,7 @@ These are checked (usually by checking for a {"success":false} response) and raise errors, possibly with extra context. """ import json +from http import HTTPStatus from lms.djangoapps.ora_staff_grader.errors import ( LockContestedError, XBlockInternalError, @@ -33,12 +34,12 @@ def get_submissions(request, usage_id): return json.loads(response.content) -def get_assessments(request, usage_id, submission_uuid, assessment_type): +def get_assessments(request, usage_id, submission_uuid, assessment_filter): """ Get a list of assessments from the ORA's 'list_assessments_grades' XBlock.json_handler """ handler_name = "list_assessments" - body = {"item_id": usage_id, "submission_uuid": submission_uuid, "assessment_type": assessment_type} + body = {"item_id": usage_id, "submission_uuid": submission_uuid, "assessment_filter": assessment_filter} response = call_xblock_json_handler(request, usage_id, handler_name, body) @@ -183,5 +184,5 @@ def batch_delete_submission_locks(request, usage_id, submission_uuids): response = call_xblock_json_handler(request, usage_id, handler_name, body) # Errors should raise a blanket exception. Otherwise body is empty, 200 is implicit success - if response.status_code != 200: + if response.status_code != HTTPStatus.OK: raise XBlockInternalError(context={"handler": handler_name}) diff --git a/lms/djangoapps/ora_staff_grader/serializers.py b/lms/djangoapps/ora_staff_grader/serializers.py index fcb41eecf4c6..e3fced951f7b 100644 --- a/lms/djangoapps/ora_staff_grader/serializers.py +++ b/lms/djangoapps/ora_staff_grader/serializers.py @@ -167,7 +167,9 @@ class Meta: class AssessmentScoresSerializer(serializers.Serializer): """ - Assessment Score for displaying assessment table in Enhanced Staff Grader (ESG) + Score information associated with a specific assessment. + + This serializer was intended for displaying assessment information in the Enhanced Staff Grader (ESG). """ criterion_name = serializers.CharField() score_earned = serializers.IntegerField() @@ -184,9 +186,9 @@ class Meta: class AssessmentSerializer(serializers.Serializer): """ - Assessment metadata for displaying assessment table in Enhanced Staff Grader (ESG) + Data for displaying Assessment objects in a table in Enhanced Staff Grader (ESG) """ - id_assessment = serializers.CharField() + assessment_id = serializers.CharField() scorer_name = serializers.CharField(allow_null=True) scorer_username = serializers.CharField(allow_null=True) scorer_email = serializers.CharField(allow_null=True) @@ -197,7 +199,7 @@ class AssessmentSerializer(serializers.Serializer): class Meta: fields = [ - "id_assessment", + "assessment_id", "scorer_name", "scorer_username", "scorer_email", @@ -236,7 +238,7 @@ def get_isEnabled(self, obj): class AssessmentFeedbackSerializer(serializers.Serializer): """ - Serialize info for the initialize call. Packages ORA, course, submission, and rubric data. + Serialize info for every assessment for a table in Enhanced Staff Grader (ESG) """ assessments = serializers.ListField(child=AssessmentSerializer()) diff --git a/lms/djangoapps/ora_staff_grader/tests/test_serializers.py b/lms/djangoapps/ora_staff_grader/tests/test_serializers.py index e4f67fd1d698..6189dfcd1cf0 100644 --- a/lms/djangoapps/ora_staff_grader/tests/test_serializers.py +++ b/lms/djangoapps/ora_staff_grader/tests/test_serializers.py @@ -239,8 +239,8 @@ class TestSubmissionMetadataSerializer(TestCase): "submissionUuid": "a", "username": "foo", "teamName": "", - 'email': None, - 'fullname': None, + 'email': "jondoes@example.com", + 'fullname': "", "dateSubmitted": "1969-07-16 13:32:00", "dateGraded": "None", "gradedBy": "", @@ -251,8 +251,8 @@ class TestSubmissionMetadataSerializer(TestCase): "b": { "submissionUuid": "b", "username": "", - 'email': None, - 'fullname': None, + 'email': "jondoes@example.com", + 'fullname': "Jhon Does", "teamName": "bar", "dateSubmitted": "1969-07-20 20:17:40", "dateGraded": "None", @@ -264,8 +264,8 @@ class TestSubmissionMetadataSerializer(TestCase): "c": { "submissionUuid": "c", "username": "baz", - 'email': None, - 'fullname': None, + 'email': "jondoes@example.com", + 'fullname': "Jhon Does", "teamName": "", "dateSubmitted": "1969-07-21 21:35:00", "dateGraded": "1969-07-24 16:44:00", @@ -297,8 +297,8 @@ def test_empty_score(self): submission = { "submissionUuid": "empty-score", "username": "WOPR", - 'email': None, - 'fullname': None, + 'email': "jhondoes@example.com", + 'fullname': "", "dateSubmitted": "1983-06-03 00:00:00", "dateGraded": None, "gradedBy": None, @@ -310,8 +310,8 @@ def test_empty_score(self): expected_output = { "submissionUUID": "empty-score", "username": "WOPR", - 'email': None, - 'fullname': None, + 'email': "jhondoes@example.com", + 'fullname': "", "teamName": None, "dateSubmitted": "1983-06-03 00:00:00", "dateGraded": None, diff --git a/lms/djangoapps/ora_staff_grader/views.py b/lms/djangoapps/ora_staff_grader/views.py index e826cacd327f..6a0355b99a05 100644 --- a/lms/djangoapps/ora_staff_grader/views.py +++ b/lms/djangoapps/ora_staff_grader/views.py @@ -24,7 +24,7 @@ from lms.djangoapps.ora_staff_grader.constants import ( PARAM_ORA_LOCATION, PARAM_SUBMISSION_ID, - PARAM_ASSESSMENT_TYPE, + PARAM_ASSESSMENT_FILTER, ) from lms.djangoapps.ora_staff_grader.errors import ( BadOraLocationResponse, @@ -152,13 +152,10 @@ def get(self, request, ora_location, *args, **kwargs): class AssessmentFeedbackView(StaffGraderBaseView): """ - GET course metadata + GET data about Assessments by submission_uuid and ora_location Response: { - courseMetadata - oraMetadata - submissions - isEnabled + assessments } Errors: @@ -168,19 +165,22 @@ class AssessmentFeedbackView(StaffGraderBaseView): - UnknownError (HTTP 500) for other errors """ - @require_params([PARAM_ORA_LOCATION, PARAM_SUBMISSION_ID, PARAM_ASSESSMENT_TYPE]) - def get(self, request, ora_location, submission_uuid, assessment_type=None, *args, **kwargs): + @require_params([PARAM_ORA_LOCATION, PARAM_SUBMISSION_ID, PARAM_ASSESSMENT_FILTER]) + def get(self, request, ora_location, submission_uuid, assessment_filter=None, *args, **kwargs): try: assessments_data = {} - # Get list of submissions for this ORA - assessments_data["assessments"] = get_assessments(request, ora_location, submission_uuid, assessment_type) + assessments_data["assessments"] = get_assessments(request, ora_location, submission_uuid, assessment_filter) response_data = AssessmentFeedbackSerializer(assessments_data).data - log.info(response_data) return Response(response_data) + # Catch bad ORA location + except (InvalidKeyError, ItemNotFoundError): + log.error(f"Bad ORA location provided: {ora_location}") + return BadOraLocationResponse() + # Issues with the XBlock handlers except XBlockInternalError as ex: log.error(ex)