Beispiel #1
0
 def test_generate_thumbnail_image(self):
     contentStore = ContentStore()
     content = Content(
         AssetLocation(u'mitX', u'800', u'ignore_run', u'asset',
                       u'monsters__.jpg'), None)
     (thumbnail_content,
      thumbnail_file_location) = contentStore.generate_thumbnail(content)
     self.assertIsNone(thumbnail_content)
     self.assertEqual(
         AssetLocation(u'mitX', u'800', u'ignore_run', u'thumbnail',
                       u'monsters__.jpg'), thumbnail_file_location)
 def test_generate_thumbnail_image(self, original_filename,
                                   thumbnail_filename):
     content_store = ContentStore()
     content = Content(
         AssetLocation(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(
         AssetLocation(u'mitX', u'800', u'ignore_run', u'thumbnail',
                       thumbnail_filename), thumbnail_file_location)
 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(
         SlashSeparatedCourseKey('mitX', '400', 'ignore'), 'subs__1eo_jXvZnE .srt.sjson'
     )
     self.assertEqual(AssetLocation(u'mitX', u'400', u'ignore', u'asset', u'subs__1eo_jXvZnE_.srt.sjson', None), asset_location)
 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(
         AssetLocation(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(
         AssetLocation(u'mitX', u'800', u'ignore_run', u'thumbnail',
                       thumbnail_filename), thumbnail_file_location)
    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(
            AssetLocation(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")
Beispiel #6
0
    def compute_location(course_key, path, revision=None, is_thumbnail=False):
        """
        Constructs a location object for static content.

        - course_key: the course that this asset belongs to
        - path: is the name of the static asset
        - revision: is the object's revision information
        - is_tumbnail: is whether or not we want the thumbnail version of this
            asset
        """
        path = path.replace('/', '_')
        return AssetLocation(course_key.org, course_key.course, course_key.run,
                             'asset' if not is_thumbnail else 'thumbnail',
                             AssetLocation.clean_keeping_underscores(path),
                             revision)
 def test_get_location_from_path(self):
     asset_location = StaticContent.get_location_from_path(u'/c4x/foo/bar/asset/images_course_image.jpg')
     self.assertEqual(
         AssetLocation(u'foo', u'bar', None, u'asset', u'images_course_image.jpg', None),
         asset_location
     )
 def test_deprecated_init(self):
     with self.assertDeprecationWarning():
         loc = AssetLocation("foo", "bar", "baz", "cat", "name")
     self.assertTrue(isinstance(loc, AssetLocator))
     self.assertTrue(loc.deprecated)