mirror of
https://github.com/f-droid/fdroidserver.git
synced 2025-10-06 09:21:07 +03:00
Merge branch '471-lint-check-unknown-keys' into 'master'
check for unknown app fields and build flags when parsing yml Closes #471 See merge request fdroid/fdroidserver!554
This commit is contained in:
commit
05be4bc814
3 changed files with 98 additions and 49 deletions
|
@ -2,6 +2,7 @@
|
|||
|
||||
# http://www.drdobbs.com/testing/unit-testing-with-python/240165163
|
||||
|
||||
import io
|
||||
import glob
|
||||
import inspect
|
||||
import logging
|
||||
|
@ -13,6 +14,8 @@ import sys
|
|||
import unittest
|
||||
import yaml
|
||||
import tempfile
|
||||
import textwrap
|
||||
from unittest import mock
|
||||
|
||||
localmodule = os.path.realpath(
|
||||
os.path.join(os.path.dirname(inspect.getfile(inspect.currentframe())), '..'))
|
||||
|
@ -22,6 +25,7 @@ if localmodule not in sys.path:
|
|||
|
||||
import fdroidserver.common
|
||||
import fdroidserver.metadata
|
||||
from fdroidserver.exception import MetaDataException
|
||||
|
||||
|
||||
class MetadataTest(unittest.TestCase):
|
||||
|
@ -139,6 +143,28 @@ class MetadataTest(unittest.TestCase):
|
|||
allappids.append(appid)
|
||||
self.assertEqual(randomlist, allappids)
|
||||
|
||||
def test_parse_yaml_metadata_unknown_app_field(self):
|
||||
mf = io.StringIO(textwrap.dedent("""\
|
||||
AutoName: F-Droid
|
||||
RepoType: git
|
||||
Builds: []
|
||||
bad: value"""))
|
||||
mf.name = 'mock_filename.yaml'
|
||||
with mock.patch('fdroidserver.metadata.warnings_action', 'error'):
|
||||
with self.assertRaises(MetaDataException):
|
||||
fdroidserver.metadata.parse_yaml_metadata(mf, {})
|
||||
|
||||
def test_parse_yaml_metadata_unknown_build_flag(self):
|
||||
mf = io.StringIO(textwrap.dedent("""\
|
||||
AutoName: F-Droid
|
||||
RepoType: git
|
||||
Builds:
|
||||
- bad: value"""))
|
||||
mf.name = 'mock_filename.yaml'
|
||||
with mock.patch('fdroidserver.metadata.warnings_action', 'error'):
|
||||
with self.assertRaises(MetaDataException):
|
||||
fdroidserver.metadata.parse_yaml_metadata(mf, {})
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
os.chdir(os.path.dirname(__file__))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue