From 1e01a30479093b1b3e298e89776102fecba4851f Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Mon, 22 Apr 2024 12:08:36 +0200 Subject: [PATCH] Adding test/test_30_apps.py for simple tests on some base application classes. --- test/test_30_apps.py | 162 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 162 insertions(+) create mode 100755 test/test_30_apps.py diff --git a/test/test_30_apps.py b/test/test_30_apps.py new file mode 100755 index 0000000..f04d1cb --- /dev/null +++ b/test/test_30_apps.py @@ -0,0 +1,162 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +""" +@summary: Test script (and module) for unit tests on application classes. + +@author: Frank Brehm +@contact: frank.brehm@pixelpark.com +@copyright: © 2024 by Frank Brehm, Berlin +@license: GPL3 +""" + +import logging +import os +import sys +import textwrap + +try: + import unittest2 as unittest +except ImportError: + import unittest + +TEST_PGSQL_APP = False +try: + import psycopg2 # noqa: F401 + TEST_PGSQL_APP = True +except ImportError: + pass + +# from babel.dates import LOCALTZ + +libdir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'lib')) +sys.path.insert(0, libdir) + +# from fb_tools.common import pp, to_str, is_sequence +# from fb_tools.common import pp + +from general import PpAdminToolsTestcase, get_arg_verbose, init_root_logger + +APPNAME = 'test-apps' +LOG = logging.getLogger(APPNAME) + + +# ============================================================================= +class TestAppClasses(PpAdminToolsTestcase): + """Testcase for unit tests on application classes.""" + + # ------------------------------------------------------------------------- + def setUp(self): + """Execute this on setting up before calling each particular test method.""" + if self.verbose >= 1: + print() + + self._appname = APPNAME + + # ------------------------------------------------------------------------- + def tearDown(self): + """Execute this after calling each particular test method.""" + pass + + # ------------------------------------------------------------------------- + def test_base_app(self): + """Test importing module pp_admintools.app.""" + LOG.info(self.get_method_doc()) + + import pp_admintools.app + version = pp_admintools.app.__version__ + LOG.debug('Version of pp_admintools.app: ' + version) + + LOG.info( + 'Testing import of BaseDPXApplication from pp_admintools.app ...') + from pp_admintools.app import BaseDPXApplication + the_doc = textwrap.dedent(BaseDPXApplication.__doc__) + LOG.debug('Description of BaseDPXApplication: ' + the_doc) + + # ------------------------------------------------------------------------- + def test_base_ldap_app(self): + """Test importing module pp_admintools.app.ldap.""" + LOG.info(self.get_method_doc()) + + import pp_admintools.app.ldap + version = pp_admintools.app.ldap.__version__ + LOG.debug('Version of pp_admintools.app.ldap: ' + version) + + LOG.info( + 'Testing import of BaseLdapApplication from pp_admintools.app.ldap ...') + from pp_admintools.app.ldap import BaseLdapApplication + the_doc = textwrap.dedent(BaseLdapApplication.__doc__) + LOG.debug('Description of BaseLdapApplication: ' + the_doc) + + # ------------------------------------------------------------------------- + def test_base_mail_app(self): + """Test importing module pp_admintools.app.mail.""" + LOG.info(self.get_method_doc()) + + import pp_admintools.app.mail + version = pp_admintools.app.mail.__version__ + LOG.debug('Version of pp_admintools.app.mail: ' + version) + + LOG.info( + 'Testing import of BaseMailApplication from pp_admintools.app.mail ...') + from pp_admintools.app.mail import BaseMailApplication + the_doc = textwrap.dedent(BaseMailApplication.__doc__) + LOG.debug('Description of BaseMailApplication: ' + the_doc) + + # ------------------------------------------------------------------------- + def test_base_pdns_app(self): + """Test importing module pp_admintools.app.pdns.""" + LOG.info(self.get_method_doc()) + + import pp_admintools.app.pdns + version = pp_admintools.app.pdns.__version__ + LOG.debug('Version of pp_admintools.app.pdns: ' + version) + + LOG.info( + 'Testing import of PpPDNSApplication from pp_admintools.app.pdns ...') + from pp_admintools.app.pdns import PpPDNSApplication + the_doc = textwrap.dedent(PpPDNSApplication.__doc__) + LOG.debug('Description of PpPDNSApplication: ' + the_doc) + + # ------------------------------------------------------------------------- + @unittest.skipUnless(TEST_PGSQL_APP, 'Cannot test, module psycopg2 could not be imported.') + def test_base_pgsql_app(self): + """Test importing module pp_admintools.app.pgsql.""" + LOG.info(self.get_method_doc()) + + import pp_admintools.app.pgsql + version = pp_admintools.app.pgsql.__version__ + LOG.debug('Version of pp_admintools.app.pgsql: ' + version) + + LOG.info( + 'Testing import of BasePgsqlApplication from pp_admintools.app.pgsql ...') + from pp_admintools.app.pgsql import BasePgsqlApplication + the_doc = textwrap.dedent(BasePgsqlApplication.__doc__) + LOG.debug('Description of BasePgsqlApplication: ' + the_doc) + + +# ============================================================================= +if __name__ == '__main__': + + verbose = get_arg_verbose() + if verbose is None: + verbose = 0 + init_root_logger(verbose) + + LOG.info('Starting tests ...') + + suite = unittest.TestSuite() + + suite.addTest(TestAppClasses('test_base_app', verbose)) + suite.addTest(TestAppClasses('test_base_ldap_app', verbose)) + suite.addTest(TestAppClasses('test_base_mail_app', verbose)) + suite.addTest(TestAppClasses('test_base_pdns_app', verbose)) + suite.addTest(TestAppClasses('test_base_pgsql_app', verbose)) + + runner = unittest.TextTestRunner(verbosity=verbose) + + result = runner.run(suite) + + +# ============================================================================= + +# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 list -- 2.39.5