コード例 #1
0
ファイル: test_files.py プロジェクト: umeshprasadk/studio
 def setUp(self):
     super(FileThumbnailTestCase, self).setUp()
     self.thumbnail_fobj = create_thumbnail_from_base64(base64encoding())
     filepath = generate_object_storage_name(self.thumbnail_fobj.checksum,
                                             str(self.thumbnail_fobj))
     with default_storage.open(filepath, 'rb') as fobj:
         self.thumbnail_contents = fobj.read()
コード例 #2
0
    def test_get_node_thumbnail_file(self):
        new_node = ContentNode.objects.create(title="Heyo!", parent=self.channel.main_tree, kind=self.topic)
        thumbnail_file = create_thumbnail_from_base64(testdata.base64encoding())
        thumbnail_file.contentnode = new_node

        # we need to make sure the file is marked as a thumbnail
        preset, _created = FormatPreset.objects.get_or_create(id="video_thumbnail")
        preset.thumbnail = True
        thumbnail_file.preset = preset
        thumbnail_file.save()

        assert new_node.get_thumbnail() == generate_storage_url(str(thumbnail_file))
コード例 #3
0
    def test_get_node_thumbnail_file(self):
        new_node = ContentNode.objects.create(title="Heyo!",
                                              parent=self.channel.main_tree,
                                              kind=self.topic)
        thumbnail_file = create_thumbnail_from_base64(testdata.base64encoding())
        thumbnail_file.contentnode = new_node

        # we need to make sure the file is marked as a thumbnail
        preset, _created = FormatPreset.objects.get_or_create(id="video_thumbnail")
        preset.thumbnail = True
        thumbnail_file.preset = preset
        thumbnail_file.save()

        assert new_node.get_thumbnail() == generate_storage_url(str(thumbnail_file))
コード例 #4
0
def create_associated_thumbnail(ccnode, ccfilemodel):
    """
        Gets the appropriate thumbnail for export (uses or generates a base64 encoding)
        Args:
            ccnode (<ContentNode>): node to derive thumbnail from (if encoding is provided)
            ccfilemodel (<File>): file to get thumbnail from if no encoding is available
        Returns <File> model of encoded, resized thumbnail
    """
    encoding = None
    try:
        encoding = ccnode.thumbnail_encoding and load_json_string(
            ccnode.thumbnail_encoding).get('base64')
    except ValueError:
        logging.error(
            "ERROR: node thumbnail is not in correct format ({}: {})".format(
                ccnode.id, ccnode.thumbnail_encoding))
        return

    # Save the encoding if it doesn't already have an encoding
    if not encoding:
        try:
            encoding = get_thumbnail_encoding(str(ccfilemodel))
        except IOError:
            # ImageMagick may raise an IOError if the file is not a thumbnail. Catch that then just return early.
            logging.error(
                "ERROR: cannot identify the thumbnail ({}: {})".format(
                    ccnode.id, ccnode.thumbnail_encoding))
            return
        ccnode.thumbnail_encoding = json.dumps({
            "base64": encoding,
            "points": [],
            "zoom": 0,
        })
        ccnode.save()

    return create_thumbnail_from_base64(
        encoding,
        uploaded_by=ccfilemodel.uploaded_by,
        file_format_id=ccfilemodel.file_format_id,
        preset_id=ccfilemodel.preset_id)
コード例 #5
0
def create_associated_thumbnail(ccnode, ccfilemodel):
    """
        Gets the appropriate thumbnail for export (uses or generates a base64 encoding)
        Args:
            ccnode (<ContentNode>): node to derive thumbnail from (if encoding is provided)
            ccfilemodel (<File>): file to get thumbnail from if no encoding is available
        Returns <File> model of encoded, resized thumbnail
    """
    encoding = None
    try:
        encoding = ccnode.thumbnail_encoding and load_json_string(ccnode.thumbnail_encoding).get('base64')
    except ValueError:
        logging.error("ERROR: node thumbnail is not in correct format ({}: {})".format(ccnode.id, ccnode.thumbnail_encoding))
        return

    # Save the encoding if it doesn't already have an encoding
    if not encoding:
        try:
            encoding = get_thumbnail_encoding(str(ccfilemodel))
        except IOError:
            # ImageMagick may raise an IOError if the file is not a thumbnail. Catch that then just return early.
            logging.error("ERROR: cannot identify the thumbnail ({}: {})".format(ccnode.id, ccnode.thumbnail_encoding))
            return
        ccnode.thumbnail_encoding = json.dumps({
            "base64": encoding,
            "points": [],
            "zoom": 0,
        })
        ccnode.save()

    return create_thumbnail_from_base64(
        encoding,
        uploaded_by=ccfilemodel.uploaded_by,
        file_format_id=ccfilemodel.file_format_id,
        preset_id=ccfilemodel.preset_id
    )
コード例 #6
0
ファイル: test_files.py プロジェクト: umeshprasadk/studio
 def test_existing_thumbnail_is_not_created(self, storage_exists_mock,
                                            storage_save_mock):
     create_thumbnail_from_base64(base64encoding())
     storage_exists_mock.assert_called()
     storage_save_mock.assert_not_called()
コード例 #7
0
 def test_existing_thumbnail_is_not_created(self, storage_exists_mock, storage_save_mock):
     create_thumbnail_from_base64(base64encoding())
     storage_exists_mock.assert_called()
     storage_save_mock.assert_not_called()
コード例 #8
0
 def setUp(self):
     super(FileThumbnailTestCase, self).setUp()
     self.thumbnail_fobj = create_thumbnail_from_base64(base64encoding())
     filepath = generate_object_storage_name(self.thumbnail_fobj.checksum, str(self.thumbnail_fobj))
     with default_storage.open(filepath, 'rb') as fobj:
         self.thumbnail_contents = fobj.read()