Fix failing tests
This commit is contained in:
@@ -128,7 +128,7 @@ class ContainerViewTestCase(CourseTestCase):
|
||||
"""
|
||||
Verify that the specified xblock has the expected HTML elements for container preview
|
||||
"""
|
||||
locator = loc_mapper().translate_location(self.course.id, xblock.location, published=False)
|
||||
locator = loc_mapper().translate_location(xblock.location, published=False)
|
||||
publish_state = compute_publish_state(xblock)
|
||||
preview_url = '/xblock/{locator}/container_preview'.format(locator=locator)
|
||||
|
||||
|
||||
@@ -178,8 +178,8 @@ class TabsPageTests(CourseTestCase):
|
||||
"""
|
||||
Verify that the static tab renders itself with the correct HTML
|
||||
"""
|
||||
locator = loc_mapper().translate_location(self.course.id, self.test_tab.location)
|
||||
preview_url = '/xblock/{locator}/student_view'.format(locator=locator)
|
||||
locator = loc_mapper().translate_location(self.test_tab.location)
|
||||
preview_url = '/xblock/{locator}/student_view'.format(locator=unicode(locator))
|
||||
|
||||
resp = self.client.get(preview_url, HTTP_ACCEPT='application/json')
|
||||
self.assertEqual(resp.status_code, 200)
|
||||
|
||||
@@ -381,11 +381,9 @@ class SSLClientTest(ModuleStoreTestCase):
|
||||
user = User.objects.get(email=self.USER_EMAIL)
|
||||
CourseEnrollment.enroll(user, course.id)
|
||||
|
||||
CourseStaffRole(course.location).add_users(user)
|
||||
location = Location(['i4x', 'MITx', '999', 'course',
|
||||
Location.clean('Robot Super Course'), None])
|
||||
CourseStaffRole(course.id).add_users(user)
|
||||
new_location = loc_mapper().translate_location(
|
||||
location.course_id, location, True, True
|
||||
course.location, True, True
|
||||
)
|
||||
course_private_url = new_location.url_reverse('course/', '')
|
||||
self.assertFalse(SESSION_KEY in self.client.session)
|
||||
|
||||
@@ -12,6 +12,7 @@ import unittest
|
||||
|
||||
from datetime import datetime
|
||||
from lxml import etree
|
||||
from lxml.html import fragment_fromstring
|
||||
from mock import Mock, MagicMock, patch
|
||||
from pytz import UTC
|
||||
from webob.multidict import MultiDict
|
||||
@@ -1384,23 +1385,44 @@ class OpenEndedModuleUtilTest(unittest.TestCase):
|
||||
link_text = u'I love going to www.lolcatz.com'
|
||||
link_atag = u'I love going to <a target="_blank" href="http://www.lolcatz.com">www.lolcatz.com</a>'
|
||||
|
||||
def assertHtmlEqual(self, actual, expected):
|
||||
"""
|
||||
Assert that two strings represent the same html.
|
||||
"""
|
||||
return self._assertHtmlEqual(
|
||||
fragment_fromstring(actual, create_parent='div'),
|
||||
fragment_fromstring(expected, create_parent='div')
|
||||
)
|
||||
|
||||
def _assertHtmlEqual(self, actual, expected):
|
||||
"""
|
||||
Assert that two HTML ElementTree elements are equal.
|
||||
"""
|
||||
self.assertEqual(actual.tag, expected.tag)
|
||||
self.assertEqual(actual.attrib, expected.attrib)
|
||||
self.assertEqual(actual.text, expected.text)
|
||||
self.assertEqual(actual.tail, expected.tail)
|
||||
self.assertEqual(len(actual), len(expected))
|
||||
for actual_child, expected_child in zip(actual, expected):
|
||||
self._assertHtmlEqual(actual_child, expected_child)
|
||||
|
||||
def test_script(self):
|
||||
"""
|
||||
Basic test for stripping <script>
|
||||
"""
|
||||
self.assertEqual(OpenEndedChild.sanitize_html(self.script_dirty), self.script_clean)
|
||||
self.assertHtmlEqual(OpenEndedChild.sanitize_html(self.script_dirty), self.script_clean)
|
||||
|
||||
def test_img(self):
|
||||
"""
|
||||
Basic test for passing through img, but stripping bad attr
|
||||
"""
|
||||
self.assertEqual(OpenEndedChild.sanitize_html(self.img_dirty), self.img_clean)
|
||||
self.assertHtmlEqual(OpenEndedChild.sanitize_html(self.img_dirty), self.img_clean)
|
||||
|
||||
def test_embed(self):
|
||||
"""
|
||||
Basic test for passing through embed, but stripping bad attr
|
||||
"""
|
||||
self.assertEqual(OpenEndedChild.sanitize_html(self.embed_dirty), self.embed_clean)
|
||||
self.assertHtmlEqual(OpenEndedChild.sanitize_html(self.embed_dirty), self.embed_clean)
|
||||
|
||||
def test_iframe(self):
|
||||
"""
|
||||
@@ -1412,25 +1434,25 @@ class OpenEndedModuleUtilTest(unittest.TestCase):
|
||||
"""
|
||||
Test for passing through text unchanged, including unicode
|
||||
"""
|
||||
self.assertEqual(OpenEndedChild.sanitize_html(self.text), self.text)
|
||||
self.assertHtmlEqual(OpenEndedChild.sanitize_html(self.text), self.text)
|
||||
|
||||
def test_lessthan(self):
|
||||
"""
|
||||
Tests that `<` in text context is handled properly
|
||||
"""
|
||||
self.assertEqual(OpenEndedChild.sanitize_html(self.text_lessthan_noencd), self.text_lessthan_encode)
|
||||
self.assertHtmlEqual(OpenEndedChild.sanitize_html(self.text_lessthan_noencd), self.text_lessthan_encode)
|
||||
|
||||
def test_linebreaks(self):
|
||||
"""
|
||||
tests the replace_newlines function
|
||||
"""
|
||||
self.assertEqual(OpenEndedChild.replace_newlines(self.text_linebreaks), self.text_brs)
|
||||
self.assertHtmlEqual(OpenEndedChild.replace_newlines(self.text_linebreaks), self.text_brs)
|
||||
|
||||
def test_linkify(self):
|
||||
"""
|
||||
tests the replace_newlines function
|
||||
"""
|
||||
self.assertEqual(OpenEndedChild.sanitize_html(self.link_text), self.link_atag)
|
||||
self.assertHtmlEqual(OpenEndedChild.sanitize_html(self.link_text), self.link_atag)
|
||||
|
||||
def test_combined(self):
|
||||
"""
|
||||
@@ -1448,4 +1470,4 @@ class OpenEndedModuleUtilTest(unittest.TestCase):
|
||||
self.embed_clean,
|
||||
self.text_lessthan_encode,
|
||||
self.img_clean)
|
||||
self.assertEqual(OpenEndedChild.sanitize_html(test_input), test_output)
|
||||
self.assertHtmlEqual(OpenEndedChild.sanitize_html(test_input), test_output)
|
||||
|
||||
@@ -25,13 +25,12 @@ class LTI20RESTResultServiceTest(LogicTest):
|
||||
def test_sanitize_get_context(self):
|
||||
"""Tests that the get_context function does basic sanitization"""
|
||||
# get_context, unfortunately, requires a lot of mocking machinery
|
||||
mocked_course = Mock(lti_passports=['lti_id:test_client:test_secret'])
|
||||
modulestore = Mock()
|
||||
modulestore.get_item.return_value = mocked_course
|
||||
runtime = Mock(modulestore=modulestore)
|
||||
mocked_course = Mock(name='mocked_course', lti_passports=['lti_id:test_client:test_secret'])
|
||||
modulestore = Mock(name='modulestore')
|
||||
modulestore.get_course.return_value = mocked_course
|
||||
runtime = Mock(name='runtime', modulestore=modulestore)
|
||||
self.xmodule.descriptor.runtime = runtime
|
||||
self.xmodule.lti_id = "lti_id"
|
||||
self.xmodule.scope_ids.usage_id = "mocked"
|
||||
|
||||
test_cases = ( # (before sanitize, after sanitize)
|
||||
(u"plaintext", u"plaintext"),
|
||||
|
||||
@@ -168,7 +168,7 @@ class TestLTIModuleListing(ModuleStoreTestCase):
|
||||
'courseware.module_render.handle_xblock_callback_noauth',
|
||||
args=[
|
||||
self.course.id.to_deprecated_string(),
|
||||
quote_slashes(unicode(self.lti_published.scope_ids.usage_id).encode('utf-8')),
|
||||
quote_slashes(unicode(self.lti_published.scope_ids.usage_id.to_deprecated_string()).encode('utf-8')),
|
||||
handler
|
||||
]
|
||||
))
|
||||
|
||||
@@ -573,7 +573,7 @@ class Courses(SysadminDashboardView):
|
||||
# don't delete user permission groups, though
|
||||
self.msg += \
|
||||
u"<font color='red'>{0} {1} = {2} ({3})</font>".format(
|
||||
_('Deleted'), loc, course.id.to_deprecated_string(), course.display_name)
|
||||
_('Deleted'), course.location.to_deprecated_string(), course.id.to_deprecated_string(), course.display_name)
|
||||
|
||||
context = {
|
||||
'datatable': self.make_datatable(),
|
||||
|
||||
@@ -50,7 +50,7 @@ class TestInstructorDashboardEmailView(ModuleStoreTestCase):
|
||||
|
||||
# Select the Email view of the instructor dash
|
||||
session = self.client.session
|
||||
session[u'idash_mode:{0}'.format(self.course.location.course_key)] = 'Email'
|
||||
session[u'idash_mode:{0}'.format(self.course.location.course_key.to_deprecated_string())] = 'Email'
|
||||
session.save()
|
||||
response = self.client.get(self.url)
|
||||
|
||||
@@ -131,7 +131,7 @@ class TestInstructorDashboardEmailView(ModuleStoreTestCase):
|
||||
course_authorization.save()
|
||||
|
||||
session = self.client.session
|
||||
session[u'idash_mode:{0}'.format(self.course.location.course_key)] = 'Email'
|
||||
session[u'idash_mode:{0}'.format(self.course.location.course_key.to_deprecated_string())] = 'Email'
|
||||
session.save()
|
||||
|
||||
response = self.client.post(
|
||||
|
||||
Reference in New Issue
Block a user