Skip to content

Commit

Permalink
fix: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
NiedielnitsevIvan committed Apr 11, 2024
1 parent 8dab7a2 commit 8663cc2
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 7 deletions.
53 changes: 53 additions & 0 deletions cms/djangoapps/contentstore/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2234,3 +2234,56 @@ def send_course_update_notification(course_key, content, user):
audience_filters={},
)
COURSE_NOTIFICATION_REQUESTED.send_event(course_notification_data=notification_data)


def get_xblock_validation_messages(xblock):
"""
Retrieves validation messages for a given xblock.
Args:
xblock: The xblock object to validate.
Returns:
list: A list of validation error messages.
"""
validation_json = xblock.validate().to_json()
return validation_json['messages']


def get_xblock_render_error(request, xblock):
"""
Checks if there are any rendering errors for a given block and return these.
Args:
request: WSGI request object
xblock: The xblock object to rendering.
Returns:
str: Error message which happened while rendering of xblock.
"""
from cms.djangoapps.contentstore.views.preview import _load_preview_block
from xmodule.studio_editable import has_author_view
from xmodule.x_module import AUTHOR_VIEW, STUDENT_VIEW

def get_xblock_render_context(request, block):
"""
Return a dict of the data needs for render of each block.
"""
can_edit = has_studio_write_access(request.user, block.usage_key.course_key)

return {
"is_unit_page": False,
"can_edit": can_edit,
"root_xblock": xblock,
"reorderable_items": set(),
"paging": None,
"force_render": None,
"item_url": "/container/{block.location}",
"tags_count_map": {},
}

try:
block = _load_preview_block(request, xblock)
preview_view = AUTHOR_VIEW if has_author_view(block) else STUDENT_VIEW
render_context = get_xblock_render_context(request, block)
block.render(preview_view, render_context)
except Exception as exc: # pylint: disable=broad-except
return str(exc)

return ""
14 changes: 7 additions & 7 deletions lms/djangoapps/course_home_api/outline/tests/test_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ def __init__(self, *args, **kwargs):

def setUp(self):
super().setUp()
self.url = reverse('course-home:course-sidebar-blocks', args=[self.course.id])
self.url = reverse('course-home:course-navigation', args=[self.course.id])

def update_course_and_overview(self):
"""
Expand Down Expand Up @@ -573,7 +573,7 @@ def test_get_unknown_course(self):
"""
Test that the API returns a 404 when the course is not found.
"""
url = reverse('course-home:course-sidebar-blocks', args=['course-v1:unknown+course+2T2020'])
url = reverse('course-home:course-navigation', args=['course-v1:unknown+course+2T2020'])
response = self.client.get(url)
assert response.status_code == 404

Expand Down Expand Up @@ -624,7 +624,7 @@ def test_proctored_exam(self, mock_summary):
'suggested_icon': 'fa-foo-bar',
}

url = reverse('course-home:course-sidebar-blocks', args=[course.id])
url = reverse('course-home:course-navigation', args=[course.id])
response = self.client.get(url)
assert response.status_code == 200

Expand Down Expand Up @@ -715,7 +715,7 @@ def test_empty_blocks_complete(self):
"""
self.add_blocks_to_course()
CourseEnrollment.enroll(self.user, self.course.id)
url = reverse('course-home:course-sidebar-blocks', args=[self.course.id])
url = reverse('course-home:course-navigation', args=[self.course.id])
response = self.client.get(url)
assert response.status_code == 200

Expand All @@ -731,7 +731,7 @@ def test_blocks_complete_with_problem(self, problem_complete):
CourseEnrollment.enroll(self.user, self.course.id)
self.create_completion(problem, int(problem_complete))

response = self.client.get(reverse('course-home:course-sidebar-blocks', args=[self.course.id]))
response = self.client.get(reverse('course-home:course-navigation', args=[self.course.id]))

sequence_data = response.data['blocks'][str(self.sequential.location)]
vertical_data = response.data['blocks'][str(self.vertical.location)]
Expand All @@ -750,7 +750,7 @@ def test_blocks_completion_stat(self):
CourseEnrollment.enroll(self.user, self.course.id)
self.create_completion(completed_problem, 1)
self.create_completion(uncompleted_problem, 0)
response = self.client.get(reverse('course-home:course-sidebar-blocks', args=[self.course.id]))
response = self.client.get(reverse('course-home:course-navigation', args=[self.course.id]))

expected_sequence_completion_stat = {
'completion': 0,
Expand Down Expand Up @@ -779,7 +779,7 @@ def test_blocks_completion_stat_all_problem_completed(self):
CourseEnrollment.enroll(self.user, self.course.id)
self.create_completion(problem1, 1)
self.create_completion(problem2, 1)
response = self.client.get(reverse('course-home:course-sidebar-blocks', args=[self.course.id]))
response = self.client.get(reverse('course-home:course-navigation', args=[self.course.id]))

expected_sequence_completion_stat = {
'completion': 1,
Expand Down

0 comments on commit 8663cc2

Please sign in to comment.