summaryrefslogtreecommitdiff
path: root/tests/__init__.py
diff options
context:
space:
mode:
authorCharles Oliveira <charles.oliveira@linaro.org>2020-03-11 16:48:21 -0300
committerCharles Oliveira <charles.oliveira@linaro.org>2020-03-23 19:25:31 -0300
commit381a89d7517cd7e4f70591d4ea053d72aceedb80 (patch)
tree4393364fb012cbe4184cc204095a9b02fd4f4776 /tests/__init__.py
parent3a1aab9581b2ae714f7032d8450f355847a63c83 (diff)
tests: start local squad server to support testing
Start a local instance of SQUAD so that Squad-Client tests can run against it. Add fixtures file, which provides all necessary data to be tested in squad-client. The mechanism is pretty simple, before every call to `./manage.py test`, a fresh squad instance is started up and run that file so that all data is available thru the api
Diffstat (limited to 'tests/__init__.py')
-rw-r--r--tests/__init__.py35
1 files changed, 28 insertions, 7 deletions
diff --git a/tests/__init__.py b/tests/__init__.py
index 4b43dfe..159726e 100644
--- a/tests/__init__.py
+++ b/tests/__init__.py
@@ -1,9 +1,30 @@
-import unittest
-import os
+import subprocess as sp
-def run():
- loader = unittest.TestLoader()
- tests = loader.discover(os.path.dirname(os.path.abspath(__file__)))
- testRunner = unittest.runner.TextTestRunner()
- testRunner.run(tests)
+from squad_client.core.api import SquadApi
+from .squad_service import SquadService
+
+
+def run(coverage=False, tests=['discover'], verbose=False):
+ squad_service = SquadService()
+ if not squad_service.start() or not squad_service.apply_fixtures('tests/fixtures.py'):
+ print('Aborting tests!')
+ return False
+
+ SquadApi.configure(url=squad_service.host)
+
+ argv = ['-m', 'unittest'] + tests
+ if len(tests) == 0 and verbose:
+ argv += ['discover', '-v']
+
+ if coverage:
+ print('\t --coverage is enabled, run `coverage report -m` to view coverage report')
+ argv = ['coverage', 'run', '--source', 'squad_client'] + argv
+ else:
+ argv = ['python3'] + argv
+
+ proc = sp.Popen(argv)
+ proc.wait()
+
+ squad_service.stop()
+ return proc.returncode == 0