forked from shaba/openuds
Fixing up testing and make them usable from vscode sidebar
This commit is contained in:
parent
76745e8624
commit
01184582b3
3
server/src/pytest.ini
Normal file
3
server/src/pytest.ini
Normal file
@ -0,0 +1,3 @@
|
||||
[pytest]
|
||||
DJANGO_SETTINGS_MODULE = server.settings
|
||||
python_files = tests.py test_*.py *_tests.py
|
@ -37,6 +37,16 @@ DATABASES = {
|
||||
# 'CONN_MAX_AGE': 600, # Enable DB Pooling, 10 minutes max connection duration
|
||||
}
|
||||
}
|
||||
# If testing, with test or with pytest, use the local test database
|
||||
if any(arg.endswith('test') for arg in sys.argv):
|
||||
DATABASES['default'] = {
|
||||
'ENGINE': 'django.db.backends.sqlite3',
|
||||
'OPTIONS': {
|
||||
'timeout': 20,
|
||||
},
|
||||
'NAME': ':memory:',
|
||||
}
|
||||
|
||||
ALLOWED_HOSTS = ['*']
|
||||
|
||||
DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'
|
||||
|
@ -29,4 +29,4 @@
|
||||
"""
|
||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
"""
|
||||
from .login_logout import *
|
||||
from . import test_login_logout
|
@ -36,7 +36,7 @@ from django.test import TestCase
|
||||
from django.test.client import Client
|
||||
from django.conf import settings
|
||||
|
||||
from uds.tests import fixtures, tools
|
||||
from .. import fixtures, tools
|
||||
|
||||
|
||||
class RESTLoginLogoutCase(TestCase):
|
||||
@ -66,7 +66,7 @@ class RESTLoginLogoutCase(TestCase):
|
||||
|
||||
# Add users to some groups, ramdomly
|
||||
for user in users + admins + stafs:
|
||||
for group in random.sample(groups, random.randint(1, len(groups))):
|
||||
for group in random.sample(groups, random.randint(1, len(groups))): # nosec: Simple test, not strong cryptograde needed
|
||||
user.groups.add(group)
|
||||
|
||||
# All users, admin and staff must be able to login
|
34
server/src/tests/__init__.py
Normal file
34
server/src/tests/__init__.py
Normal file
@ -0,0 +1,34 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (c) 2022 Virtual Cable S.L.U.
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification,
|
||||
# are permitted provided that the following conditions are met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright notice,
|
||||
# this list of conditions and the following disclaimer.
|
||||
# * Redistributions in binary form must reproduce the above copyright notice,
|
||||
# this list of conditions and the following disclaimer in the documentation
|
||||
# and/or other materials provided with the distribution.
|
||||
# * Neither the name of Virtual Cable S.L.U. nor the names of its contributors
|
||||
# may be used to endorse or promote products derived from this software
|
||||
# without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
"""
|
||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
"""
|
||||
from . import core
|
||||
from . import web
|
||||
from . import messaging
|
||||
from . import REST
|
@ -28,5 +28,5 @@
|
||||
"""
|
||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
"""
|
||||
from .cache import *
|
||||
from .stats_counters import *
|
||||
from . import test_cache
|
||||
from . import test_stats_counters
|
@ -28,4 +28,4 @@
|
||||
"""
|
||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
"""
|
||||
from .notifier import *
|
||||
from . import test_notifier
|
@ -28,15 +28,11 @@
|
||||
"""
|
||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
"""
|
||||
import random
|
||||
import typing
|
||||
|
||||
|
||||
from django.test import TestCase
|
||||
from django.test.client import Client
|
||||
from django.conf import settings
|
||||
|
||||
from uds.tests import fixtures, tools
|
||||
from .. import fixtures, tools
|
||||
from uds.core import messaging
|
||||
|
||||
class TestEmailNotifier(TestCase):
|
||||
@ -44,7 +40,7 @@ class TestEmailNotifier(TestCase):
|
||||
Test Email Notifier
|
||||
"""
|
||||
|
||||
def setUp(self):
|
||||
def setUp(self) -> None:
|
||||
# Setup smtp server
|
||||
from aiosmtpd.controller import Controller
|
||||
from aiosmtpd.handlers import Debugging
|
||||
@ -56,11 +52,11 @@ class TestEmailNotifier(TestCase):
|
||||
)
|
||||
self.smtp_server.start()
|
||||
|
||||
def tearDown(self):
|
||||
def tearDown(self) -> None:
|
||||
# Stop smtp debug server
|
||||
self.smtp_server.stop()
|
||||
|
||||
def test_email_notifier(self):
|
||||
def test_email_notifier(self) -> None:
|
||||
"""
|
||||
Test email notifier
|
||||
"""
|
@ -28,3 +28,4 @@
|
||||
"""
|
||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
"""
|
||||
from . import user
|
@ -28,4 +28,4 @@
|
||||
"""
|
||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
"""
|
||||
from .login_logout import *
|
||||
from . import test_login_logout
|
@ -35,7 +35,7 @@ import typing
|
||||
from django.test import TestCase, TransactionTestCase
|
||||
from django.db import transaction
|
||||
|
||||
from uds.tests import fixtures, tools
|
||||
from ... import fixtures, tools
|
||||
|
||||
if typing.TYPE_CHECKING:
|
||||
from django.http import HttpResponse
|
||||
@ -89,7 +89,7 @@ class WebLoginLogoutCase(TransactionTestCase):
|
||||
|
||||
# Add users to some groups, ramdomly
|
||||
for user in users + admins + stafs:
|
||||
for group in random.sample(groups, random.randint(1, len(groups))):
|
||||
for group in random.sample(groups, random.randint(1, len(groups))): # nosec: Simple test, not strong cryptograde needed
|
||||
user.groups.add(group)
|
||||
|
||||
# All users, admin and staff must be able to login
|
@ -61,7 +61,7 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
__all__ = ['Handler', 'Dispatcher']
|
||||
|
||||
AUTH_TOKEN_HEADER = 'X-Auth-Token'
|
||||
AUTH_TOKEN_HEADER = 'X-Auth-Token' # nosec: this is not a password, but a header name
|
||||
|
||||
|
||||
class Dispatcher(View):
|
||||
|
@ -1,36 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (c) 2022 Virtual Cable S.L.
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification,
|
||||
# are permitted provided that the following conditions are met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright notice,
|
||||
# this list of conditions and the following disclaimer.
|
||||
# * Redistributions in binary form must reproduce the above copyright notice,
|
||||
# this list of conditions and the following disclaimer in the documentation
|
||||
# and/or other materials provided with the distribution.
|
||||
# * Neither the name of Virtual Cable S.L. nor the names of its contributors
|
||||
# may be used to endorse or promote products derived from this software
|
||||
# without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
"""
|
||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
"""
|
||||
|
||||
# Imports all possible automatic tests
|
||||
from .messaging import *
|
||||
from .REST import *
|
||||
from .web import *
|
||||
from .core import *
|
@ -1,31 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (c) 2022 Virtual Cable S.L.
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification,
|
||||
# are permitted provided that the following conditions are met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright notice,
|
||||
# this list of conditions and the following disclaimer.
|
||||
# * Redistributions in binary form must reproduce the above copyright notice,
|
||||
# this list of conditions and the following disclaimer in the documentation
|
||||
# and/or other materials provided with the distribution.
|
||||
# * Neither the name of Virtual Cable S.L. nor the names of its contributors
|
||||
# may be used to endorse or promote products derived from this software
|
||||
# without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
"""
|
||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
"""
|
||||
from .user import *
|
Loading…
Reference in New Issue
Block a user