1
0
mirror of https://github.com/dkmstr/openuds.git synced 2025-03-11 00:58:39 +03:00

Minor fixes and added a "vars.py" utility for specific servers (with auth info) tests

This commit is contained in:
Adolfo Gómez García 2024-05-08 22:02:13 +02:00
parent 56cdee2b0d
commit 77e45099d1
No known key found for this signature in database
GPG Key ID: DD1ABF20724CDA23
5 changed files with 67 additions and 4 deletions

1
.gitignore vendored
View File

@ -167,3 +167,4 @@
.python-version
target/
server/test-vars.ini

View File

@ -7,6 +7,7 @@ python_classes =
# If coverage is enabled, debug test will not work on vscode
#addopts = --cov --cov-report html --cov-config=coverage.ini -n 12
#addopts = --cov --cov-report html --cov-config=coverage.ini -n 12
# addopts = -n 12
filterwarnings =
error
ignore:The --rsyncdir command line argument and rsyncdirs config variable are deprecated.:DeprecationWarning

View File

@ -40,7 +40,7 @@ DEFAULT_CACHE_TIMEOUT: typing.Final[int] = BASE_CACHE_TIMEOUT * 60 # 3 minutes
LONG_CACHE_TIMEOUT: typing.Final[int] = BASE_CACHE_TIMEOUT * 60 * 60 # 1 hour
EXTREME_CACHE_TIMEOUT: typing.Final[int] = BASE_CACHE_TIMEOUT * 60 * 60 * 24 # 1 day
SHORT_CACHE_TIMEOUT: typing.Final[int] = BASE_CACHE_TIMEOUT * 20 # 1 minute
SHORTEST_CACHE_TIMEOUT: typing.Final[int] = BASE_CACHE_TIMEOUT # 6 seconds
SHORTEST_CACHE_TIMEOUT: typing.Final[int] = BASE_CACHE_TIMEOUT # 3 seconds
# Used to mark a cache as not found
# use "cache.get(..., default=CACHE_NOT_FOUND)" to check if a cache is non existing instead of real None value

View File

@ -30,7 +30,6 @@ Author: Adolfo Gómez, dkmaster at dkmon dot com
"""
# pyright: reportUnknownMemberType=false
import typing
import collections.abc
import logging
from django.test import TestCase, TransactionTestCase
@ -52,8 +51,6 @@ class UDSHttpResponse(HttpResponse):
Custom response class to be able to access the response content
"""
url: str
def __init__(self, content: bytes, *args: typing.Any, **kwargs: typing.Any) -> None:
super().__init__(content, *args, **kwargs)

View File

@ -0,0 +1,64 @@
# -*- 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
"""
# pyright: reportUnknownMemberType=false
import typing
import logging
import configparser
logger = logging.getLogger(__name__)
# VARS is {SECTION: {VARIABLE: VALUE}}
config: configparser.ConfigParser = configparser.ConfigParser()
VAR_FILE: typing.Final[str] = 'test-vars.ini'
def load() -> None:
if config.sections():
return
try:
config.read(VAR_FILE)
except configparser.Error:
pass # Ignore errors, no vars will be loaded
def get_vars(section: str) -> typing.Dict[str, str]:
load() # Ensure vars are loaded
try:
v = dict(config[section])
if v.get('enabled', 'false') == 'false':
logger.info('Section %s is disabled (use enabled=true to enable it on %s file)', section, VAR_FILE)
return {} # If section is disabled, return empty dict
return v
except KeyError:
return {}