mirror of
https://github.com/ail-project/ail-framework.git
synced 2025-01-18 16:36:13 +00:00
chg: [test] log if flask is reachable
This commit is contained in:
parent
b4491270b9
commit
d0f4247c2b
2 changed files with 40 additions and 6 deletions
|
@ -51,3 +51,24 @@ def get_access_config(create=False):
|
||||||
|
|
||||||
logger.propagate = False
|
logger.propagate = False
|
||||||
return logger
|
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
|
||||||
|
|
|
@ -5,30 +5,43 @@ import os
|
||||||
import sys
|
import sys
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from pyail import PyAIL
|
from pyail import PyAIL, PyAILError
|
||||||
|
|
||||||
sys.path.append(os.environ['AIL_BIN'])
|
sys.path.append(os.environ['AIL_BIN'])
|
||||||
##################################
|
##################################
|
||||||
# Import Project packages
|
# Import Project packages
|
||||||
##################################
|
##################################
|
||||||
from lib import ail_users
|
from lib import ail_users
|
||||||
|
from lib import ail_logger
|
||||||
from lib.ConfigLoader import ConfigLoader
|
from lib.ConfigLoader import ConfigLoader
|
||||||
|
|
||||||
|
test_logger = ail_logger.get_test_config(create=True)
|
||||||
|
|
||||||
class TestApiV1(unittest.TestCase):
|
class TestApiV1(unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
config = ConfigLoader()
|
config = ConfigLoader()
|
||||||
port = config.get_config_str('Flask', 'port')
|
port = config.get_config_str('Flask', 'port')
|
||||||
|
try:
|
||||||
self.ail = PyAIL(f'https://localhost:{port}', ail_users.get_user_token('admin@admin.test'), ssl=False)
|
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
|
# GET /api/v1/ping
|
||||||
def test_0001_api_ping(self):
|
def test_0001_api_ping(self):
|
||||||
r = self.ail.ping_ail()
|
|
||||||
self.assertEqual(r.get('status'), 'pong')
|
|
||||||
print()
|
print()
|
||||||
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('----------------------------------------------------')
|
||||||
print()
|
print()
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue