Browse Source

get artifact-attributes from config_tool

master
Ulrich Carmesin 2 years ago
parent
commit
7296053ccc
  1. 4
      basic/compexec.py
  2. 42
      basic/constants.py
  3. 36
      test/test_04config.py
  4. 12
      test/testtools.py
  5. 44
      utils/config_tool.py

4
basic/compexec.py

@ -352,8 +352,8 @@ class Testexecuter():
# fill each data into matching-object # fill each data into matching-object
for side in M.MATCH_SIDES: for side in M.MATCH_SIDES:
if side == M.MATCH_SIDE_PRESTEP: if side == M.MATCH_SIDE_PRESTEP:
if B.ATTR_DB_PRESTEP in self.conf[B.SUBJECT_ARTS][B.TOPIC_NODE_DB][t]: if B.ATTR_ARTS_PRESTEP in self.conf[B.SUBJECT_ARTS][B.TOPIC_NODE_DB][t]:
a = self.conf[B.SUBJECT_ARTS][B.TOPIC_NODE_DB][t][B.ATTR_DB_PRESTEP].split(":") a = self.conf[B.SUBJECT_ARTS][B.TOPIC_NODE_DB][t][B.ATTR_ARTS_PRESTEP].split(":")
if a[0] != self.name: if a[0] != self.name:
comp = cm.getComponent(a[0]) comp = cm.getComponent(a[0])
else: else:

42
basic/constants.py

@ -98,13 +98,18 @@ DATA_NODE_COMP = "comp"
DATA_NODE_PAR = "par" DATA_NODE_PAR = "par"
""" This constant defines """ ATTR_ARTS_TYPE = "type"
""" must attribute for the type of the technique """
ATTR_ARTS_PATH = "path"
""" optional attribute for the basic folder if the artifact is stored in the filesystem """
ATTR_ARTS_RESET = "reset"
""" optional attribute if the artefact should be reset in the initializing-phase """
ATTR_ARTS_PRESTEP = "prestep"
""" optional attribute to define a source-table for this table """
LIST_ARTS_ATTR = [ATTR_ARTS_TYPE, ATTR_ARTS_PATH, ATTR_ARTS_RESET, ATTR_ARTS_PRESTEP]
TOPIC_NODE_DB = "db" TOPIC_NODE_DB = "db"
# testexec, db_abstr # testexec, db_abstr
ATTR_DB_TYPE = "type"
""" must attribute for the type of the database """
ATTR_DB_RESET = "reset"
""" optional attribute in order to use a different technical name for the db-table """
ATTR_DB_PARTITION = "partitioned" ATTR_DB_PARTITION = "partitioned"
""" optional attribute if table is partitioned """ optional attribute if table is partitioned
- this keyword delimited by "+" will be replaced by partition-names which are parametrized """ - this keyword delimited by "+" will be replaced by partition-names which are parametrized """
@ -114,10 +119,20 @@ ATTR_DB_SCHEMA = "schema"
""" optional attribute for technical name of the schema """ """ optional attribute for technical name of the schema """
ATTR_DB_TABNAME = "tabname" ATTR_DB_TABNAME = "tabname"
""" optional attribute in order to use a different technical name for the db-table """ """ optional attribute in order to use a different technical name for the db-table """
ATTR_DB_PRESTEP = "prestep" LIST_DB_ATTR = [ATTR_DB_PARTITION, ATTR_DB_DATABASE, ATTR_DB_SCHEMA, ATTR_DB_TABNAME, ATTR_ARTS_PRESTEP] + LIST_ARTS_ATTR
""" optional attribute to define a source-table for this table """ TOPIC_NODE_CLI = "cli"
LIST_DB_ATTR = [ATTR_DB_TYPE, ATTR_DB_RESET, ATTR_DB_PARTITION, LIST_CLI_ATTR = [] + LIST_ARTS_ATTR
ATTR_DB_DATABASE, ATTR_DB_SCHEMA, ATTR_DB_TABNAME, ATTR_DB_PRESTEP] TOPIC_NODE_API = "api"
LIST_API_ATTR = [] + LIST_ARTS_ATTR
TOPIC_NODE_FILE = "file"
LIST_FILE_ATTR = [] + LIST_ARTS_ATTR
LIST_ATTR = {
TOPIC_NODE_DB: LIST_DB_ATTR,
TOPIC_NODE_API: LIST_API_ATTR,
TOPIC_NODE_CLI: LIST_CLI_ATTR,
TOPIC_NODE_FILE: LIST_FILE_ATTR
}
ATTR_DB_CONN_JAR = "conn_jar_name" ATTR_DB_CONN_JAR = "conn_jar_name"
""" optional attribute for connection-jar-file instead of connection by ip, port """ """ optional attribute for connection-jar-file instead of connection by ip, port """
ATTR_CONN_HOST = "hostname" ATTR_CONN_HOST = "hostname"
@ -131,15 +146,6 @@ ATTR_CONN_DOMPATH = "dompath"
ATTR_CONN_USER = "user" ATTR_CONN_USER = "user"
ATTR_CONN_PASSWD = "password" ATTR_CONN_PASSWD = "password"
LIST_CONN_ATTR = [ATTR_DB_CONN_JAR, ATTR_CONN_HOST, ATTR_CONN_IP, ATTR_CONN_PORT, ATTR_CONN_DOMPATH, ATTR_CONN_USER, ATTR_CONN_PASSWD] LIST_CONN_ATTR = [ATTR_DB_CONN_JAR, ATTR_CONN_HOST, ATTR_CONN_IP, ATTR_CONN_PORT, ATTR_CONN_DOMPATH, ATTR_CONN_USER, ATTR_CONN_PASSWD]
TOPIC_NODE_CLI = "cli"
ATTR_CLI_TYPE = "type"
LIST_CLI_ATTR = [ATTR_CLI_TYPE]
TOPIC_NODE_API = "api"
ATTR_API_TYPE = "type"
LIST_API_ATTR = [ATTR_API_TYPE]
TOPIC_NODE_FILE = "file"
ATTR_FILE_TYPE = "type"
LIST_FILE_ATTR = [ATTR_FILE_TYPE]
# the configuration of a component or tool # the configuration of a component or tool
# entity { : variable name of the group, basic, component-name or tool-name # entity { : variable name of the group, basic, component-name or tool-name

36
test/test_04config.py

@ -1,3 +1,12 @@
#!/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 unittest
import os import os
import inspect import inspect
@ -8,13 +17,14 @@ import test.testtools
import utils.path_const as P import utils.path_const as P
import basic.constants as B import basic.constants as B
TEST_FUNCTIONS = ["test_getConfig", "test_mergeAttributes"] TEST_FUNCTIONS = ["test_01getConfig", "test_02mergeAttributes", "test_03getAttributes"]
VERIFY = False #TEST_FUNCTIONS = ["test_03getAttributes"]
verbose = False
class MyTestCase(unittest.TestCase): class MyTestCase(unittest.TestCase):
mymsg = "--------------------------------------------------------------" mymsg = "--------------------------------------------------------------"
def test_getConfig(self): def test_01getConfig(self):
global mymsg global mymsg
actfunction = str(inspect.currentframe().f_code.co_name) actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0 cnttest = 0
@ -39,12 +49,12 @@ class MyTestCase(unittest.TestCase):
r = utils.config_tool.getConfigPath(P.KEY_COMP, "testcrm") r = utils.config_tool.getConfigPath(P.KEY_COMP, "testcrm")
self.assertIn(os.path.join(job.conf.getPath(P.ATTR_PATH_COMPONENTS), "testcrm", "CONFIG"), r) self.assertIn(os.path.join(job.conf.getPath(P.ATTR_PATH_COMPONENTS), "testcrm", "CONFIG"), r)
r = utils.config_tool.getConfig(P.KEY_TOOL, "path") r = utils.config_tool.getConfig(P.KEY_TOOL, "path")
if VERIFY: print("pattern " + r["pattern"]["log"]) if verbose: print("pattern " + r["pattern"]["log"])
if VERIFY: print("pattern " + r["pattern"]["precond"]) if verbose: print("pattern " + r["pattern"]["precond"])
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest) MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)
def test_mergeAttributes(self): def test_02mergeAttributes(self):
global mymsg global mymsg
actfunction = str(inspect.currentframe().f_code.co_name) actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0 cnttest = 0
@ -65,20 +75,26 @@ class MyTestCase(unittest.TestCase):
componentName = "testprddb" componentName = "testprddb"
confs = utils.config_tool.getConfig("comp", componentName) confs = utils.config_tool.getConfig("comp", componentName)
conns = utils.conn_tool.getConnections(componentName) conns = utils.conn_tool.getConnections(componentName)
self.assertNotIn(B.ATTR_DB_TYPE, confs["conf"][B.SUBJECT_ARTS][B.TOPIC_NODE_DB]) 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]) confs["conf"] = utils.config_tool.mergeConn(job.m, confs["conf"], conns[0])
self.assertIn(B.ATTR_DB_TYPE, confs["conf"][B.SUBJECT_ARTS][B.TOPIC_NODE_DB]) self.assertIn(B.ATTR_ARTS_TYPE, confs["conf"][B.SUBJECT_ARTS][B.TOPIC_NODE_DB])
cnttest += 1 # new attribute cnttest += 1 # new attribute
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest) MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)
def test_getAttributes(self): def test_03getAttributes(self):
global mymsg global mymsg
actfunction = str(inspect.currentframe().f_code.co_name) actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0 cnttest = 0
if actfunction not in TEST_FUNCTIONS: if actfunction not in TEST_FUNCTIONS:
return return
job = test.testtools.getJob() job = test.testtools.getJob()
comp = test.testtools.getComp("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
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest) MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)
@ -87,5 +103,5 @@ class MyTestCase(unittest.TestCase):
if __name__ == '__main__': if __name__ == '__main__':
VERIFY = True verbose = True
unittest.main() unittest.main()

12
test/testtools.py

@ -3,6 +3,7 @@ import basic.constants as B
import basic.component import basic.component
import utils.data_const as D import utils.data_const as D
import test.constants as T import test.constants as T
import utils.config_tool
DEFAULT_GRAN = "tc" DEFAULT_GRAN = "tc"
DEFAULT_APP = "TESTAPP" DEFAULT_APP = "TESTAPP"
@ -82,9 +83,12 @@ def getJob(pgran="", papp="", penv="", ptstamp="", pmode=""):
return job return job
def getComp(): def getComp(componentName):
comp = basic.component.Component() comp = basic.component.Component()
comp.conf = {} comp.conf = {}
comp.name = "person" comp.name = componentName
confs = utils.config_tool.getConfig("comp", componentName)
pass conns = utils.conn_tool.getConnections(componentName)
comp.conf = confs["conf"]
comp.conf[B.SUBJECT_CONN] = conns[0]
return comp

44
utils/config_tool.py

@ -3,6 +3,7 @@
# --------------------------------------------------------------------------------------------------------- # ---------------------------------------------------------------------------------------------------------
# Author : Ulrich Carmesin # Author : Ulrich Carmesin
# Source : gitea.ucarmesin.de # Source : gitea.ucarmesin.de
# https://ucarmesin.de/index.php/it/testautomatisierung-fuer-daten-test/225-konfiguration-der-testanwendung
# --------------------------------------------------------------------------------------------------------- # ---------------------------------------------------------------------------------------------------------
import sys import sys
import basic.constants as B import basic.constants as B
@ -247,10 +248,53 @@ def getConfig(modul, name, subname=""):
return confs return confs
def getAttributeList(comp, path, job):
"""
gets a concrete attribute-list for an arteifact-element from the config-attributes from the connection-attributes
https://ucarmesin.de/index.php/it/testautomatisierung-fuer-daten-test/225-konfiguration-der-testanwendung#konfigurationshierarchie
:param comp:
:param path: artifact-type.artifact-name for example: DB.person
:return: list of all attributes for the artifact-element
"""
attrList = {}
a = path.split(".")
artType = a[0]
artName = a[1]
if B.SUBJECT_CONN not in comp.conf:
raise Exception ("Environment is not configured")
if artType in comp.conf[B.SUBJECT_CONN]:
if artName in comp.conf[B.SUBJECT_CONN][artType]:
for attr, val in comp.conf[B.SUBJECT_CONN][artType][artName].items():
if attr not in B.LIST_ATTR[artType]:
continue
attrList[attr] = val
for attr, val in comp.conf[B.SUBJECT_CONN][artType].items():
if attr not in B.LIST_ATTR[artType]:
continue
if attr in attrList:
continue
attrList[attr] = val
if artType in comp.conf[B.SUBJECT_ARTS]:
if artName in comp.conf[B.SUBJECT_ARTS][artType]:
for attr, val in comp.conf[B.SUBJECT_ARTS][artType][artName].items():
if attr not in B.LIST_ATTR[artType]:
continue
if attr in attrList:
continue
attrList[attr] = val
for attr, val in comp.conf[B.SUBJECT_ARTS][artType].items():
if attr not in B.LIST_ATTR[artType]:
continue
if attr in attrList:
continue
attrList[attr] = val
return attrList
def mergeConn(msg, conf, conn): def mergeConn(msg, conf, conn):
""" """
merges the config-attributes from the connection-attributes merges the config-attributes from the connection-attributes
because the connection-attributes has to overwrite the config-attributes if the subject is configured because the connection-attributes has to overwrite the config-attributes if the subject is configured
https://ucarmesin.de/index.php/it/testautomatisierung-fuer-daten-test/225-konfiguration-der-testanwendung#konfigurationshierarchie
:param conf: :param conf:
:param conn: :param conn:
:return: :return:

Loading…
Cancel
Save