mirror of
https://github.com/f-droid/fdroidserver.git
synced 2025-09-13 14:32:28 +03:00
clarify config data types and structures
This commit is contained in:
parent
081e02c109
commit
8cf1297e2c
5 changed files with 116 additions and 31 deletions
|
@ -2903,46 +2903,46 @@ class CommonTest(unittest.TestCase):
|
|||
with self.assertRaises(TypeError):
|
||||
fdroidserver.common.expand_env_dict({'env': 'foo', 'foo': 'bar'})
|
||||
|
||||
def test_parse_mirrors_config_str(self):
|
||||
def test_parse_list_of_dicts_str(self):
|
||||
s = 'foo@example.com:/var/www'
|
||||
mirrors = yaml.load("""'%s'""" % s)
|
||||
self.assertEqual(
|
||||
[{'url': s}], fdroidserver.common.parse_mirrors_config(mirrors)
|
||||
[{'url': s}], fdroidserver.common.parse_list_of_dicts(mirrors)
|
||||
)
|
||||
|
||||
def test_parse_mirrors_config_list(self):
|
||||
def test_parse_list_of_dicts_list(self):
|
||||
s = 'foo@example.com:/var/www'
|
||||
mirrors = yaml.load("""- '%s'""" % s)
|
||||
self.assertEqual(
|
||||
[{'url': s}], fdroidserver.common.parse_mirrors_config(mirrors)
|
||||
[{'url': s}], fdroidserver.common.parse_list_of_dicts(mirrors)
|
||||
)
|
||||
|
||||
def test_parse_mirrors_config_dict(self):
|
||||
def test_parse_list_of_dicts_dict(self):
|
||||
s = 'foo@example.com:/var/www'
|
||||
mirrors = yaml.load("""- url: '%s'""" % s)
|
||||
self.assertEqual(
|
||||
[{'url': s}], fdroidserver.common.parse_mirrors_config(mirrors)
|
||||
[{'url': s}], fdroidserver.common.parse_list_of_dicts(mirrors)
|
||||
)
|
||||
|
||||
@mock.patch.dict(os.environ, {'PATH': os.getenv('PATH'), 'foo': 'bar'}, clear=True)
|
||||
def test_parse_mirrors_config_env_str(self):
|
||||
def test_parse_list_of_dicts_env_str(self):
|
||||
mirrors = yaml.load('{env: foo}')
|
||||
self.assertEqual(
|
||||
[{'url': 'bar'}], fdroidserver.common.parse_mirrors_config(mirrors)
|
||||
[{'url': 'bar'}], fdroidserver.common.parse_list_of_dicts(mirrors)
|
||||
)
|
||||
|
||||
def test_parse_mirrors_config_env_list(self):
|
||||
def test_parse_list_of_dicts_env_list(self):
|
||||
s = 'foo@example.com:/var/www'
|
||||
mirrors = yaml.load("""- '%s'""" % s)
|
||||
self.assertEqual(
|
||||
[{'url': s}], fdroidserver.common.parse_mirrors_config(mirrors)
|
||||
[{'url': s}], fdroidserver.common.parse_list_of_dicts(mirrors)
|
||||
)
|
||||
|
||||
def test_parse_mirrors_config_env_dict(self):
|
||||
def test_parse_list_of_dicts_env_dict(self):
|
||||
s = 'foo@example.com:/var/www'
|
||||
mirrors = yaml.load("""- url: '%s'""" % s)
|
||||
self.assertEqual(
|
||||
[{'url': s}], fdroidserver.common.parse_mirrors_config(mirrors)
|
||||
[{'url': s}], fdroidserver.common.parse_list_of_dicts(mirrors)
|
||||
)
|
||||
|
||||
def test_KnownApks_recordapk(self):
|
||||
|
|
|
@ -4,6 +4,7 @@ import logging
|
|||
import os
|
||||
import shutil
|
||||
import tempfile
|
||||
import textwrap
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
|
@ -534,6 +535,13 @@ class LintAntiFeaturesTest(unittest.TestCase):
|
|||
|
||||
|
||||
class ConfigYmlTest(LintTest):
|
||||
"""Test data formats used in config.yml.
|
||||
|
||||
lint.py uses print() and not logging so hacks are used to control
|
||||
the output when running in the test runner.
|
||||
|
||||
"""
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.config_yml = Path(self.testdir) / fdroidserver.common.CONFIG_FILE
|
||||
|
@ -550,6 +558,22 @@ class ConfigYmlTest(LintTest):
|
|||
self.config_yml.write_text('sdk_path: /opt/android-sdk\n')
|
||||
self.assertTrue(fdroidserver.lint.lint_config(self.config_yml))
|
||||
|
||||
def test_config_yml_str_list(self):
|
||||
self.config_yml.write_text('serverwebroot: [server1, server2]\n')
|
||||
self.assertTrue(fdroidserver.lint.lint_config(self.config_yml))
|
||||
|
||||
def test_config_yml_str_list_of_dicts(self):
|
||||
self.config_yml.write_text(
|
||||
textwrap.dedent(
|
||||
"""\
|
||||
serverwebroot:
|
||||
- url: 'me@b.az:/srv/fdroid'
|
||||
index_only: true
|
||||
"""
|
||||
)
|
||||
)
|
||||
self.assertTrue(fdroidserver.lint.lint_config(self.config_yml))
|
||||
|
||||
def test_config_yml_str_list_of_dicts_env(self):
|
||||
"""serverwebroot can be str, list of str, or list of dicts."""
|
||||
self.config_yml.write_text('serverwebroot: {env: ANDROID_HOME}\n')
|
||||
|
@ -595,3 +619,32 @@ class ConfigYmlTest(LintTest):
|
|||
fdroidserver.lint.lint_config(self.config_yml),
|
||||
f'{key} should fail on value of "{value}"',
|
||||
)
|
||||
|
||||
def test_config_yml_keyaliases(self):
|
||||
self.config_yml.write_text(
|
||||
textwrap.dedent(
|
||||
"""\
|
||||
keyaliases:
|
||||
com.example: myalias
|
||||
com.foo: '@com.example'
|
||||
"""
|
||||
)
|
||||
)
|
||||
self.assertTrue(fdroidserver.lint.lint_config(self.config_yml))
|
||||
|
||||
def test_config_yml_keyaliases_bad_str(self):
|
||||
"""The keyaliases: value is a dict not a str."""
|
||||
self.config_yml.write_text("keyaliases: '@com.example'\n")
|
||||
self.assertFalse(fdroidserver.lint.lint_config(self.config_yml))
|
||||
|
||||
def test_config_yml_keyaliases_bad_list(self):
|
||||
"""The keyaliases: value is a dict not a list."""
|
||||
self.config_yml.write_text(
|
||||
textwrap.dedent(
|
||||
"""\
|
||||
keyaliases:
|
||||
- com.example: myalias
|
||||
"""
|
||||
)
|
||||
)
|
||||
self.assertFalse(fdroidserver.lint.lint_config(self.config_yml))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue