2020-11-24 11:21:51 +01:00
|
|
|
"""
|
|
|
|
Usage:
|
|
|
|
$ python -m venv .venv
|
|
|
|
$ source .venv/bin/activate
|
|
|
|
$ pip install -r requirements-testing.txt -r requirements.txt
|
|
|
|
$ python ./quicktest.py
|
|
|
|
"""
|
2012-08-08 06:32:28 +02:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import argparse
|
2015-01-14 14:10:09 +01:00
|
|
|
|
|
|
|
import django
|
2012-08-08 06:32:28 +02:00
|
|
|
from django.conf import settings
|
|
|
|
|
2015-01-14 14:10:09 +01:00
|
|
|
|
2012-08-08 06:32:28 +02:00
|
|
|
class QuickDjangoTest(object):
|
|
|
|
"""
|
|
|
|
A quick way to run the Django test suite without a fully-configured project.
|
|
|
|
|
|
|
|
Example usage:
|
|
|
|
|
|
|
|
>>> QuickDjangoTest('app1', 'app2')
|
|
|
|
|
2014-07-21 10:21:33 +02:00
|
|
|
Based on a script published by Lukasz Dziedzia at:
|
2012-08-08 06:32:28 +02:00
|
|
|
http://stackoverflow.com/questions/3841725/how-to-launch-tests-for-django-reusable-app
|
|
|
|
"""
|
|
|
|
DIRNAME = os.path.dirname(__file__)
|
|
|
|
INSTALLED_APPS = (
|
2015-11-16 16:10:58 +01:00
|
|
|
'django.contrib.admin',
|
2012-08-08 06:32:28 +02:00
|
|
|
'django.contrib.auth',
|
|
|
|
'django.contrib.contenttypes',
|
2015-11-16 16:10:58 +01:00
|
|
|
'django.contrib.humanize',
|
|
|
|
'django.contrib.messages',
|
2012-08-08 06:32:28 +02:00
|
|
|
'django.contrib.sessions',
|
2015-11-16 16:10:58 +01:00
|
|
|
'django.contrib.sites',
|
2012-08-08 06:32:28 +02:00
|
|
|
'django.contrib.staticfiles',
|
2019-03-25 17:40:02 +01:00
|
|
|
'bootstrap4form',
|
2022-07-12 12:34:19 +02:00
|
|
|
# The following commented apps are optional,
|
|
|
|
# related to teams functionalities
|
2021-08-04 15:26:32 +02:00
|
|
|
#'account',
|
|
|
|
#'pinax.invitations',
|
|
|
|
#'pinax.teams',
|
2022-04-22 20:52:51 +02:00
|
|
|
'rest_framework',
|
2019-03-25 17:40:02 +01:00
|
|
|
'helpdesk',
|
2021-08-04 15:26:32 +02:00
|
|
|
#'reversion',
|
2012-08-08 06:32:28 +02:00
|
|
|
)
|
2017-12-28 13:23:51 +01:00
|
|
|
MIDDLEWARE = [
|
|
|
|
'django.middleware.security.SecurityMiddleware',
|
2015-01-14 15:54:39 +01:00
|
|
|
'django.contrib.sessions.middleware.SessionMiddleware',
|
2015-01-14 15:49:08 +01:00
|
|
|
'django.middleware.common.CommonMiddleware',
|
|
|
|
'django.middleware.csrf.CsrfViewMiddleware',
|
|
|
|
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
|
|
|
'django.contrib.messages.middleware.MessageMiddleware',
|
2015-01-14 15:54:39 +01:00
|
|
|
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
2015-01-14 15:49:08 +01:00
|
|
|
]
|
2012-08-08 06:32:28 +02:00
|
|
|
|
2016-10-20 08:26:06 +02:00
|
|
|
TEMPLATES = [
|
|
|
|
{
|
|
|
|
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
|
|
|
'APP_DIRS': True,
|
|
|
|
'OPTIONS': {
|
|
|
|
'context_processors': (
|
|
|
|
# Defaults:
|
|
|
|
"django.contrib.auth.context_processors.auth",
|
|
|
|
"django.template.context_processors.debug",
|
|
|
|
"django.template.context_processors.i18n",
|
|
|
|
"django.template.context_processors.media",
|
|
|
|
"django.template.context_processors.static",
|
|
|
|
"django.template.context_processors.tz",
|
|
|
|
"django.contrib.messages.context_processors.messages",
|
|
|
|
# Our extra:
|
|
|
|
"django.template.context_processors.request",
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
]
|
2018-08-30 12:03:54 +02:00
|
|
|
|
2012-08-08 06:32:28 +02:00
|
|
|
def __init__(self, *args, **kwargs):
|
2019-03-25 17:40:02 +01:00
|
|
|
self.tests = args
|
2016-11-21 01:32:56 +01:00
|
|
|
self._tests()
|
2012-08-08 06:32:28 +02:00
|
|
|
|
2016-11-21 01:32:56 +01:00
|
|
|
def _tests(self):
|
2015-01-14 15:36:37 +01:00
|
|
|
|
2012-08-08 06:32:28 +02:00
|
|
|
settings.configure(
|
2016-10-24 08:04:31 +02:00
|
|
|
DEBUG=True,
|
2020-04-15 11:18:37 +02:00
|
|
|
TIME_ZONE='UTC',
|
2016-10-24 08:04:31 +02:00
|
|
|
DATABASES={
|
2012-08-08 06:32:28 +02:00
|
|
|
'default': {
|
|
|
|
'ENGINE': 'django.db.backends.sqlite3',
|
|
|
|
'NAME': os.path.join(self.DIRNAME, 'database.db'),
|
|
|
|
'USER': '',
|
|
|
|
'PASSWORD': '',
|
|
|
|
'HOST': '',
|
|
|
|
'PORT': '',
|
|
|
|
}
|
|
|
|
},
|
2019-03-25 17:40:02 +01:00
|
|
|
INSTALLED_APPS=self.INSTALLED_APPS,
|
2017-12-28 13:23:51 +01:00
|
|
|
MIDDLEWARE=self.MIDDLEWARE,
|
2016-10-24 08:04:31 +02:00
|
|
|
ROOT_URLCONF='helpdesk.tests.urls',
|
|
|
|
STATIC_URL='/static/',
|
2022-06-20 17:26:52 +02:00
|
|
|
LOGIN_URL='/login/',
|
2018-08-30 12:03:54 +02:00
|
|
|
TEMPLATES=self.TEMPLATES,
|
2021-08-04 15:38:28 +02:00
|
|
|
SITE_ID=1,
|
2021-10-19 05:05:03 +02:00
|
|
|
SECRET_KEY='wowdonotusethisfakesecuritykeyyouneedarealsecure1',
|
2022-07-12 12:34:19 +02:00
|
|
|
# The following settings disable teams
|
|
|
|
HELPDESK_TEAMS_MODEL='auth.User',
|
|
|
|
HELPDESK_TEAMS_MIGRATION_DEPENDENCIES=[],
|
|
|
|
HELPDESK_KBITEM_TEAM_GETTER=lambda _: None,
|
|
|
|
# test the API
|
2022-04-22 20:52:51 +02:00
|
|
|
HELPDESK_ACTIVATE_API_ENDPOINT=True
|
2012-08-08 06:32:28 +02:00
|
|
|
)
|
2015-01-14 15:36:37 +01:00
|
|
|
|
2016-11-21 01:32:56 +01:00
|
|
|
from django.test.runner import DiscoverRunner
|
|
|
|
test_runner = DiscoverRunner(verbosity=1)
|
|
|
|
django.setup()
|
2015-01-14 14:10:09 +01:00
|
|
|
|
2019-03-25 17:40:02 +01:00
|
|
|
failures = test_runner.run_tests(self.tests)
|
2012-08-08 06:32:28 +02:00
|
|
|
if failures:
|
|
|
|
sys.exit(failures)
|
|
|
|
|
2020-11-24 11:21:51 +01:00
|
|
|
|
2012-08-08 06:32:28 +02:00
|
|
|
if __name__ == '__main__':
|
|
|
|
"""
|
|
|
|
What do when the user hits this file from the shell.
|
|
|
|
|
|
|
|
Example usage:
|
|
|
|
|
2019-03-25 17:40:02 +01:00
|
|
|
$ python quicktest.py test1 test2
|
2012-08-08 06:32:28 +02:00
|
|
|
|
|
|
|
"""
|
|
|
|
parser = argparse.ArgumentParser(
|
|
|
|
usage="[args]",
|
2019-03-25 17:40:02 +01:00
|
|
|
description="Run Django tests."
|
2012-08-08 06:32:28 +02:00
|
|
|
)
|
2019-03-25 17:45:42 +01:00
|
|
|
parser.add_argument('tests', nargs="*", type=str)
|
2012-08-08 06:32:28 +02:00
|
|
|
args = parser.parse_args()
|
2019-03-25 17:45:42 +01:00
|
|
|
if not args.tests:
|
|
|
|
args.tests = ['helpdesk']
|
2019-03-25 17:40:02 +01:00
|
|
|
QuickDjangoTest(*args.tests)
|