chg: [test] log if flask is reachable

master
terrtia 2025-01-07 14:24:10 +01:00
parent b4491270b9
commit d0f4247c2b
No known key found for this signature in database
GPG Key ID: 1E1B1F50D84613D0
2 changed files with 40 additions and 6 deletions

View File

@ -51,3 +51,24 @@ def get_access_config(create=False):
logger.propagate = False
return logger
def get_test_config(create=False):
logger = logging.getLogger('test.log')
if create:
formatter = logging.Formatter("%(asctime)s %(levelname)s:%(message)s")
# STDOUT
handler = logging.StreamHandler()
handler.setLevel(logging.INFO)
logger.addHandler(handler)
# FILE
handler = logging.handlers.RotatingFileHandler(filename=os.path.join(LOGS_DIR, f'test.log'),
maxBytes=10*1024*1024, backupCount=5)
handler.setLevel(logging.INFO)
handler.setFormatter(formatter)
logger.addHandler(handler)
logger.propagate = False
return logger

View File

@ -5,30 +5,43 @@ import os
import sys
import unittest
from pyail import PyAIL
from pyail import PyAIL, PyAILError
sys.path.append(os.environ['AIL_BIN'])
##################################
# Import Project packages
##################################
from lib import ail_users
from lib import ail_logger
from lib.ConfigLoader import ConfigLoader
test_logger = ail_logger.get_test_config(create=True)
class TestApiV1(unittest.TestCase):
def setUp(self):
config = ConfigLoader()
port = config.get_config_str('Flask', 'port')
self.ail = PyAIL(f'https://localhost:{port}', ail_users.get_user_token('admin@admin.test'), ssl=False)
try:
self.ail = PyAIL(f'https://localhost:{port}', ail_users.get_user_token('admin@admin.test'), ssl=False)
except Exception as e:
print()
print('----------------------------------------------------')
test_logger.warning(f'Flask / Web interface is unreachable: {e}')
print('----------------------------------------------------')
print()
raise e
# GET /api/v1/ping
def test_0001_api_ping(self):
r = self.ail.ping_ail()
self.assertEqual(r.get('status'), 'pong')
print()
print('----------------------------------------------------')
print(' AIL successfully reached Flask / Web interface')
try:
r = self.ail.ping()
self.assertEqual(r.get('status'), 'pong')
test_logger.info('AIL successfully reached Flask / Web interface')
except (AssertionError, PyAILError) as ae:
test_logger.warning(f'Flask / Web interface is unreachable: {ae}')
print('----------------------------------------------------')
print()