From 381a89d7517cd7e4f70591d4ea053d72aceedb80 Mon Sep 17 00:00:00 2001 From: Charles Oliveira Date: Wed, 11 Mar 2020 16:48:21 -0300 Subject: 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 --- tests/__init__.py | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) (limited to 'tests/__init__.py') 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 -- cgit v1.2.3