Skip to content

Commit

Permalink
Merge tag 'open-release/palm.3' of github.com:EduTrigger/edx-platform…
Browse files Browse the repository at this point in the history
… into viceclass-prod
  • Loading branch information
chuan-edutrigger committed Nov 24, 2023
2 parents 8a11cd2 + 176d0d8 commit 256f882
Show file tree
Hide file tree
Showing 18 changed files with 442 additions and 60 deletions.
5 changes: 2 additions & 3 deletions lms/djangoapps/discussion/rest_api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,10 +402,9 @@ def get_unread_comment_count(self, obj):

def get_preview_body(self, obj):
"""
Returns a cleaned and truncated version of the thread's body to display in a
preview capacity.
Returns a cleaned version of the thread's body to display in a preview capacity.
"""
return strip_tags(self.get_rendered_body(obj)).replace('\n', ' ')
return strip_tags(self.get_rendered_body(obj)).replace('\n', ' ').replace(' ', ' ')

def get_close_reason(self, obj):
"""
Expand Down
15 changes: 15 additions & 0 deletions lms/djangoapps/discussion/rest_api/tests/test_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,21 @@ def test_response_count_missing(self):
serialized = self.serialize(thread_data)
assert 'response_count' not in serialized

def test_get_preview_body(self):
"""
Test for the 'get_preview_body' method.
This test verifies that the 'get_preview_body' method returns a cleaned
version of the thread's body that is suitable for display as a preview.
The test specifically focuses on handling the presence of multiple
spaces within the body.
"""
thread_data = self.make_cs_content(
{"body": "<p>This is a test thread body with some text.</p>"}
)
serialized = self.serialize(thread_data)
assert serialized['preview_body'] == "This is a test thread body with some text."


@ddt.ddt
class CommentSerializerTest(SerializerTestMixin, SharedModuleStoreTestCase):
Expand Down
8 changes: 4 additions & 4 deletions lms/templates/wiki/includes/editor_widget.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{% load i18n %}
{% load django_markup %}
<p id="hint_id_content" class="help-block">
{% filter force_escape %}
{% blocktrans with start_link="<a id='cheatsheetLink' href='#cheatsheetModal' rel='leanModal'>" end_link="</a>" trimmed %}
Markdown syntax is allowed. See the {{ start_link }}cheatsheet{{ end_link }} for help.
{% blocktrans trimmed asvar tmsg %}
Markdown syntax is allowed. See the {start_link}cheatsheet{end_link} for help.
{% endblocktrans %}
{% endfilter %}
{% interpolate_html tmsg start_link='<a id="cheatsheetLink" href="#cheatsheetModal" rel="leanModal">'|safe end_link='</a>'|safe %}
</p>
<textarea {{ attrs }}>{{ content }}</textarea>
53 changes: 32 additions & 21 deletions openedx/core/djangoapps/models/tests/test_course_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@


import datetime
from django.test import override_settings
import pytest
import ddt
from pytz import UTC
Expand All @@ -29,27 +30,37 @@ class CourseDetailsTestCase(ModuleStoreTestCase):

def setUp(self):
super().setUp()
self.course = CourseFactory.create()

def test_virgin_fetch(self):
details = CourseDetails.fetch(self.course.id)
assert details.org == self.course.location.org, 'Org not copied into'
assert details.course_id == self.course.location.course, 'Course_id not copied into'
assert details.run == self.course.location.run, 'Course run not copied into'
assert details.course_image_name == self.course.course_image
assert details.start_date.tzinfo is not None
assert details.end_date is None, ('end date somehow initialized ' + str(details.end_date))
assert details.enrollment_start is None,\
('enrollment_start date somehow initialized ' + str(details.enrollment_start))
assert details.enrollment_end is None,\
('enrollment_end date somehow initialized ' + str(details.enrollment_end))
assert details.certificate_available_date is None,\
('certificate_available_date date somehow initialized ' + str(details.certificate_available_date))
assert details.syllabus is None, ('syllabus somehow initialized' + str(details.syllabus))
assert details.intro_video is None, ('intro_video somehow initialized' + str(details.intro_video))
assert details.effort is None, ('effort somehow initialized' + str(details.effort))
assert details.language is None, ('language somehow initialized' + str(details.language))
assert not details.self_paced
self.course = CourseFactory.create(default_enrollment_start=True)

@ddt.data(True, False)
def test_virgin_fetch(self, should_have_default_enroll_start):
features = settings.FEATURES.copy()
features['CREATE_COURSE_WITH_DEFAULT_ENROLLMENT_START_DATE'] = should_have_default_enroll_start

with override_settings(FEATURES=features):
course = CourseFactory.create(default_enrollment_start=should_have_default_enroll_start)
details = CourseDetails.fetch(course.id)
wrong_enrollment_start_msg = (
'enrollment_start not copied into'
if should_have_default_enroll_start
else f'enrollment_start date somehow initialized {str(details.enrollment_start)}'
)
assert details.org == course.location.org, 'Org not copied into'
assert details.course_id == course.location.course, 'Course_id not copied into'
assert details.run == course.location.run, 'Course run not copied into'
assert details.course_image_name == course.course_image
assert details.start_date.tzinfo is not None
assert details.end_date is None, ('end date somehow initialized ' + str(details.end_date))
assert details.enrollment_start == course.enrollment_start, wrong_enrollment_start_msg
assert details.enrollment_end is None,\
('enrollment_end date somehow initialized ' + str(details.enrollment_end))
assert details.certificate_available_date is None,\
('certificate_available_date date somehow initialized ' + str(details.certificate_available_date))
assert details.syllabus is None, ('syllabus somehow initialized' + str(details.syllabus))
assert details.intro_video is None, ('intro_video somehow initialized' + str(details.intro_video))
assert details.effort is None, ('effort somehow initialized' + str(details.effort))
assert details.language is None, ('language somehow initialized' + str(details.language))
assert not details.self_paced

def test_update_and_fetch(self):
jsondetails = CourseDetails.fetch(self.course.id)
Expand Down
141 changes: 141 additions & 0 deletions openedx/core/djangoapps/user_authn/api/tests/test_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
""" Mocked data for testing """

mfe_context_data_keys = {
'contextData',
'registrationFields',
'optionalFields'
}

mock_mfe_context_data = {
'context_data': {
'currentProvider': 'edX',
'platformName': 'edX',
'providers': [
{
'id': 'oa2-facebook',
'name': 'Facebook',
'iconClass': 'fa-facebook',
'iconImage': None,
'skipHintedLogin': False,
'skipRegistrationForm': False,
'loginUrl': 'https://facebook.com/login',
'registerUrl': 'https://facebook.com/register'
},
{
'id': 'oa2-google-oauth2',
'name': 'Google',
'iconClass': 'fa-google-plus',
'iconImage': None,
'skipHintedLogin': False,
'skipRegistrationForm': False,
'loginUrl': 'https://google.com/login',
'registerUrl': 'https://google.com/register'
}
],
'secondaryProviders': [],
'finishAuthUrl': 'https://edx.com/auth/finish',
'errorMessage': None,
'registerFormSubmitButtonText': 'Create Account',
'autoSubmitRegForm': False,
'syncLearnerProfileData': False,
'countryCode': '',
'pipeline_user_details': {
'username': 'test123',
'email': '[email protected]',
'fullname': 'Test Test',
'first_name': 'Test',
'last_name': 'Test'
}
},
'registration_fields': {},
'optional_fields': {
'extended_profile': []
}
}

mock_default_mfe_context_data = {
'context_data': {
'currentProvider': None,
'platformName': 'édX',
'providers': [],
'secondaryProviders': [],
'finishAuthUrl': None,
'errorMessage': None,
'registerFormSubmitButtonText': 'Create Account',
'autoSubmitRegForm': False,
'syncLearnerProfileData': False,
'countryCode': '',
'pipeline_user_details': {}
},
'registration_fields': {},
'optional_fields': {
'extended_profile': []
}
}

expected_mfe_context_data = {
'contextData': {
'currentProvider': 'edX',
'platformName': 'edX',
'providers': [
{
'id': 'oa2-facebook',
'name': 'Facebook',
'iconClass': 'fa-facebook',
'iconImage': None,
'skipHintedLogin': False,
'skipRegistrationForm': False,
'loginUrl': 'https://facebook.com/login',
'registerUrl': 'https://facebook.com/register'
},
{
'id': 'oa2-google-oauth2',
'name': 'Google',
'iconClass': 'fa-google-plus',
'iconImage': None,
'skipHintedLogin': False,
'skipRegistrationForm': False,
'loginUrl': 'https://google.com/login',
'registerUrl': 'https://google.com/register'
}
],
'secondaryProviders': [],
'finishAuthUrl': 'https://edx.com/auth/finish',
'errorMessage': None,
'registerFormSubmitButtonText': 'Create Account',
'autoSubmitRegForm': False,
'syncLearnerProfileData': False,
'countryCode': '',
'pipelineUserDetails': {
'username': 'test123',
'email': '[email protected]',
'name': 'Test Test',
'firstName': 'Test',
'lastName': 'Test'
}
},
'registrationFields': {},
'optionalFields': {
'extended_profile': []
}
}

default_expected_mfe_context_data = {
'contextData': {
'currentProvider': None,
'platformName': 'édX',
'providers': [],
'secondaryProviders': [],
'finishAuthUrl': None,
'errorMessage': None,
'registerFormSubmitButtonText': 'Create Account',
'autoSubmitRegForm': False,
'syncLearnerProfileData': False,
'countryCode': '',
'pipelineUserDetails': {}
},
'registrationFields': {},
'optionalFields': {
'extended_profile': []
}
}
44 changes: 44 additions & 0 deletions openedx/core/djangoapps/user_authn/api/tests/test_serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
"""Tests for serializers for the MFE Context"""

from django.test import TestCase

from openedx.core.djangoapps.user_authn.api.tests.test_data import (
mock_mfe_context_data,
expected_mfe_context_data,
mock_default_mfe_context_data,
default_expected_mfe_context_data,
)
from openedx.core.djangoapps.user_authn.serializers import MFEContextSerializer


class TestMFEContextSerializer(TestCase):
"""
High-level unit tests for MFEContextSerializer
"""

def test_mfe_context_serializer(self):
"""
Test MFEContextSerializer with mock data that serializes data correctly
"""

output_data = MFEContextSerializer(
mock_mfe_context_data
).data

self.assertDictEqual(
output_data,
expected_mfe_context_data
)

def test_mfe_context_serializer_default_response(self):
"""
Test MFEContextSerializer with default data
"""
serialized_data = MFEContextSerializer(
mock_default_mfe_context_data
).data

self.assertDictEqual(
serialized_data,
default_expected_mfe_context_data
)
Loading

0 comments on commit 256f882

Please sign in to comment.