Add failing tests for course image names
Tests LMS-2073 (non-ascii course image names) and STUD-1197 (spaces in course image names)
This commit is contained in:
@@ -1,14 +1,15 @@
|
||||
""" Tests for utils. """
|
||||
from contentstore import utils
|
||||
import mock
|
||||
import collections
|
||||
import copy
|
||||
import mock
|
||||
from unittest import expectedFailure
|
||||
|
||||
from django.test import TestCase
|
||||
from xmodule.modulestore.tests.factories import CourseFactory
|
||||
from django.test.utils import override_settings
|
||||
|
||||
from contentstore import utils
|
||||
from xmodule.modulestore import Location
|
||||
from xmodule.modulestore.tests.factories import CourseFactory
|
||||
|
||||
|
||||
class LMSLinksTestCase(TestCase):
|
||||
@@ -166,3 +167,23 @@ class CourseImageTestCase(TestCase):
|
||||
course = CourseFactory.create(org='edX', course='999')
|
||||
url = utils.course_image_url(course)
|
||||
self.assertEquals(url, '/c4x/edX/999/asset/{0}'.format(course.course_image))
|
||||
|
||||
@expectedFailure
|
||||
def test_non_ascii_image_name(self):
|
||||
# Verify that non-ascii image names are cleaned
|
||||
course = CourseFactory.create(course_image=u'before_\N{SNOWMAN}_after.jpg')
|
||||
self.assertEquals(
|
||||
utils.course_image_url(course),
|
||||
'/c4x/{org}/{course}/asset/before___after.jpg'.format(org=course.location.org, course=course.location.course)
|
||||
)
|
||||
|
||||
def test_spaces_in_image_name(self):
|
||||
# Verify that image names with spaces in them are cleaned
|
||||
course = CourseFactory.create(course_image=u'before after.jpg')
|
||||
self.assertEquals(
|
||||
utils.course_image_url(course),
|
||||
'/c4x/{org}/{course}/asset/before_after.jpg'.format(
|
||||
org=course.location.org,
|
||||
course=course.location.course
|
||||
)
|
||||
)
|
||||
|
||||
@@ -3,6 +3,7 @@ Xml parsing tests for XModules
|
||||
"""
|
||||
import pprint
|
||||
from mock import Mock
|
||||
from unittest import TestCase
|
||||
|
||||
from xmodule.x_module import XMLParsingSystem, policy_key
|
||||
from xmodule.mako_module import MakoDescriptorSystem
|
||||
@@ -54,7 +55,7 @@ class InMemorySystem(XMLParsingSystem, MakoDescriptorSystem): # pylint: disable
|
||||
return self._descriptors[Location(location).url()]
|
||||
|
||||
|
||||
class XModuleXmlImportTest(object):
|
||||
class XModuleXmlImportTest(TestCase):
|
||||
"""Base class for tests that use basic XML parsing"""
|
||||
def process_xml(self, xml_import_data):
|
||||
"""Use the `xml_import_data` to import an :class:`XBlock` from XML."""
|
||||
|
||||
@@ -119,6 +119,10 @@ class XmlImportFactory(Factory):
|
||||
class CourseFactory(XmlImportFactory):
|
||||
"""Factory for <course> nodes"""
|
||||
tag = 'course'
|
||||
org = 'edX'
|
||||
course = 'xml_test_course'
|
||||
name = '101'
|
||||
static_asset_path = 'xml_test_course'
|
||||
|
||||
|
||||
class SequenceFactory(XmlImportFactory):
|
||||
|
||||
@@ -3,13 +3,17 @@
|
||||
Tests for course access
|
||||
"""
|
||||
import mock
|
||||
from unittest import expectedFailure
|
||||
|
||||
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
|
||||
from django.http import Http404
|
||||
from django.test.utils import override_settings
|
||||
from courseware.courses import get_course_by_id, get_course, get_cms_course_link
|
||||
from xmodule.modulestore.django import get_default_store_name_for_current_request
|
||||
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
|
||||
from xmodule.modulestore.tests.factories import CourseFactory
|
||||
from xmodule.tests.xml import factories as xml
|
||||
from xmodule.tests.xml import XModuleXmlImportTest
|
||||
|
||||
from courseware.courses import get_course_by_id, get_course, get_cms_course_link, course_image_url
|
||||
from courseware.tests.tests import TEST_DATA_MONGO_MODULESTORE
|
||||
|
||||
|
||||
@@ -79,3 +83,57 @@ class CoursesTest(ModuleStoreTestCase):
|
||||
)
|
||||
def test_default_modulestore_published_mapping(self):
|
||||
self.assertEqual(get_default_store_name_for_current_request(), 'default')
|
||||
|
||||
|
||||
@override_settings(
|
||||
MODULESTORE=TEST_DATA_MONGO_MODULESTORE, CMS_BASE=CMS_BASE_TEST
|
||||
)
|
||||
class MongoCourseImageTestCase(ModuleStoreTestCase):
|
||||
"""Tests for course image URLs when using a mongo modulestore."""
|
||||
|
||||
def test_get_image_url(self):
|
||||
"""Test image URL formatting."""
|
||||
course = CourseFactory.create(org='edX', course='999')
|
||||
self.assertEquals(course_image_url(course), '/c4x/edX/999/asset/{0}'.format(course.course_image))
|
||||
|
||||
@expectedFailure
|
||||
def test_non_ascii_image_name(self):
|
||||
# Verify that non-ascii image names are cleaned
|
||||
course = CourseFactory.create(course_image=u'before_\N{SNOWMAN}_after.jpg')
|
||||
self.assertEquals(
|
||||
course_image_url(course),
|
||||
'/c4x/{org}/{course}/asset/before___after.jpg'.format(
|
||||
org=course.location.org,
|
||||
course=course.location.course
|
||||
)
|
||||
)
|
||||
|
||||
def test_spaces_in_image_name(self):
|
||||
# Verify that image names with spaces in them are cleaned
|
||||
course = CourseFactory.create(course_image=u'before after.jpg')
|
||||
self.assertEquals(
|
||||
course_image_url(course),
|
||||
'/c4x/{org}/{course}/asset/before_after.jpg'.format(
|
||||
org=course.location.org,
|
||||
course=course.location.course
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
class XmlCourseImageTestCase(XModuleXmlImportTest):
|
||||
"""Tests for course image URLs when using an xml modulestore."""
|
||||
|
||||
def test_get_image_url(self):
|
||||
"""Test image URL formatting."""
|
||||
course = self.process_xml(xml.CourseFactory.build())
|
||||
self.assertEquals(course_image_url(course), '/static/xml_test_course/images/course_image.jpg')
|
||||
|
||||
def test_non_ascii_image_name(self):
|
||||
# XML Course images are always stored at /images/course_image.jpg
|
||||
course = self.process_xml(xml.CourseFactory.build(course_image=u'before_\N{SNOWMAN}_after.jpg'))
|
||||
self.assertEquals(course_image_url(course), '/static/xml_test_course/images/course_image.jpg')
|
||||
|
||||
def test_spaces_in_image_name(self):
|
||||
# XML Course images are always stored at /images/course_image.jpg
|
||||
course = self.process_xml(xml.CourseFactory.build(course_image=u'before after.jpg'))
|
||||
self.assertEquals(course_image_url(course), '/static/xml_test_course/images/course_image.jpg')
|
||||
|
||||
Reference in New Issue
Block a user