From 46932ee0f91fc43c7f1bb7266b6aa9af5473977b Mon Sep 17 00:00:00 2001 From: Ben McMorran Date: Mon, 18 Aug 2014 17:20:41 -0400 Subject: [PATCH] Replace data-test-course and data-test-unsucceeded with data-course-key --- .../contentstore/tests/test_contentstore.py | 25 +++++----- cms/djangoapps/contentstore/views/course.py | 47 ++++++++++--------- cms/templates/index.html | 46 +++++++++--------- requirements/edx/base.txt | 1 + 4 files changed, 62 insertions(+), 57 deletions(-) diff --git a/cms/djangoapps/contentstore/tests/test_contentstore.py b/cms/djangoapps/contentstore/tests/test_contentstore.py index c5b72868ea..946500e299 100644 --- a/cms/djangoapps/contentstore/tests/test_contentstore.py +++ b/cms/djangoapps/contentstore/tests/test_contentstore.py @@ -5,6 +5,7 @@ import copy import mock import shutil +import lxml from datetime import timedelta from fs.osfs import OSFS @@ -1585,31 +1586,31 @@ class RerunCourseTest(ContentStoreTestCase): destination_course_key = CourseKey.from_string(json_resp['destination_course_key']) return destination_course_key - def create_course_listing_html(self, course_key): - """Creates html fragment that is created for the given course_key in the course listing section""" - return 'data-test-course="{}/{}/{}"'.format(course_key.org, course_key.course, course_key.run) + def get_course_listing_elements(self, html, course_key): + """Returns the elements in the course listing section of html that have the given course_key""" + return html.cssselect('.course-item[data-course-key="{}"]'.format(unicode(course_key))) - def create_unsucceeded_course_action_html(self, course_key): - """Creates html fragment that is created for the given course_key in the unsucceeded course action section""" - return 'data-test-unsucceeded="{}/{}/{}"'.format(course_key.org, course_key.course, course_key.run) + def get_unsucceeded_course_action_elements(self, html, course_key): + """Returns the elements in the unsucceeded course action section that have the given course_key""" + return html.cssselect('.courses-processing li[data-course-key="{}"]'.format(unicode(course_key))) def assertInCourseListing(self, course_key): """ Asserts that the given course key is in the accessible course listing section of the html and NOT in the unsucceeded course action section of the html. """ - course_listing_html = self.client.get_html('/course/') - self.assertIn(self.create_course_listing_html(course_key), course_listing_html.content) - self.assertNotIn(self.create_unsucceeded_course_action_html(course_key), course_listing_html.content) + course_listing = lxml.html.fromstring(self.client.get_html('/course/').content) + self.assertEqual(len(self.get_course_listing_elements(course_listing, course_key)), 1) + self.assertEqual(len(self.get_unsucceeded_course_action_elements(course_listing, course_key)), 0) def assertInUnsucceededCourseActions(self, course_key): """ Asserts that the given course key is in the unsucceeded course action section of the html and NOT in the accessible course listing section of the html. """ - course_listing_html = self.client.get_html('/course/') - self.assertNotIn(self.create_course_listing_html(course_key), course_listing_html.content) - self.assertIn(self.create_unsucceeded_course_action_html(course_key), course_listing_html.content) + course_listing = lxml.html.fromstring(self.client.get_html('/course/').content) + self.assertEqual(len(self.get_course_listing_elements(course_listing, course_key)), 0) + self.assertEqual(len(self.get_unsucceeded_course_action_elements(course_listing, course_key)), 1) def test_rerun_course_success(self): diff --git a/cms/djangoapps/contentstore/views/course.py b/cms/djangoapps/contentstore/views/course.py index 0443f92827..33f083a020 100644 --- a/cms/djangoapps/contentstore/views/course.py +++ b/cms/djangoapps/contentstore/views/course.py @@ -353,33 +353,36 @@ def course_listing(request): def format_course_for_view(course): """ - return tuple of the data which the view requires for each course + Return a dict of the data which the view requires for each course """ - return ( - course.display_name, - reverse_course_url('course_handler', course.id), - get_lms_link_for_item(course.location), - _get_rerun_link_for_item(course.id), - course.display_org_with_default, - course.display_number_with_default, - course.location.run - ) + return { + 'display_name': course.display_name, + 'course_key': unicode(course.location.course_key), + 'url': reverse_course_url('course_handler', course.id), + 'lms_link': get_lms_link_for_item(course.location), + 'rerun_link': _get_rerun_link_for_item(course.id), + 'org': course.display_org_with_default, + 'number': course.display_number_with_default, + 'run': course.location.run + } def format_unsucceeded_course_for_view(uca): """ - return tuple of the data which the view requires for each unsucceeded course + Return a dict of the data which the view requires for each unsucceeded course """ - return ( - uca.display_name, - uca.course_key.org, - uca.course_key.course, - uca.course_key.run, - True if uca.state == CourseRerunUIStateManager.State.FAILED else False, - True if uca.state == CourseRerunUIStateManager.State.IN_PROGRESS else False, - reverse_course_url('course_notifications_handler', uca.course_key, kwargs={ - 'action_state_id': uca.id, - }) if uca.state == CourseRerunUIStateManager.State.FAILED else '' - ) + return { + 'display_name': uca.display_name, + 'course_key': unicode(uca.course_key), + 'org': uca.course_key.org, + 'number': uca.course_key.course, + 'run': uca.course_key.run, + 'is_failed': True if uca.state == CourseRerunUIStateManager.State.FAILED else False, + 'is_in_progress': True if uca.state == CourseRerunUIStateManager.State.IN_PROGRESS else False, + 'dismiss_link': + reverse_course_url('course_notifications_handler', uca.course_key, kwargs={ + 'action_state_id': uca.id, + }) if uca.state == CourseRerunUIStateManager.State.FAILED else '' + } # remove any courses in courses that are also in the unsucceeded_course_actions list unsucceeded_action_course_keys = [uca.course_key for uca in unsucceeded_course_actions] diff --git a/cms/templates/index.html b/cms/templates/index.html index b89d8c75fe..72b384f4bf 100644 --- a/cms/templates/index.html +++ b/cms/templates/index.html @@ -137,24 +137,24 @@ require(["domReady!", "jquery", "jquery.form", "js/index"], function(doc, $) {

Courses Being Processed