Esempio n. 1
0
 def test_map_into_course_asset_location(self):
     original_course = CourseKey.from_string('org/course/run')
     new_course = CourseKey.from_string('edX/toy/2012_Fall')
     loc = AssetLocator(original_course, 'asset', 'foo.bar')
     self.assertEqual(
         AssetLocator(new_course, 'asset', 'foo.bar', deprecated=True),
         loc.map_into_course(new_course))
Esempio n. 2
0
class CachingTestCase(TestCase):
    """
    Tests for https://edx.lighthouseapp.com/projects/102637/tickets/112-updating-asset-does-not-refresh-the-cached-copy
    """
    unicodeLocation = AssetLocator(CourseLocator(u'c4x', u'mitX', u'800'),
                                   u'thumbnail', u'monsters.jpg')
    # Note that some of the parts are strings instead of unicode strings
    nonUnicodeLocation = AssetLocator(CourseLocator('c4x', u'mitX', u'800'),
                                      'thumbnail', 'monsters.jpg')
    mockAsset = Content(unicodeLocation, 'my content')

    def test_put_and_get(self):
        set_cached_content(self.mockAsset)
        self.assertEqual(self.mockAsset.content,
                         get_cached_content(self.unicodeLocation).content,
                         'should be stored in cache with unicodeLocation')
        self.assertEqual(self.mockAsset.content,
                         get_cached_content(self.nonUnicodeLocation).content,
                         'should be stored in cache with nonUnicodeLocation')

    def test_delete(self):
        set_cached_content(self.mockAsset)
        del_cached_content(self.nonUnicodeLocation)
        self.assertEqual(None, get_cached_content(self.unicodeLocation),
                         'should not be stored in cache with unicodeLocation')
        self.assertEqual(
            None, get_cached_content(self.nonUnicodeLocation),
            'should not be stored in cache with nonUnicodeLocation')
Esempio n. 3
0
 def test_old_charset(self):
     # merely not raising InvalidKeyError suffices
     AssetLocator(CourseLocator('a', 'b', 'c'), 'asset',
                  'subs_%20S2x5jhbWl_o.srt.sjson')
     AssetLocator(CourseLocator('a', 'b', 'c'),
                  'asset',
                  'subs_%20S2x5jhbWl_o.srt.sjson',
                  deprecated=True)
Esempio n. 4
0
 def test_generate_thumbnail_image(self, original_filename, thumbnail_filename):
     content_store = ContentStore()
     content = Content(AssetLocator(CourseLocator(u'mitX', u'800', u'ignore_run'), u'asset', original_filename),
                       None)
     (thumbnail_content, thumbnail_file_location) = content_store.generate_thumbnail(content)
     self.assertIsNone(thumbnail_content)
     self.assertEqual(
         AssetLocator(CourseLocator(u'mitX', u'800', u'ignore_run'), u'thumbnail', thumbnail_filename),
         thumbnail_file_location
     )
Esempio n. 5
0
 def test_generate_thumbnail_image(self, original_filename,
                                   thumbnail_filename):
     content_store = ContentStore()
     content = Content(
         AssetLocator(CourseLocator('mitX', '800', 'ignore_run'), 'asset',
                      original_filename), None)
     (thumbnail_content,
      thumbnail_file_location) = content_store.generate_thumbnail(content)
     assert thumbnail_content is None
     assert AssetLocator(CourseLocator('mitX', '800', 'ignore_run'), 'thumbnail', thumbnail_filename) ==\
            thumbnail_file_location
Esempio n. 6
0
 def test_store_svg_as_thumbnail(self):
     # We had a bug that caused generate_thumbnail to attempt to pass SVG to PIL to generate a thumbnail.
     # SVG files should be stored in original form for thumbnail purposes.
     content_store = ContentStore()
     content_store.save = Mock()
     thumbnail_filename = u'test.svg'
     content = Content(AssetLocator(CourseLocator(u'mitX', u'800', u'ignore_run'), u'asset', u'test.svg'),
                       'image/svg+xml')
     content.data = 'mock svg file'
     (thumbnail_content, thumbnail_file_location) = content_store.generate_thumbnail(content)
     self.assertEqual(thumbnail_content.data.read(), b'mock svg file')
     self.assertEqual(
         AssetLocator(CourseLocator(u'mitX', u'800', u'ignore_run'), u'thumbnail', thumbnail_filename),
         thumbnail_file_location
     )
Esempio n. 7
0
 def test_get_location_from_path(self):
     asset_location = StaticContent.get_location_from_path(u'/c4x/a/b/asset/images_course_image.jpg')
     self.assertEqual(
         AssetLocator(CourseLocator(u'a', u'b', None, deprecated=True),
                      u'asset', u'images_course_image.jpg', deprecated=True),
         asset_location
     )
Esempio n. 8
0
 def test_get_location_from_path(self):
     asset_location = StaticContent.get_location_from_path(
         '/c4x/a/b/asset/images_course_image.jpg')
     assert AssetLocator(CourseLocator('a', 'b', None, deprecated=True),
                         'asset',
                         'images_course_image.jpg',
                         deprecated=True) == asset_location
Esempio n. 9
0
 def test_compute_location(self):
     # We had a bug that __ got converted into a single _. Make sure that substitution of INVALID_CHARS (like space)
     # still happen.
     asset_location = StaticContent.compute_location(
         CourseKey.from_string('mitX/400/ignore'),
         'subs__1eo_jXvZnE .srt.sjson')
     assert AssetLocator(
         CourseLocator('mitX', '400', 'ignore', deprecated=True), 'asset',
         'subs__1eo_jXvZnE_.srt.sjson') == asset_location
Esempio n. 10
0
    def test_image_is_closed_when_generating_thumbnail(self, image_class_mock):
        # We used to keep the Image's file descriptor open when generating a thumbnail.
        # It should be closed after being used.
        mock_image = MockImage()
        image_class_mock.open.return_value = mock_image

        content_store = ContentStore()
        content = Content(AssetLocator(CourseLocator(u'mitX', u'800', u'ignore_run'), u'asset', "monsters.jpg"),
                          "image/jpeg")
        content.data = 'mock data'
        content_store.generate_thumbnail(content)
        self.assertTrue(image_class_mock.open.called, "Image.open not called")
        self.assertTrue(mock_image.close.called, "mock_image.close not called")
Esempio n. 11
0
 def test_make_asset_key(self):
     lib_key = CourseKey.from_string('library-v1:TestX+lib1')
     self.assertEqual(AssetLocator(lib_key, 'asset', 'foo.bar'),
                      lib_key.make_asset_key('asset', 'foo.bar'))
Esempio n. 12
0
 def make_asset_key(self, asset_type, path):
     return AssetLocator(self.to_course_locator(),
                         asset_type,
                         path,
                         deprecated=False)
Esempio n. 13
0
 def test_make_asset_key(self):
     course = CourseKey.from_string('org/course/run')
     self.assertEqual(
         AssetLocator(course, 'asset', 'foo.bar', deprecated=True),
         course.make_asset_key('asset', 'foo.bar'))