Commit e92280ac by Chris Dodge Committed by Jonathan Piacenti

tunnel through any attributes needed for the overview API

remove duplicate data
parent 66985ff9
...@@ -107,5 +107,8 @@ TEST_COURSE_OVERVIEW_CONTENT = dedent( ...@@ -107,5 +107,8 @@ TEST_COURSE_OVERVIEW_CONTENT = dedent(
<section class="faq"> <section class="faq">
<p>Some text here</p> <p>Some text here</p>
</section> </section>
<section class="intro-video" data-videoid="foobar">
</section>
""" """
) )
...@@ -548,11 +548,12 @@ class CoursesApiTests(TestCase): ...@@ -548,11 +548,12 @@ class CoursesApiTests(TestCase):
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
self.assertGreater(len(response.data), 0) self.assertGreater(len(response.data), 0)
sections = response.data['sections'] sections = response.data['sections']
self.assertEqual(len(sections), 4) self.assertEqual(len(sections), 5)
self.assertIsNotNone(self._find_item_by_class(sections, 'about')) self.assertIsNotNone(self._find_item_by_class(sections, 'about'))
self.assertIsNotNone(self._find_item_by_class(sections, 'prerequisites')) self.assertIsNotNone(self._find_item_by_class(sections, 'prerequisites'))
self.assertIsNotNone(self._find_item_by_class(sections, 'course-staff')) self.assertIsNotNone(self._find_item_by_class(sections, 'course-staff'))
self.assertIsNotNone(self._find_item_by_class(sections, 'faq')) self.assertIsNotNone(self._find_item_by_class(sections, 'faq'))
self.assertIsNotNone(self._find_item_by_class(sections, 'intro-video'))
course_staff = self._find_item_by_class(sections, 'course-staff') course_staff = self._find_item_by_class(sections, 'course-staff')
staff = course_staff['articles'] staff = course_staff['articles']
...@@ -578,6 +579,10 @@ class CoursesApiTests(TestCase): ...@@ -578,6 +579,10 @@ class CoursesApiTests(TestCase):
invalid_tab = self._find_item_by_class(sections, 'invalid_tab') invalid_tab = self._find_item_by_class(sections, 'invalid_tab')
self.assertFalse(invalid_tab) self.assertFalse(invalid_tab)
intro_video = self._find_item_by_class(sections, 'intro-video')
self.assertEqual(len(intro_video['attributes']), 1)
self.assertEqual(intro_video['attributes']['data-videoid'], 'foobar')
def test_courses_overview_get_invalid_course(self): def test_courses_overview_get_invalid_course(self):
#try a bogus course_id to test failure case #try a bogus course_id to test failure case
test_uri = '{}/{}/overview'.format(self.base_courses_uri, self.test_bogus_course_id) test_uri = '{}/{}/overview'.format(self.base_courses_uri, self.test_bogus_course_id)
......
...@@ -173,6 +173,13 @@ def _parse_overview_html(html): ...@@ -173,6 +173,13 @@ def _parse_overview_html(html):
section_data = OrderedDict() section_data = OrderedDict()
section_data['class'] = section_class section_data['class'] = section_class
section_data['attributes'] = {}
for attribute_key in section.keys():
# don't return the class attribute as we are already using the class attribute
# as a key name to the result set, so we don't want to end up duplicating it
if attribute_key != 'class':
section_data['attributes'][attribute_key] = section.get(attribute_key)
articles = section.findall('article') articles = section.findall('article')
if articles: if articles:
section_data['articles'] = [] section_data['articles'] = []
......
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