1
0
mirror of https://gitlab.com/fdroid/fdroidserver.git synced 2024-11-09 00:40:11 +01:00
fdroidserver/tests/rewritemeta.TestCase
Hans-Christoph Steiner 8c1cf724e1 init: force keystore to PKCS12 format
Java 8 supports PKCS12, Java 9+ uses PKCS12 by default, which should have
a .p12 file extension.  `fdroid init` has always just added .jks which is
the old default format.

* https://docs.oracle.com/en/java/javase/12/tools/keytool.html#GUID-5990A2E4-78E3-47B7-AE75-6D1826259549__GUID-A8B9E662-C1C2-4A0E-9307-A8464F0E95D4
* https://openjdk.java.net/jeps/229
2020-09-23 16:40:37 +02:00

99 lines
3.0 KiB
Python
Executable File

#!/usr/bin/env python3
import inspect
import logging
import optparse
import os
import sys
import unittest
import tempfile
import textwrap
from unittest import mock
from testcommon import TmpCwd
localmodule = os.path.realpath(
os.path.join(os.path.dirname(inspect.getfile(inspect.currentframe())), '..'))
print('localmodule: ' + localmodule)
if localmodule not in sys.path:
sys.path.insert(0, localmodule)
from fdroidserver import common
from fdroidserver import rewritemeta
from fdroidserver.exception import FDroidException
class RewriteMetaTest(unittest.TestCase):
'''fdroidserver/publish.py'''
def setUp(self):
logging.basicConfig(level=logging.DEBUG)
self.basedir = os.path.join(localmodule, 'tests')
self.tmpdir = os.path.abspath(os.path.join(self.basedir, '..', '.testfiles'))
if not os.path.exists(self.tmpdir):
os.makedirs(self.tmpdir)
os.chdir(self.basedir)
def test_rewrite_scenario_trivial(self):
sys.argv = ['rewritemeta', 'a', 'b']
with tempfile.TemporaryDirectory() as tmpdir, TmpCwd(tmpdir):
os.mkdir('metadata')
with open('metadata/a.yml', 'w') as f:
f.write('AutoName: a')
with open('metadata/b.yml', 'w') as f:
f.write('AutoName: b')
rewritemeta.main()
with open('metadata/a.yml') as f:
self.assertEqual(f.read(), textwrap.dedent('''\
License: Unknown
AutoName: a
AutoUpdateMode: None
UpdateCheckMode: None
'''))
with open('metadata/b.yml') as f:
self.assertEqual(f.read(), textwrap.dedent('''\
License: Unknown
AutoName: b
AutoUpdateMode: None
UpdateCheckMode: None
'''))
def test_rewrite_scenario_yml_no_ruamel(self):
sys.argv = ['rewritemeta', 'a']
with tempfile.TemporaryDirectory() as tmpdir, TmpCwd(tmpdir):
os.mkdir('metadata')
with open('metadata/a.yml', 'w') as f:
f.write('AutoName: a')
def boom(*args):
raise FDroidException(' '.join((str(x) for x in args)))
with mock.patch('importlib.util.find_spec', boom):
with self.assertRaises(FDroidException):
rewritemeta.main()
with open('metadata/a.yml') as f:
self.assertEqual(f.read(), textwrap.dedent('''\
AutoName: a'''))
if __name__ == "__main__":
os.chdir(os.path.dirname(__file__))
parser = optparse.OptionParser()
parser.add_option("-v", "--verbose", action="store_true", default=False,
help="Spew out even more information than normal")
(common.options, args) = parser.parse_args(['--verbose'])
newSuite = unittest.TestSuite()
newSuite.addTest(unittest.makeSuite(RewriteMetaTest))
unittest.main(failfast=False)