category with no apps should be ignored, even if defined in config

https://gitlab.com/fdroid/fdroidclient/-/issues/2619#note_1421280589

The test needed to change because the test index files contained category
definitions that were not ever used in the "copy tests/repo, generate java/gpg
keys, update, and gpgsign" test in tests/run-tests.
This commit is contained in:
Hans-Christoph Steiner 2023-06-07 15:57:58 +02:00
parent 2c566cf68f
commit 48559ecec5
9 changed files with 44 additions and 3 deletions

View File

@ -743,9 +743,16 @@ def make_v2(apps, packages, repodir, repodict, requestsdict, fdroid_signing_key_
if categories_used_by_apps and not output['repo'].get(CATEGORIES_CONFIG_NAME):
output['repo'][CATEGORIES_CONFIG_NAME] = dict()
# include definitions for "auto-defined" categories, e.g. just used in app metadata
for category in sorted(categories_used_by_apps):
if category not in output['repo'][CATEGORIES_CONFIG_NAME]:
output['repo'][CATEGORIES_CONFIG_NAME][category] = dict()
# do not include defined categories if no apps use them
for category in list(output['repo'].get(CATEGORIES_CONFIG_NAME, list())):
if category not in categories_used_by_apps:
del output['repo'][CATEGORIES_CONFIG_NAME][category]
msg = _('Category "{category}" defined but not used for any apps!')
logging.warning(msg.format(category=category))
entry = {}
entry["timestamp"] = repodict["timestamp"]

View File

@ -1863,6 +1863,8 @@ class MetadataTest(unittest.TestCase):
AntiFeatures:
- NonFreeNet
Categories:
- Multimedia
- Security
- Time
License: GPL-3.0-only
SourceCode: https://github.com/miguelvps/PoliteDroid

View File

@ -1,6 +1,8 @@
AntiFeatures:
- NonFreeNet
Categories:
- Multimedia
- Security
- Time
License: GPL-3.0-only
SourceCode: https://github.com/miguelvps/PoliteDroid

View File

@ -161,6 +161,8 @@ Builds:
versionCode: 6
versionName: '1.5'
Categories:
- Multimedia
- Security
- Time
Changelog: ''
CurrentVersion: '1.5'

View File

@ -3,7 +3,7 @@
"version": 20002,
"index": {
"name": "/index-v2.json",
"sha256": "b613858aa7a2ec476fcef5c841a5b8ff4b3b0f67f07678da981e2843f49c71ba",
"sha256": "5e3c0eaafd99d3518da2bb2bc7565b2ebcb17775a2f4ccc33b7336901ec71a6f",
"size": 53283,
"numPackages": 10
},

View File

@ -174,6 +174,8 @@
"NonFreeNet"
],
"categories": [
"Multimedia",
"Security",
"Time"
],
"suggestedVersionName": "1.5",

View File

@ -553,6 +553,8 @@
"metadata": {
"added": 1498176000000,
"categories": [
"Multimedia",
"Security",
"Time"
],
"issueTracker": "https://github.com/miguelvps/PoliteDroid/issues",

View File

@ -311,8 +311,8 @@ APK is called F-Droid Privileged Extension.</desc>
<icon>com.politedroid.6.png</icon>
<desc>Activates silent mode during calendar events.</desc>
<license>GPL-3.0-only</license>
<categories>Time</categories>
<category>Time</category>
<categories>Multimedia,Security,Time</categories>
<category>Multimedia</category>
<web></web>
<source>https://github.com/miguelvps/PoliteDroid</source>
<tracker>https://github.com/miguelvps/PoliteDroid/issues</tracker>

View File

@ -1898,6 +1898,30 @@ class UpdateTest(unittest.TestCase):
index['repo'][CATEGORIES_CONFIG_NAME],
)
def test_empty_categories_not_in_index(self):
"""A category with no apps should be ignored, even if defined in config."""
os.chdir(self.testdir)
os.mkdir('config')
Path('config/categories.yml').write_text('System: {name: S}\nTime: {name: T}\n')
os.mkdir('metadata')
os.mkdir('repo')
Path('config.yml').write_text(
'repo_pubkey: ffffffffffffffffffffffffffffffffffffffff'
)
testapk = os.path.join('repo', 'com.politedroid_6.apk')
shutil.copy(os.path.join(self.basedir, testapk), testapk)
Path('metadata/com.politedroid.yml').write_text('Categories: [Time]')
with mock.patch('sys.argv', ['fdroid update', '--delete-unknown', '--nosign']):
fdroidserver.update.main()
with open('repo/index-v2.json') as fp:
index = json.load(fp)
self.assertEqual(
{'Time': {'name': {'en-US': 'T'}}},
index['repo'][CATEGORIES_CONFIG_NAME],
)
if __name__ == "__main__":
os.chdir(os.path.dirname(__file__))