chiark / gitweb /
update: handle APKs with a blank versionName
[fdroidserver.git] / tests / import.TestCase
1 #!/usr/bin/env python3
2
3 # http://www.drdobbs.com/testing/unit-testing-with-python/240165163
4
5 import inspect
6 import logging
7 import optparse
8 import os
9 import requests
10 import sys
11 import unittest
12
13 localmodule = os.path.realpath(
14     os.path.join(os.path.dirname(inspect.getfile(inspect.currentframe())), '..'))
15 print('localmodule: ' + localmodule)
16 if localmodule not in sys.path:
17     sys.path.insert(0, localmodule)
18
19 import fdroidserver.common
20 import fdroidserver.metadata
21 # work around the syntax error from: import fdroidserver.import
22 import import_proxy
23
24
25 class ImportTest(unittest.TestCase):
26     '''fdroid import'''
27
28     def setUp(self):
29         logging.basicConfig(level=logging.DEBUG)
30         self.basedir = os.path.join(localmodule, 'tests')
31         self.tmpdir = os.path.abspath(os.path.join(self.basedir, '..', '.testfiles'))
32         if not os.path.exists(self.tmpdir):
33             os.makedirs(self.tmpdir)
34         os.chdir(self.basedir)
35
36     def test_import_gitlab(self):
37         # FDroidPopen needs some config to work
38         config = dict()
39         fdroidserver.common.fill_config_defaults(config)
40         fdroidserver.common.config = config
41
42         url = 'https://gitlab.com/fdroid/ci-test-app'
43         r = requests.head(url)
44         if r.status_code != 200:
45             print("ERROR", url, 'unreachable (', r.status_code, ')')
46             print('Skipping ImportTest!')
47             return
48
49         app = fdroidserver.metadata.App()
50         app.UpdateCheckMode = "Tags"
51         root_dir, src_dir = import_proxy.get_metadata_from_url(app, url)
52         self.assertEqual(app.RepoType, 'git')
53         self.assertEqual(app.WebSite, 'https://gitlab.com/fdroid/ci-test-app')
54         self.assertEqual(app.Repo, 'https://gitlab.com/fdroid/ci-test-app.git')
55
56
57 if __name__ == "__main__":
58     parser = optparse.OptionParser()
59     parser.add_option("-v", "--verbose", action="store_true", default=False,
60                       help="Spew out even more information than normal")
61     (fdroidserver.common.options, args) = parser.parse_args(['--verbose'])
62
63     newSuite = unittest.TestSuite()
64     newSuite.addTest(unittest.makeSuite(ImportTest))
65     unittest.main(failfast=False)