From 36a49ec37abe480db307f677bc08796388adccd3 Mon Sep 17 00:00:00 2001 From: ruzniaievdm Date: Tue, 30 Jan 2024 18:30:53 +0200 Subject: [PATCH] feat: [AXIMST-166] Certificates screen additional data --- .../rest_api/v1/serializers/certificates.py | 3 + .../rest_api/v1/views/certificates.py | 59 ++++++++++--------- .../v1/views/tests/test_certificates.py | 10 +++- 3 files changed, 41 insertions(+), 31 deletions(-) diff --git a/cms/djangoapps/contentstore/rest_api/v1/serializers/certificates.py b/cms/djangoapps/contentstore/rest_api/v1/serializers/certificates.py index 04d028e24178..9e536efa4550 100644 --- a/cms/djangoapps/contentstore/rest_api/v1/serializers/certificates.py +++ b/cms/djangoapps/contentstore/rest_api/v1/serializers/certificates.py @@ -47,3 +47,6 @@ class CourseCertificatesSerializer(serializers.Serializer): mfe_proctored_exam_settings_url = serializers.CharField( required=False, allow_null=True, allow_blank=True ) + course_number = serializers.CharField(source="context_course.number") + course_title = serializers.CharField(source="context_course.display_name_with_default") + course_number_override = serializers.CharField(source="context_course.display_coursenumber") diff --git a/cms/djangoapps/contentstore/rest_api/v1/views/certificates.py b/cms/djangoapps/contentstore/rest_api/v1/views/certificates.py index e338786d9c81..db93d65da68a 100644 --- a/cms/djangoapps/contentstore/rest_api/v1/views/certificates.py +++ b/cms/djangoapps/contentstore/rest_api/v1/views/certificates.py @@ -58,35 +58,38 @@ def get(self, request: Request, course_id: str): ```json { - "certificate_activation_handler_url": "/certificates/activation/course-v1:org+101+101/", - "certificate_web_view_url": "///certificates/course/course-v1:org+101+101?preview=honor", - "certificates": [ - { - "course_title": "Course title", - "description": "Description of the certificate", - "editing": false, - "id": 1622146085, - "is_active": false, - "name": "Name of the certificate", - "signatories": [ + "certificate_activation_handler_url": "/certificates/activation/course-v1:org+101+101/", + "certificate_web_view_url": "///certificates/course/course-v1:org+101+101?preview=honor", + "certificates": [ { - "id": 268550145, - "name": "name_sign", - "organization": "org", - "signature_image_path": "/asset-v1:org+101+101+type@asset+block@camera.png", - "title": "title_sign" - } - ], - "version": 1 - } - ], - "course_modes": [ - "honor" - ], - "has_certificate_modes": true, - "is_active": false, - "is_global_staff": true, - "mfe_proctored_exam_settings_url": "" + "course_title": "Course title", + "description": "Description of the certificate", + "editing": false, + "id": 1622146085, + "is_active": false, + "name": "Name of the certificate", + "signatories": [ + { + "id": 268550145, + "name": "name_sign", + "organization": "org", + "signature_image_path": "/asset-v1:org+101+101+type@asset+block@camera.png", + "title": "title_sign" + } + ], + "version": 1 + }, + ], + "course_modes": [ + "honor" + ], + "has_certificate_modes": true, + "is_active": false, + "is_global_staff": true, + "mfe_proctored_exam_settings_url": "", + "course_number": "DemoX", + "course_title": "Demonstration Course", + "course_number_override": "Course Number Display String" } ``` """ diff --git a/cms/djangoapps/contentstore/rest_api/v1/views/tests/test_certificates.py b/cms/djangoapps/contentstore/rest_api/v1/views/tests/test_certificates.py index e63cda981ac9..db9d1dacca90 100644 --- a/cms/djangoapps/contentstore/rest_api/v1/views/tests/test_certificates.py +++ b/cms/djangoapps/contentstore/rest_api/v1/views/tests/test_certificates.py @@ -28,7 +28,11 @@ def test_success_response(self): """ self._add_course_certificates(count=2, signatory_count=2) response = self.client.get(self.url) + response_data = response.data self.assertEqual(response.status_code, status.HTTP_200_OK) - self.assertEqual(len(response.data["certificates"]), 2) - self.assertEqual(len(response.data["certificates"][0]["signatories"]), 2) - self.assertEqual(len(response.data["certificates"][1]["signatories"]), 2) + self.assertEqual(len(response_data["certificates"]), 2) + self.assertEqual(len(response_data["certificates"][0]["signatories"]), 2) + self.assertEqual(len(response_data["certificates"][1]["signatories"]), 2) + self.assertEqual(response_data["course_number_override"], self.course.display_coursenumber) + self.assertEqual(response_data["course_title"], self.course.display_name_with_default) + self.assertEqual(response_data["course_number"], self.course.number)