deluge/deluge/tests/test_plugin_metadata.py
Calum Lind c3cd7f5e5c
[Plugins] Fix missing description with metadata 2.1
Changes to the metadata specs in v2.1 meant that Description field
might appear in the body of the message instead of as a header key.

Replaced custom parser with email parser (as outlined in the document
using compat32 policy) to simplify extracting the message header and
body.

Ref: https://dev.deluge-torrent.org/ticket/3476
Ref: https://packaging.python.org/en/latest/specifications/core-metadata/#description
2022-01-12 20:12:02 +00:00

50 lines
1.7 KiB
Python

#
# Copyright (C) 2015 Calum Lind <calumlind@gmail.com>
#
# This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with
# the additional special exception to link portions of this program with the OpenSSL library.
# See LICENSE for more details.
#
from deluge.pluginmanagerbase import PluginManagerBase
from . import common
from .basetest import BaseTestCase
class PluginManagerBaseTestCase(BaseTestCase):
def set_up(self):
common.set_tmp_config_dir()
def test_get_plugin_info(self):
pm = PluginManagerBase('core.conf', 'deluge.plugin.core')
for p in pm.get_available_plugins():
for key, value in pm.get_plugin_info(p).items():
self.assertIsInstance(key, str)
self.assertIsInstance(value, str)
def test_get_plugin_info_invalid_name(self):
pm = PluginManagerBase('core.conf', 'deluge.plugin.core')
for key, value in pm.get_plugin_info('random').items():
result = 'not available' if key in ('Name', 'Version') else ''
self.assertEqual(value, result)
def test_parse_pkg_info_metadata_2_1(self):
pkg_info = """Metadata-Version: 2.1
Name: AutoAdd
Version: 1.8
Summary: Monitors folders for .torrent files.
Home-page: http://dev.deluge-torrent.org/wiki/Plugins/AutoAdd
Author: Chase Sterling, Pedro Algarvio
Author-email: chase.sterling@gmail.com, pedro@algarvio.me
License: GPLv3
Platform: UNKNOWN
Monitors folders for .torrent files.
"""
plugin_info = PluginManagerBase.parse_pkg_info(pkg_info)
for value in plugin_info.values():
self.assertNotEqual(value, '')
result = 'Monitors folders for .torrent files.'
self.assertEqual(plugin_info['Description'], result)