forked from openedx/edx-platform
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Create DRF for course settings and course details views out of
current Django views (openedx#32397) (cherry picked from commit ed1e5f5) Co-authored-by: ruzniaievdm <[email protected]>
- Loading branch information
1 parent
2a93834
commit 98a0bf2
Showing
8 changed files
with
707 additions
and
173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
cms/djangoapps/contentstore/rest_api/v1/tests/test_course_details.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
""" | ||
Unit tests for course details views. | ||
""" | ||
import json | ||
from unittest.mock import patch | ||
|
||
import ddt | ||
from django.urls import reverse | ||
from rest_framework import status | ||
|
||
from cms.djangoapps.contentstore.tests.utils import CourseTestCase | ||
|
||
from ..mixins import PermissionAccessMixin | ||
|
||
|
||
@ddt.ddt | ||
class CourseDetailsViewTest(CourseTestCase, PermissionAccessMixin): | ||
""" | ||
Tests for CourseDetailsView. | ||
""" | ||
|
||
def setUp(self): | ||
super().setUp() | ||
self.url = reverse( | ||
'cms.djangoapps.contentstore:v1:course_details', | ||
kwargs={"course_id": self.course.id}, | ||
) | ||
|
||
def test_put_permissions_unauthenticated(self): | ||
""" | ||
Test that an error is returned in the absence of auth credentials. | ||
""" | ||
self.client.logout() | ||
response = self.client.put(self.url) | ||
error = self.get_and_check_developer_response(response) | ||
self.assertEqual(error, "Authentication credentials were not provided.") | ||
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED) | ||
|
||
def test_put_permissions_unauthorized(self): | ||
""" | ||
Test that an error is returned if the user is unauthorised. | ||
""" | ||
client, _ = self.create_non_staff_authed_user_client() | ||
response = client.put(self.url) | ||
error = self.get_and_check_developer_response(response) | ||
self.assertEqual(error, "You do not have permission to perform this action.") | ||
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) | ||
|
||
@patch.dict("django.conf.settings.FEATURES", {'ENABLE_PREREQUISITE_COURSES': True}) | ||
def test_put_invalid_pre_requisite_course(self): | ||
pre_requisite_course_keys = [str(self.course.id), 'invalid_key'] | ||
request_data = {"pre_requisite_courses": pre_requisite_course_keys} | ||
response = self.client.put(path=self.url, data=json.dumps(request_data), content_type="application/json") | ||
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) | ||
self.assertEqual(response.json()['error'], 'Invalid prerequisite course key') | ||
|
||
def test_put_course_details(self): | ||
request_data = { | ||
"about_sidebar_html": "", | ||
"banner_image_name": "images_course_image.jpg", | ||
"banner_image_asset_path": "/asset-v1:edX+E2E-101+course+type@asset+block@images_course_image.jpg", | ||
"certificate_available_date": "2029-01-02T00:00:00Z", | ||
"certificates_display_behavior": "end", | ||
"course_id": "E2E-101", | ||
"course_image_asset_path": "/static/studio/images/pencils.jpg", | ||
"course_image_name": "bar_course_image_name", | ||
"description": "foo_description", | ||
"duration": "", | ||
"effort": None, | ||
"end_date": "2023-08-01T01:30:00Z", | ||
"enrollment_end": "2023-05-30T01:00:00Z", | ||
"enrollment_start": "2023-05-29T01:00:00Z", | ||
"entrance_exam_enabled": "", | ||
"entrance_exam_id": "", | ||
"entrance_exam_minimum_score_pct": "50", | ||
"intro_video": None, | ||
"language": "creative-commons: ver=4.0 BY NC ND", | ||
"learning_info": [ | ||
"foo", | ||
"bar" | ||
], | ||
"license": "creative-commons: ver=4.0 BY NC ND", | ||
"org": "edX", | ||
"overview": "<section class=\"about\"></section>", | ||
"pre_requisite_courses": [], | ||
"run": "course", | ||
"self_paced": None, | ||
"short_description": "", | ||
"start_date": "2023-06-01T01:30:00Z", | ||
"subtitle": "", | ||
"syllabus": None, | ||
"title": "", | ||
"video_thumbnail_image_asset_path": "/asset-v1:edX+E2E-101+course+type@asset+block@images_course_image.jpg", | ||
"video_thumbnail_image_name": "images_course_image.jpg", | ||
"instructor_info": { | ||
"instructors": [ | ||
{ | ||
"name": "foo bar", | ||
"title": "title", | ||
"organization": "org", | ||
"image": "image", | ||
"bio": "" | ||
} | ||
] | ||
}, | ||
} | ||
response = self.client.put(path=self.url, data=json.dumps(request_data), content_type="application/json") | ||
self.assertEqual(response.status_code, status.HTTP_200_OK) |
80 changes: 80 additions & 0 deletions
80
cms/djangoapps/contentstore/rest_api/v1/tests/test_settings.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
""" | ||
Unit tests for course settings views. | ||
""" | ||
import ddt | ||
from django.conf import settings | ||
from django.urls import reverse | ||
from mock import patch | ||
from rest_framework import status | ||
|
||
from cms.djangoapps.contentstore.tests.utils import CourseTestCase | ||
from cms.djangoapps.contentstore.utils import get_proctored_exam_settings_url | ||
from common.djangoapps.util.course import get_link_for_about_page | ||
from openedx.core.djangoapps.credit.tests.factories import CreditCourseFactory | ||
|
||
from ..mixins import PermissionAccessMixin | ||
|
||
|
||
@ddt.ddt | ||
class CourseSettingsViewTest(CourseTestCase, PermissionAccessMixin): | ||
""" | ||
Tests for CourseSettingsView. | ||
""" | ||
|
||
def setUp(self): | ||
super().setUp() | ||
self.url = reverse( | ||
'cms.djangoapps.contentstore:v1:course_settings', | ||
kwargs={"course_id": self.course.id}, | ||
) | ||
|
||
def test_course_settings_response(self): | ||
""" Check successful response content """ | ||
response = self.client.get(self.url) | ||
expected_response = { | ||
'about_page_editable': True, | ||
'can_show_certificate_available_date_field': False, | ||
'course_display_name': self.course.display_name, | ||
'course_display_name_with_default': self.course.display_name_with_default, | ||
'credit_eligibility_enabled': True, | ||
'enrollment_end_editable': True, | ||
'enable_extended_course_details': False, | ||
'is_credit_course': False, | ||
'is_entrance_exams_enabled': True, | ||
'is_prerequisite_courses_enabled': False, | ||
'language_options': settings.ALL_LANGUAGES, | ||
'lms_link_for_about_page': get_link_for_about_page(self.course), | ||
'marketing_enabled': False, | ||
'mfe_proctored_exam_settings_url': get_proctored_exam_settings_url(self.course.id), | ||
'short_description_editable': True, | ||
'sidebar_html_enabled': False, | ||
'show_min_grade_warning': False, | ||
'upgrade_deadline': None, | ||
'use_v2_cert_display_settings': False, | ||
} | ||
|
||
self.assertEqual(response.status_code, status.HTTP_200_OK) | ||
self.assertDictEqual(expected_response, response.data) | ||
|
||
@patch.dict('django.conf.settings.FEATURES', {'ENABLE_CREDIT_ELIGIBILITY': True}) | ||
def test_credit_eligibility_setting(self): | ||
""" | ||
Make sure if the feature flag is enabled we have updated the dict keys in response. | ||
""" | ||
_ = CreditCourseFactory(course_key=self.course.id, enabled=True) | ||
response = self.client.get(self.url) | ||
self.assertEqual(response.status_code, status.HTTP_200_OK) | ||
self.assertIn('credit_requirements', response.data) | ||
self.assertTrue(response.data['is_credit_course']) | ||
|
||
@patch.dict('django.conf.settings.FEATURES', { | ||
'ENABLE_PREREQUISITE_COURSES': True, | ||
'MILESTONES_APP': True, | ||
}) | ||
def test_prerequisite_courses_enabled_setting(self): | ||
""" | ||
Make sure if the feature flags are enabled we have updated the dict keys in response. | ||
""" | ||
response = self.client.get(self.url) | ||
self.assertIn('possible_pre_requisite_courses', response.data) | ||
self.assertEqual(response.status_code, status.HTTP_200_OK) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.