Commit 46932ee0 by Ben McMorran

Replace data-test-course and data-test-unsucceeded with data-course-key

parent 0d1669c6
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
import copy import copy
import mock import mock
import shutil import shutil
import lxml
from datetime import timedelta from datetime import timedelta
from fs.osfs import OSFS from fs.osfs import OSFS
...@@ -1585,31 +1586,31 @@ class RerunCourseTest(ContentStoreTestCase): ...@@ -1585,31 +1586,31 @@ class RerunCourseTest(ContentStoreTestCase):
destination_course_key = CourseKey.from_string(json_resp['destination_course_key']) destination_course_key = CourseKey.from_string(json_resp['destination_course_key'])
return destination_course_key return destination_course_key
def create_course_listing_html(self, course_key): def get_course_listing_elements(self, html, course_key):
"""Creates html fragment that is created for the given course_key in the course listing section""" """Returns the elements in the course listing section of html that have the given course_key"""
return 'data-test-course="{}/{}/{}"'.format(course_key.org, course_key.course, course_key.run) return html.cssselect('.course-item[data-course-key="{}"]'.format(unicode(course_key)))
def create_unsucceeded_course_action_html(self, course_key): def get_unsucceeded_course_action_elements(self, html, course_key):
"""Creates html fragment that is created for the given course_key in the unsucceeded course action section""" """Returns the elements in the unsucceeded course action section that have the given course_key"""
return 'data-test-unsucceeded="{}/{}/{}"'.format(course_key.org, course_key.course, course_key.run) return html.cssselect('.courses-processing li[data-course-key="{}"]'.format(unicode(course_key)))
def assertInCourseListing(self, course_key): def assertInCourseListing(self, course_key):
""" """
Asserts that the given course key is in the accessible course listing section of the html 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. and NOT in the unsucceeded course action section of the html.
""" """
course_listing_html = self.client.get_html('/course/') course_listing = lxml.html.fromstring(self.client.get_html('/course/').content)
self.assertIn(self.create_course_listing_html(course_key), course_listing_html.content) self.assertEqual(len(self.get_course_listing_elements(course_listing, course_key)), 1)
self.assertNotIn(self.create_unsucceeded_course_action_html(course_key), course_listing_html.content) self.assertEqual(len(self.get_unsucceeded_course_action_elements(course_listing, course_key)), 0)
def assertInUnsucceededCourseActions(self, course_key): def assertInUnsucceededCourseActions(self, course_key):
""" """
Asserts that the given course key is in the unsucceeded course action section of the html 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. and NOT in the accessible course listing section of the html.
""" """
course_listing_html = self.client.get_html('/course/') course_listing = lxml.html.fromstring(self.client.get_html('/course/').content)
self.assertNotIn(self.create_course_listing_html(course_key), course_listing_html.content) self.assertEqual(len(self.get_course_listing_elements(course_listing, course_key)), 0)
self.assertIn(self.create_unsucceeded_course_action_html(course_key), course_listing_html.content) self.assertEqual(len(self.get_unsucceeded_course_action_elements(course_listing, course_key)), 1)
def test_rerun_course_success(self): def test_rerun_course_success(self):
......
...@@ -353,33 +353,36 @@ def course_listing(request): ...@@ -353,33 +353,36 @@ def course_listing(request):
def format_course_for_view(course): 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 ( return {
course.display_name, 'display_name': course.display_name,
reverse_course_url('course_handler', course.id), 'course_key': unicode(course.location.course_key),
get_lms_link_for_item(course.location), 'url': reverse_course_url('course_handler', course.id),
_get_rerun_link_for_item(course.id), 'lms_link': get_lms_link_for_item(course.location),
course.display_org_with_default, 'rerun_link': _get_rerun_link_for_item(course.id),
course.display_number_with_default, 'org': course.display_org_with_default,
course.location.run 'number': course.display_number_with_default,
) 'run': course.location.run
}
def format_unsucceeded_course_for_view(uca): 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 ( return {
uca.display_name, 'display_name': uca.display_name,
uca.course_key.org, 'course_key': unicode(uca.course_key),
uca.course_key.course, 'org': uca.course_key.org,
uca.course_key.run, 'number': uca.course_key.course,
True if uca.state == CourseRerunUIStateManager.State.FAILED else False, 'run': uca.course_key.run,
True if uca.state == CourseRerunUIStateManager.State.IN_PROGRESS else False, '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={ reverse_course_url('course_notifications_handler', uca.course_key, kwargs={
'action_state_id': uca.id, 'action_state_id': uca.id,
}) if uca.state == CourseRerunUIStateManager.State.FAILED else '' }) if uca.state == CourseRerunUIStateManager.State.FAILED else ''
) }
# remove any courses in courses that are also in the unsucceeded_course_actions list # 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] unsucceeded_action_course_keys = [uca.course_key for uca in unsucceeded_course_actions]
......
...@@ -137,24 +137,24 @@ require(["domReady!", "jquery", "jquery.form", "js/index"], function(doc, $) { ...@@ -137,24 +137,24 @@ require(["domReady!", "jquery", "jquery.form", "js/index"], function(doc, $) {
<h3 class="title">Courses Being Processed</h3> <h3 class="title">Courses Being Processed</h3>
<ul class="list-courses"> <ul class="list-courses">
%for display_name, org, num, run, state_failed, state_in_progress, dismiss_link in sorted(unsucceeded_course_actions, key=lambda s: s[0].lower() if s[0] is not None else ''): %for course_info in sorted(unsucceeded_course_actions, key=lambda s: s['display_name'].lower() if s['display_name'] is not None else ''):
<!-- STATE: re-run is processing --> <!-- STATE: re-run is processing -->
%if state_in_progress: %if course_info['is_in_progress']:
<li class="wrapper-course has-status" data-test-unsucceeded="${org}/${num}/${run}"> <li class="wrapper-course has-status" data-course-key="${course_info['course_key']}">
<div class="course-item course-rerun is-processing"> <div class="course-item course-rerun is-processing">
<div class="course-details" href="#"> <div class="course-details" href="#">
<h3 class="course-title">${display_name}</h3> <h3 class="course-title">${course_info['display_name']}</h3>
<div class="course-metadata"> <div class="course-metadata">
<span class="course-org metadata-item"> <span class="course-org metadata-item">
<span class="label">${_("Organization:")}</span> <span class="value">${org}</span> <span class="label">${_("Organization:")}</span> <span class="value">${course_info['org']}</span>
</span> </span>
<span class="course-num metadata-item"> <span class="course-num metadata-item">
<span class="label">${_("Course Number:")}</span> <span class="label">${_("Course Number:")}</span>
<span class="value">${num}</span> <span class="value">${course_info['number']}</span>
</span> </span>
<span class="course-run metadata-item"> <span class="course-run metadata-item">
<span class="label">${_("Course Run:")}</span> <span class="value">${run}</span> <span class="label">${_("Course Run:")}</span> <span class="value">${course_info['run']}</span>
</span> </span>
</div> </div>
</div> </div>
...@@ -177,22 +177,22 @@ require(["domReady!", "jquery", "jquery.form", "js/index"], function(doc, $) { ...@@ -177,22 +177,22 @@ require(["domReady!", "jquery", "jquery.form", "js/index"], function(doc, $) {
<!-- - - - --> <!-- - - - -->
<!-- STATE: re-run has error --> <!-- STATE: re-run has error -->
%if state_failed: %if course_info['is_failed']:
<li class="wrapper-course has-status" data-test-unsucceeded="${org}/${num}/${run}"> <li class="wrapper-course has-status" data-course-key="${course_info['course_key']}">
<div class="course-item course-rerun has-error"> <div class="course-item course-rerun has-error">
<div class="course-details" href="#"> <div class="course-details" href="#">
<h3 class="course-title">${display_name}</h3> <h3 class="course-title">${course_info['display_name']}</h3>
<div class="course-metadata"> <div class="course-metadata">
<span class="course-org metadata-item"> <span class="course-org metadata-item">
<span class="label">${_("Organization:")}</span> <span class="value">${org}</span> <span class="label">${_("Organization:")}</span> <span class="value">${course_info['org']}</span>
</span> </span>
<span class="course-num metadata-item"> <span class="course-num metadata-item">
<span class="label">${_("Course Number:")}</span> <span class="label">${_("Course Number:")}</span>
<span class="value">${num}</span> <span class="value">${course_info['number']}</span>
</span> </span>
<span class="course-run metadata-item"> <span class="course-run metadata-item">
<span class="label">${_("Course Run:")}</span> <span class="value">${run}</span> <span class="label">${_("Course Run:")}</span> <span class="value">${course_info['run']}</span>
</span> </span>
</div> </div>
</div> </div>
...@@ -211,7 +211,7 @@ require(["domReady!", "jquery", "jquery.form", "js/index"], function(doc, $) { ...@@ -211,7 +211,7 @@ require(["domReady!", "jquery", "jquery.form", "js/index"], function(doc, $) {
<ul class="status-actions"> <ul class="status-actions">
<li class="action action-dismiss"> <li class="action action-dismiss">
<a href="#" class="button dismiss-button" data-dismiss-link="${dismiss_link}"> <a href="#" class="button dismiss-button" data-dismiss-link="${course_info['dismiss_link']}">
<i class="icon icon-remove-sign"></i> <i class="icon icon-remove-sign"></i>
<span class="button-copy">${_("Dismiss")}</span> <span class="button-copy">${_("Dismiss")}</span>
</a> </a>
...@@ -228,21 +228,21 @@ require(["domReady!", "jquery", "jquery.form", "js/index"], function(doc, $) { ...@@ -228,21 +228,21 @@ require(["domReady!", "jquery", "jquery.form", "js/index"], function(doc, $) {
%if len(courses) > 0: %if len(courses) > 0:
<div class="courses"> <div class="courses">
<ul class="list-courses"> <ul class="list-courses">
%for course, url, lms_link, rerun_link, org, num, run in sorted(courses, key=lambda s: s[0].lower() if s[0] is not None else ''): %for course_info in sorted(courses, key=lambda s: s['display_name'].lower() if s['display_name'] is not None else ''):
<li class="course-item" data-test-course="${org}/${num}/${run}"> <li class="course-item" data-course-key="${course_info['course_key']}">
<a class="course-link" href="${url}"> <a class="course-link" href="${course_info['url']}">
<h3 class="course-title">${course}</h3> <h3 class="course-title">${course_info['display_name']}</h3>
<div class="course-metadata"> <div class="course-metadata">
<span class="course-org metadata-item"> <span class="course-org metadata-item">
<span class="label">${_("Organization:")}</span> <span class="value">${org}</span> <span class="label">${_("Organization:")}</span> <span class="value">${course_info['org']}</span>
</span> </span>
<span class="course-num metadata-item"> <span class="course-num metadata-item">
<span class="label">${_("Course Number:")}</span> <span class="label">${_("Course Number:")}</span>
<span class="value">${num}</span> <span class="value">${course_info['number']}</span>
</span> </span>
<span class="course-run metadata-item"> <span class="course-run metadata-item">
<span class="label">${_("Course Run:")}</span> <span class="value">${run}</span> <span class="label">${_("Course Run:")}</span> <span class="value">${course_info['run']}</span>
</span> </span>
</div> </div>
</a> </a>
...@@ -250,11 +250,11 @@ require(["domReady!", "jquery", "jquery.form", "js/index"], function(doc, $) { ...@@ -250,11 +250,11 @@ require(["domReady!", "jquery", "jquery.form", "js/index"], function(doc, $) {
<ul class="item-actions course-actions"> <ul class="item-actions course-actions">
% if allow_course_reruns and rerun_creator_status and course_creator_status=='granted': % if allow_course_reruns and rerun_creator_status and course_creator_status=='granted':
<li class="action action-rerun"> <li class="action action-rerun">
<a href="${rerun_link}" class="button rerun-button">${_("Re-run Course")}</a> <a href="${course_info['rerun_link']}" class="button rerun-button">${_("Re-run Course")}</a>
</li> </li>
% endif % endif
<li class="action action-view"> <li class="action action-view">
<a href="${lms_link}" rel="external" class="button view-button">${_("View Live")}</a> <a href="${course_info['lms_link']}" rel="external" class="button view-button">${_("View Live")}</a>
</li> </li>
</ul> </ul>
</li> </li>
......
...@@ -10,6 +10,7 @@ bleach==1.4 ...@@ -10,6 +10,7 @@ bleach==1.4
html5lib==0.999 html5lib==0.999
boto==2.13.3 boto==2.13.3
celery==3.0.19 celery==3.0.19
cssselect==0.9.1
dealer==0.2.3 dealer==0.2.3
distribute>=0.6.28, <0.7 distribute>=0.6.28, <0.7
django-babel-underscore==0.1.0 django-babel-underscore==0.1.0
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment