Skip to content

Commit d398994

Browse files
committed
Merge branch 'fix-categories-yml-only-icon' into 'master'
update: If categories.yml only has icon:, then add name: See merge request fdroid/fdroidserver!1659
2 parents 964861e + 494d811 commit d398994

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

fdroidserver/index.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,9 @@ def _index_encoder_default(obj):
775775
# include definitions for "auto-defined" categories, e.g. just used in app metadata
776776
for category in sorted(categories_used_by_apps):
777777
if category not in output['repo'][CATEGORIES_CONFIG_NAME]:
778-
output['repo'][CATEGORIES_CONFIG_NAME][category] = {"name": {DEFAULT_LOCALE: category}}
778+
output['repo'][CATEGORIES_CONFIG_NAME][category] = dict()
779+
if 'name' not in output['repo'][CATEGORIES_CONFIG_NAME][category]:
780+
output['repo'][CATEGORIES_CONFIG_NAME][category]['name'] = {DEFAULT_LOCALE: category}
779781
# do not include defined categories if no apps use them
780782
for category in list(output['repo'].get(CATEGORIES_CONFIG_NAME, list())):
781783
if category not in categories_used_by_apps:

tests/test_update.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1913,6 +1913,41 @@ def test_auto_defined_categories(self):
19131913
index['repo'][CATEGORIES_CONFIG_NAME],
19141914
)
19151915

1916+
def test_categories_with_only_icon_defined(self):
1917+
"""If cateogories.yml only includes the icon, the name should be added."""
1918+
os.chdir(self.testdir)
1919+
os.mkdir('config')
1920+
os.mkdir('metadata')
1921+
os.mkdir('repo')
1922+
fdroidserver.common.write_config_file(
1923+
'repo_pubkey: ffffffffffffffffffffffffffffffffffffffff\n'
1924+
)
1925+
testvalue = 'Time'
1926+
Path('config/time.png').write_text('placeholder')
1927+
Path('config/categories.yml').write_text(testvalue + ': {icon: time.png}')
1928+
1929+
testapk = os.path.join('repo', 'com.politedroid_6.apk')
1930+
shutil.copy(basedir / testapk, testapk)
1931+
Path('metadata/com.politedroid.yml').write_text(f'Categories: [{testvalue}]')
1932+
1933+
with mock.patch('sys.argv', ['fdroid update', '--delete-unknown', '--nosign']):
1934+
fdroidserver.update.main()
1935+
with open('repo/index-v2.json') as fp:
1936+
index = json.load(fp)
1937+
self.assertEqual(
1938+
{
1939+
'icon': {
1940+
'en-US': {
1941+
'name': '/icons/time.png',
1942+
'sha256': '4097889236a2af26c293033feb964c4cf118c0224e0d063fec0a89e9d0569ef2',
1943+
'size': 11,
1944+
}
1945+
},
1946+
'name': {'en-US': testvalue},
1947+
},
1948+
index['repo'][CATEGORIES_CONFIG_NAME][testvalue],
1949+
)
1950+
19161951
def test_auto_defined_categories_two_apps(self):
19171952
"""Repos that don't define categories in config/ should use auto-generated."""
19181953
os.chdir(self.testdir)

0 commit comments

Comments
 (0)