2016-01-04 21:17:58 +01:00
|
|
|
#!/usr/bin/env python3
|
2015-08-06 00:55:16 +02:00
|
|
|
|
|
|
|
# http://www.drdobbs.com/testing/unit-testing-with-python/240165163
|
|
|
|
|
|
|
|
import inspect
|
2017-11-30 10:14:38 +01:00
|
|
|
import logging
|
2015-08-06 00:55:16 +02:00
|
|
|
import optparse
|
|
|
|
import os
|
2016-09-15 08:29:18 +02:00
|
|
|
import requests
|
2020-01-31 23:49:50 +01:00
|
|
|
import shutil
|
2015-08-06 00:55:16 +02:00
|
|
|
import sys
|
2020-01-31 23:49:50 +01:00
|
|
|
import tempfile
|
2015-08-06 00:55:16 +02:00
|
|
|
import unittest
|
2020-01-31 23:49:50 +01:00
|
|
|
from unittest import mock
|
2015-08-06 00:55:16 +02:00
|
|
|
|
|
|
|
localmodule = os.path.realpath(
|
2021-06-07 11:49:21 +02:00
|
|
|
os.path.join(os.path.dirname(inspect.getfile(inspect.currentframe())), '..')
|
|
|
|
)
|
2015-08-06 00:55:16 +02:00
|
|
|
print('localmodule: ' + localmodule)
|
|
|
|
if localmodule not in sys.path:
|
|
|
|
sys.path.insert(0, localmodule)
|
|
|
|
|
|
|
|
import fdroidserver.common
|
|
|
|
import fdroidserver.metadata
|
2021-06-07 11:49:21 +02:00
|
|
|
|
2015-08-06 00:55:16 +02:00
|
|
|
# work around the syntax error from: import fdroidserver.import
|
|
|
|
import import_proxy
|
|
|
|
|
|
|
|
|
|
|
|
class ImportTest(unittest.TestCase):
|
|
|
|
'''fdroid import'''
|
|
|
|
|
2017-11-30 10:14:38 +01:00
|
|
|
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)
|
|
|
|
|
2015-08-06 00:55:16 +02:00
|
|
|
def test_import_gitlab(self):
|
|
|
|
# FDroidPopen needs some config to work
|
2015-08-05 14:39:58 +02:00
|
|
|
config = dict()
|
|
|
|
fdroidserver.common.fill_config_defaults(config)
|
|
|
|
fdroidserver.common.config = config
|
2015-08-06 00:55:16 +02:00
|
|
|
|
2017-01-09 15:12:27 +01:00
|
|
|
url = 'https://gitlab.com/fdroid/ci-test-app'
|
2016-09-15 08:29:18 +02:00
|
|
|
r = requests.head(url)
|
|
|
|
if r.status_code != 200:
|
|
|
|
print("ERROR", url, 'unreachable (', r.status_code, ')')
|
|
|
|
print('Skipping ImportTest!')
|
|
|
|
return
|
|
|
|
|
2020-02-26 17:07:12 +01:00
|
|
|
app = fdroidserver.common.get_app_from_url(url)
|
2020-02-03 12:39:41 +01:00
|
|
|
import_proxy.clone_to_tmp_dir(app)
|
2016-06-10 12:02:03 +02:00
|
|
|
self.assertEqual(app.RepoType, 'git')
|
2017-01-09 15:12:27 +01:00
|
|
|
self.assertEqual(app.Repo, 'https://gitlab.com/fdroid/ci-test-app.git')
|
2015-08-06 00:55:16 +02:00
|
|
|
|
2020-02-03 12:39:41 +01:00
|
|
|
def test_get_app_from_url(self):
|
2021-06-07 11:49:21 +02:00
|
|
|
testdir = tempfile.mkdtemp(
|
|
|
|
prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir
|
|
|
|
)
|
2020-01-31 23:49:50 +01:00
|
|
|
os.chdir(testdir)
|
|
|
|
os.mkdir(os.path.join(testdir, 'tmp'))
|
|
|
|
tmp_importer = os.path.join(testdir, 'tmp', 'importer')
|
|
|
|
data = (
|
2021-06-07 11:49:21 +02:00
|
|
|
(
|
|
|
|
'cn.wildfirechat.chat',
|
|
|
|
'https://github.com/wildfirechat/android-chat',
|
|
|
|
'0.6.9',
|
|
|
|
'23',
|
|
|
|
),
|
|
|
|
(
|
|
|
|
'com.anpmech.launcher',
|
|
|
|
'https://github.com/KeikaiLauncher/KeikaiLauncher',
|
|
|
|
'Unknown',
|
|
|
|
None,
|
|
|
|
),
|
|
|
|
(
|
|
|
|
'ut.ewh.audiometrytest',
|
|
|
|
'https://github.com/ReeceStevens/ut_ewh_audiometer_2014',
|
|
|
|
'1.65',
|
|
|
|
'14',
|
|
|
|
),
|
2020-01-31 23:49:50 +01:00
|
|
|
)
|
|
|
|
for appid, url, vn, vc in data:
|
|
|
|
shutil.rmtree(tmp_importer, ignore_errors=True)
|
2021-06-07 11:49:21 +02:00
|
|
|
shutil.copytree(
|
|
|
|
os.path.join(self.basedir, 'source-files', appid), tmp_importer
|
|
|
|
)
|
2020-01-31 23:49:50 +01:00
|
|
|
|
2020-02-26 17:07:12 +01:00
|
|
|
app = fdroidserver.common.get_app_from_url(url)
|
2020-01-31 23:49:50 +01:00
|
|
|
with mock.patch('fdroidserver.common.getvcs',
|
|
|
|
lambda a, b, c: fdroidserver.common.vcs(url, testdir)):
|
|
|
|
with mock.patch('fdroidserver.common.vcs.gotorevision',
|
|
|
|
lambda s, rev: None):
|
|
|
|
with mock.patch('shutil.rmtree', lambda a: None):
|
2020-02-03 12:39:41 +01:00
|
|
|
build_dir = import_proxy.clone_to_tmp_dir(app)
|
2020-01-31 23:49:50 +01:00
|
|
|
self.assertEqual('git', app.RepoType)
|
|
|
|
self.assertEqual(url, app.Repo)
|
|
|
|
self.assertEqual(url, app.SourceCode)
|
|
|
|
logging.info(build_dir)
|
2020-02-26 17:07:12 +01:00
|
|
|
paths = fdroidserver.common.get_all_gradle_and_manifests(build_dir)
|
2020-01-31 23:49:50 +01:00
|
|
|
self.assertNotEqual(paths, [])
|
|
|
|
versionName, versionCode, package = fdroidserver.common.parse_androidmanifests(paths, app)
|
|
|
|
self.assertEqual(vn, versionName)
|
|
|
|
self.assertEqual(vc, versionCode)
|
|
|
|
self.assertEqual(appid, package)
|
|
|
|
|
2015-08-06 00:55:16 +02:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2018-08-14 10:34:13 +02:00
|
|
|
os.chdir(os.path.dirname(__file__))
|
|
|
|
|
2015-08-06 00:55:16 +02:00
|
|
|
parser = optparse.OptionParser()
|
2021-06-07 11:49:21 +02:00
|
|
|
parser.add_option(
|
|
|
|
"-v",
|
|
|
|
"--verbose",
|
|
|
|
action="store_true",
|
|
|
|
default=False,
|
|
|
|
help="Spew out even more information than normal",
|
|
|
|
)
|
2015-08-06 00:55:16 +02:00
|
|
|
(fdroidserver.common.options, args) = parser.parse_args(['--verbose'])
|
|
|
|
|
|
|
|
newSuite = unittest.TestSuite()
|
|
|
|
newSuite.addTest(unittest.makeSuite(ImportTest))
|
2017-10-20 11:51:59 +02:00
|
|
|
unittest.main(failfast=False)
|