Commit 9ec83a11 authored by Johan Bloemberg's avatar Johan Bloemberg

add some changes from ssl_scan_task

parent 174ecc8b
# create/load python3 virtualenv when entering directory
layout python3
# enable DEBUG mode by default
export DEBUG=1
......@@ -29,14 +29,25 @@ class TaskCommand(BaseCommand):
"""
task = None
# it is a anti-pattern to instantiate empty lists/dicts as class parameters
# but since management commands are contained in their own invocation this can fly
args = list()
kwargs = dict()
def add_arguments(self, parser):
"""Add common argument for Celery tasks."""
parser.add_argument('-m', '--method', choices=['direct', 'sync', 'async'])
parser.add_argument(
'-m',
'--method',
choices=[
'direct',
'sync',
'async'],
default='direct',
help='Execute the task directly or via Celery queues.')
def handle(self, *args, **options):
"""Command handle logic, eg: logging."""
# set django loglevel based on `-v` argument
verbosity = int(options['verbosity'])
root_logger = logging.getLogger('')
......@@ -48,11 +59,12 @@ class TaskCommand(BaseCommand):
root_logger.setLevel(logging.ERROR)
# execute task based on selected method
if options['method'] == 'sync':
self.task.apply_async().get()
elif options['method'] == 'async':
task_id = self.task.apply_async()
if options['method'] in ['sync', 'async']:
task_id = self.task.apply_async(args=self.args, kwargs=self.kwargs)
log.info('Task %s scheduled for execution.', task_id)
if options['method'] == 'sync':
return task_id.get()
else:
# by default execute the task directly without involving celery or a broker
self.task()
return self.task(*self.args, **self.kwargs)
......@@ -4,6 +4,10 @@ isort
pylama
pytest-cov
pytest-django
# counterpart of requests for mock responses
pytest-responses
# output logging when test fails
pytest-logging
django-coverage
django-extensions
......
......@@ -19,8 +19,6 @@ passenv =
DB_ENGINE
commands =
# check migrations
failmap-admin migrate
# run testsuite
coverage run --include 'failmap_admin/*' -m pytest {posargs}
# generate coverage
......@@ -32,7 +30,7 @@ commands =
# make sure code quality is up to par
pylama failmap_admin tests setup.py
# ensure all datasets can be imported
# ensure all datasets can be imported (and indirectly if all migrations work)
[testenv:datasets]
commands =
# find all fixtures in source and verify loading each one
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment