Пример #1
0
 def test_generate_thumbnail_image(self):
     contentStore = ContentStore()
     content = Content(Location(
         u'c4x', u'mitX', u'800', u'asset', u'monsters__.jpg'), None)
     (thumbnail_content,
      thumbnail_file_location) = contentStore.generate_thumbnail(content)
     self.assertIsNone(thumbnail_content)
     self.assertEqual(Location(
         u'c4x', u'mitX', u'800', u'thumbnail', u'monsters__.jpg'), thumbnail_file_location)
Пример #2
0
 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
     )
Пример #3
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
     )
Пример #4
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
Пример #5
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)
Пример #6
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(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")
Пример #7
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")
Пример #8
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(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
     )
Пример #9
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
     )