#!/usr/bin/python # -*- coding: utf-8 -*- # --------------------------------------------------------------------------------------------------------- # Author : Ulrich Carmesin # Source : gitea.ucarmesin.de # https://ucarmesin.de/index.php/it/testautomatisierung-fuer-daten-test/225-konfiguration-der-testanwendung # --------------------------------------------------------------------------------------------------------- import sys import basic.constants as B import unittest import os import inspect import utils.config_tool import utils.conn_tool import test.constants as T import test.testtools import utils.path_const as P import basic.constants as B TEST_FUNCTIONS = ["test_01getConfig", "test_02mergeAttributes", "test_03getAttributes"] #TEST_FUNCTIONS = ["test_03getAttributes"] verbose = False class MyTestCase(unittest.TestCase): mymsg = "--------------------------------------------------------------" def test_01getConfig(self): global mymsg actfunction = str(inspect.currentframe().f_code.co_name) cnttest = 0 if actfunction not in TEST_FUNCTIONS: return job = test.testtools.getJob() x = B.SUBJECT_APPS r = utils.config_tool.getConfigPath(job, P.KEY_BASIC, x) self.assertIn(os.path.join(T.COMP_PATH, P.VAL_CONFIG, B.SUBJECT_APPS), r) cnttest += 1 x = "path" r = utils.config_tool.getConfigPath(job, P.KEY_TOOL, x) self.assertIn(os.path.join(T.PROG_PATH, P.VAL_UTIL, P.VAL_CONFIG), r) cnttest += 1 x = "conn" r = utils.config_tool.getConfigPath(job, P.KEY_TOOL, x) self.assertIn(os.path.join(job.conf.getPath(P.ATTR_PATH_ENV)), r) cnttest += 1 self.assertRaises(Exception, utils.config_tool.getConfigPath, (job, P.KEY_COMP, "TestX2")) # self.assertEqual(r, None) cnttest += 1 r = utils.config_tool.getConfigPath(job, P.KEY_COMP, "testcrm") self.assertIn(os.path.join(job.conf.getPath(P.ATTR_PATH_COMPONENTS), "testcrm", "CONFIG"), r) r = utils.config_tool.getConfig(job, P.KEY_TOOL, "path") if verbose: print("pattern " + r["pattern"]["log"]) if verbose: print("pattern " + r["pattern"]["precond"]) MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest) def test_02mergeAttributes(self): global mymsg actfunction = str(inspect.currentframe().f_code.co_name) cnttest = 0 if actfunction not in TEST_FUNCTIONS: return job = test.testtools.getJob() componentName = "testcm" confs = utils.config_tool.getConfig(job, "comp", componentName) conns = utils.conn_tool.getConnections(job, componentName) self.assertEqual(confs["conf"][B.SUBJECT_INST][B.ATTR_INST_CNT], 1) self.assertEqual(conns[0][B.SUBJECT_INST][B.ATTR_INST_CNT], 2) self.assertNotIn(B.ATTR_INST_SGL, conns[0][B.SUBJECT_INST]) confs["conf"] = utils.config_tool.mergeConn(job.m, confs["conf"], conns[0]) self.assertEqual(confs["conf"][B.SUBJECT_INST][B.ATTR_INST_CNT], 2) cnttest += 1 # it overwrites self.assertEqual(confs["conf"][B.SUBJECT_INST][B.ATTR_INST_SGL], "n") cnttest += 1 # it keep componentName = "testprddb" confs = utils.config_tool.getConfig(job, "comp", componentName) conns = utils.conn_tool.getConnections(job, componentName) self.assertNotIn(B.ATTR_ARTS_TYPE, confs["conf"][B.SUBJECT_ARTS][B.TOPIC_NODE_DB]) confs["conf"] = utils.config_tool.mergeConn(job.m, confs["conf"], conns[0]) self.assertIn(B.ATTR_ARTS_TYPE, confs["conf"][B.SUBJECT_ARTS][B.TOPIC_NODE_DB]) cnttest += 1 # new attribute MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest) def test_03getAttributes(self): global mymsg actfunction = str(inspect.currentframe().f_code.co_name) cnttest = 0 if actfunction not in TEST_FUNCTIONS: return job = test.testtools.getJob() comp = test.testtools.getComp(job, "testprddb") path = "db.product" attrList = utils.config_tool.getAttributeList(comp, path, job) self.assertIn(B.ATTR_ARTS_PATH, attrList) self.assertIn(B.ATTR_ARTS_RESET, attrList) cnttest += 2 # new attribute comp = test.testtools.getComp(job, "testrest") path = "file.xmlrest" attrList = utils.config_tool.getAttributeList(comp, path, job) #print(str(comp.conf["conn"])) #print(str(comp.conf[B.SUBJECT_ARTS])) #print(str(attrList)) MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest) def test_zzz(self): print(MyTestCase.mymsg) if __name__ == '__main__': verbose = True unittest.main()