Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
3c53f16d
Commit
3c53f16d
authored
May 13, 2014
by
chrisndodge
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #46 from edx-solutions/cdodge/fix-updates-parsing
Cdodge/fix updates parsing
parents
d956be1a
6bbe040d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
62 additions
and
3 deletions
+62
-3
lms/djangoapps/api_manager/courses/content.py
+24
-1
lms/djangoapps/api_manager/courses/tests.py
+33
-1
lms/djangoapps/api_manager/courses/views.py
+5
-1
No files found.
lms/djangoapps/api_manager/courses/content.py
View file @
3c53f16d
...
...
@@ -7,10 +7,33 @@ from textwrap import dedent
TEST_COURSE_UPDATES_CONTENT
=
dedent
(
"""
<section>
<article>
<h2>April 18, 2014</h2>
This does not have a paragraph tag around it
</article>
<article>
<h2>April 17, 2014</h2>
Some text before paragraph tag<p>This is inside paragraph tag</p>Some text after tag
</article>
<article>
<h2>April 16, 2014</h2>
Some text before paragraph tag<p>This is inside paragraph tag</p>Some text after tag<p>one more</p>
</article>
<article>
<h2>April 15, 2014</h2>
<p>A perfectly</p><p>formatted piece</p><p>of HTML</p>
</article>
</section>
"""
)
TEST_COURSE_UPDATES_CONTENT_LEGACY
=
dedent
(
"""
<ol>
<li>
<h2>April 18, 2014</h2>
This
does not have a paragraph tag around i
t
This
is some legacy conten
t
</li>
<li>
<h2>April 17, 2014</h2>
...
...
lms/djangoapps/api_manager/courses/tests.py
View file @
3c53f16d
...
...
@@ -15,7 +15,7 @@ from django.test.utils import override_settings
from
courseware.tests.modulestore_config
import
TEST_DATA_MIXED_MODULESTORE
from
xmodule.modulestore.tests.factories
import
CourseFactory
,
ItemFactory
from
.content
import
TEST_COURSE_OVERVIEW_CONTENT
,
TEST_COURSE_UPDATES_CONTENT
from
.content
import
TEST_COURSE_OVERVIEW_CONTENT
,
TEST_COURSE_UPDATES_CONTENT
,
TEST_COURSE_UPDATES_CONTENT_LEGACY
from
.content
import
TEST_STATIC_TAB1_CONTENT
,
TEST_STATIC_TAB2_CONTENT
TEST_API_KEY
=
str
(
uuid
.
uuid4
())
...
...
@@ -560,6 +560,38 @@ class CoursesApiTests(TestCase):
response
=
self
.
do_get
(
test_uri
)
self
.
assertEqual
(
response
.
status_code
,
404
)
def
test_courses_updates_legacy
(
self
):
#try a bogus course_id to test failure case
test_course
=
CourseFactory
.
create
()
ItemFactory
.
create
(
category
=
"course_info"
,
parent_location
=
test_course
.
location
,
data
=
TEST_COURSE_UPDATES_CONTENT_LEGACY
,
display_name
=
"updates"
)
test_uri
=
self
.
base_courses_uri
+
'/'
+
test_course
.
id
+
'/updates'
response
=
self
.
do_get
(
test_uri
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertGreater
(
len
(
response
.
data
),
0
)
self
.
assertEqual
(
response
.
data
[
'content'
],
TEST_COURSE_UPDATES_CONTENT_LEGACY
)
# then try parsed
test_uri
=
self
.
base_courses_uri
+
'/'
+
test_course
.
id
+
'/updates?parse=True'
response
=
self
.
do_get
(
test_uri
)
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertGreater
(
len
(
response
.
data
),
0
)
postings
=
response
.
data
[
'postings'
]
self
.
assertEqual
(
len
(
postings
),
4
)
self
.
assertEqual
(
postings
[
0
][
'date'
],
'April 18, 2014'
)
self
.
assertEqual
(
postings
[
0
][
'content'
],
'This is some legacy content'
)
self
.
assertEqual
(
postings
[
1
][
'date'
],
'April 17, 2014'
)
self
.
assertEqual
(
postings
[
1
][
'content'
],
'Some text before paragraph tag<p>This is inside paragraph tag</p>Some text after tag'
)
self
.
assertEqual
(
postings
[
2
][
'date'
],
'April 16, 2014'
)
self
.
assertEqual
(
postings
[
2
][
'content'
],
'Some text before paragraph tag<p>This is inside paragraph tag</p>Some text after tag<p>one more</p>'
)
self
.
assertEqual
(
postings
[
3
][
'date'
],
'April 15, 2014'
)
self
.
assertEqual
(
postings
[
3
][
'content'
],
'<p>A perfectly</p><p>formatted piece</p><p>of HTML</p>'
)
def
test_static_tab_list_get
(
self
):
test_uri
=
'{}/{}/static_tabs'
.
format
(
self
.
base_courses_uri
,
self
.
test_course_id
)
response
=
self
.
do_get
(
test_uri
)
...
...
lms/djangoapps/api_manager/courses/views.py
View file @
3c53f16d
...
...
@@ -224,7 +224,11 @@ def _parse_updates_html(html):
tree
=
etree
.
parse
(
StringIO
(
html
),
parser
)
# get all of the individual postings
postings
=
tree
.
findall
(
'/body/ol/li'
)
postings
=
tree
.
findall
(
'/body/section/article'
)
# be backwards compatible
if
not
postings
:
postings
=
tree
.
findall
(
'/body/ol/li'
)
result
=
[]
for
posting
in
postings
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment