Skip to content

Commit

Permalink
chg: [test] log if flask is reachable
Browse files Browse the repository at this point in the history
  • Loading branch information
Terrtia committed Jan 7, 2025
1 parent b449127 commit d0f4247
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 6 deletions.
21 changes: 21 additions & 0 deletions bin/lib/ail_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
25 changes: 19 additions & 6 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,43 @@
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()

Expand Down

0 comments on commit d0f4247

Please sign in to comment.