Exemple #1
0
    def test_make_cover_thumbnail(self, mock_shutils, mock_os, mock_util,
                                  mock_artresizer, _):
        thumbnail_dir = os.path.normpath(b"/thumbnail/dir")
        md5_file = os.path.join(thumbnail_dir, b"md5")
        path_to_art = os.path.normpath(b"/path/to/art")

        mock_os.path.join = os.path.join  # don't mock that function
        plugin = ThumbnailsPlugin()
        plugin.add_tags = Mock()

        album = Mock(artpath=path_to_art)
        mock_util.syspath.side_effect = lambda x: x
        plugin.thumbnail_file_name = Mock(return_value=b'md5')
        mock_os.path.exists.return_value = False

        def os_stat(target):
            if target == md5_file:
                return Mock(st_mtime=1)
            elif target == path_to_art:
                return Mock(st_mtime=2)
            else:
                raise ValueError(u"invalid target {0}".format(target))

        mock_os.stat.side_effect = os_stat

        plugin.make_cover_thumbnail(album, 12345, thumbnail_dir)

        mock_os.path.exists.assert_called_once_with(md5_file)
        mock_os.stat.has_calls(
            [call(md5_file), call(path_to_art)], any_order=True)

        resize = mock_artresizer.shared.resize
        resize.assert_called_once_with(12345, path_to_art, md5_file)
        plugin.add_tags.assert_called_once_with(album, resize.return_value)
        mock_shutils.move.assert_called_once_with(resize.return_value,
                                                  md5_file)

        # now test with recent thumbnail & with force
        mock_os.path.exists.return_value = True
        plugin.force = False
        resize.reset_mock()

        def os_stat(target):
            if target == md5_file:
                return Mock(st_mtime=3)
            elif target == path_to_art:
                return Mock(st_mtime=2)
            else:
                raise ValueError(u"invalid target {0}".format(target))

        mock_os.stat.side_effect = os_stat

        plugin.make_cover_thumbnail(album, 12345, thumbnail_dir)
        self.assertEqual(resize.call_count, 0)

        # and with force
        plugin.config['force'] = True
        plugin.make_cover_thumbnail(album, 12345, thumbnail_dir)
        resize.assert_called_once_with(12345, path_to_art, md5_file)
    def test_make_cover_thumbnail(self, mock_shutils, mock_os, mock_util,
                                  mock_artresizer, _):
        thumbnail_dir = os.path.normpath(b"/thumbnail/dir")
        md5_file = os.path.join(thumbnail_dir, b"md5")
        path_to_art = os.path.normpath(b"/path/to/art")

        mock_os.path.join = os.path.join  # don't mock that function
        plugin = ThumbnailsPlugin()
        plugin.add_tags = Mock()

        album = Mock(artpath=path_to_art)
        mock_util.syspath.side_effect = lambda x: x
        plugin.thumbnail_file_name = Mock(return_value=b'md5')
        mock_os.path.exists.return_value = False

        def os_stat(target):
            if target == md5_file:
                return Mock(st_mtime=1)
            elif target == path_to_art:
                return Mock(st_mtime=2)
            else:
                raise ValueError(u"invalid target {0}".format(target))
        mock_os.stat.side_effect = os_stat

        plugin.make_cover_thumbnail(album, 12345, thumbnail_dir)

        mock_os.path.exists.assert_called_once_with(md5_file)
        mock_os.stat.has_calls([call(md5_file), call(path_to_art)],
                               any_order=True)

        resize = mock_artresizer.shared.resize
        resize.assert_called_once_with(12345, path_to_art, md5_file)
        plugin.add_tags.assert_called_once_with(album, resize.return_value)
        mock_shutils.move.assert_called_once_with(resize.return_value,
                                                  md5_file)

        # now test with recent thumbnail & with force
        mock_os.path.exists.return_value = True
        plugin.force = False
        resize.reset_mock()

        def os_stat(target):
            if target == md5_file:
                return Mock(st_mtime=3)
            elif target == path_to_art:
                return Mock(st_mtime=2)
            else:
                raise ValueError(u"invalid target {0}".format(target))
        mock_os.stat.side_effect = os_stat

        plugin.make_cover_thumbnail(album, 12345, thumbnail_dir)
        self.assertEqual(resize.call_count, 0)

        # and with force
        plugin.config['force'] = True
        plugin.make_cover_thumbnail(album, 12345, thumbnail_dir)
        resize.assert_called_once_with(12345, path_to_art, md5_file)