Browse Source

refactoring and beautifying

master
Ulrich Carmesin 2 years ago
parent
commit
f2537d7604
  1. 22
      basic/compexec.py
  2. 13
      basic/message.py
  3. 7
      basic/text_const.py
  4. 18
      basic/toolHandling.py
  5. 13
      test/test_24gen.py
  6. 2
      test/test_31db.py
  7. 1
      utils/data_const.py
  8. 20
      utils/file_abstract.py
  9. 1
      utils/filejson_tool.py
  10. 5
      utils/filexml_tool.py
  11. 3
      utils/gen_tool.py
  12. 11
      utils/i18n_tool.py

22
basic/compexec.py

@ -49,6 +49,8 @@ import utils.match_tool
import utils.match_const as M import utils.match_const as M
import utils.tdata_tool import utils.tdata_tool
import basic.constants as B import basic.constants as B
import basic.text_const as T
import utils.data_const as D
class Testexecuter(): class Testexecuter():
@ -112,7 +114,7 @@ class Testexecuter():
print (t) print (t)
if utils.db_abstract.isCompTable(self, tdata, t): if utils.db_abstract.isCompTable(self, tdata, t):
self.m.logInfo("insert content "+ self.name) self.m.logInfo("insert content "+ self.name)
dbi = basic.toolHandling.getDbTool(self, job) dbi = basic.toolHandling.getDbTool(job, self)
dbi.insertTables(tdata, job) dbi.insertTables(tdata, job)
break break
self.m.setMsg("data loaded for " + self.name + " is OK") self.m.setMsg("data loaded for " + self.name + " is OK")
@ -139,7 +141,7 @@ class Testexecuter():
self.m.debug(verify, "--- " + str(inspect.currentframe().f_code.co_name) + "() started at " + datetime.now().strftime("%Y%m%d_%H%M%S") + " for " + str(self.name).upper()) self.m.debug(verify, "--- " + str(inspect.currentframe().f_code.co_name) + "() started at " + datetime.now().strftime("%Y%m%d_%H%M%S") + " for " + str(self.name).upper())
if B.TOPIC_NODE_DB in self.conf[B.SUBJECT_ARTS]: if B.TOPIC_NODE_DB in self.conf[B.SUBJECT_ARTS]:
self.m.logInfo("select db-content "+ self.name) self.m.logInfo("select db-content "+ self.name)
dbi = basic.toolHandling.getDbTool(self, job) dbi = basic.toolHandling.getDbTool(job, self)
data = dbi.selectTables(subdir, job) data = dbi.selectTables(subdir, job)
print("ppp") print("ppp")
#data = {} #data = {}
@ -252,16 +254,18 @@ class Testexecuter():
:param tdata: :param tdata:
:return: :return:
""" """
if step.fct in self.conf["teststeps"]: if not step.fct in self.conf[B.DATA_NODE_STEPS]:
for s in self.conf["teststeps"][step.fct]: raise Exception(self.m.getMessageText(T.EXP_KEY_DOESNT_EXIST, [step.fct, self.name]))
stepconf = self.conf["teststeps"][step.fct][s] if step.fct in self.conf[B.DATA_NODE_STEPS]:
if stepconf["tool"] == "file": for stepconf in self.conf[B.DATA_NODE_STEPS][step.fct]:
if stepconf[B.SUBJECT_TOOL] == B.TOPIC_NODE_FILE:
tool = basic.toolHandling.getFileTool(job, self, stepconf[B.ATTR_ARTS_TYPE])
print("file-tool") print("file-tool")
elif stepconf["tool"] == "api": elif stepconf[B.SUBJECT_TOOL] == B.TOPIC_NODE_API:
print("api-tool") print("api-tool")
elif stepconf["tool"] == "cli": elif stepconf[B.SUBJECT_TOOL] == B.TOPIC_NODE_CLI:
print("cli-tool") print("cli-tool")
elif stepconf["tool"] == "db": elif stepconf[B.SUBJECT_TOOL] == B.TOPIC_NODE_DB:
print("db-tool") print("db-tool")
else: else:
print("nichts da") print("nichts da")

13
basic/message.py

@ -21,6 +21,8 @@ import os
import math import math
from datetime import datetime from datetime import datetime
import utils.path_tool import utils.path_tool
import utils.i18n_tool
import basic.text_const as T
LIMIT_FATAL = 0 LIMIT_FATAL = 0
LIMIT_ERROR = 4 LIMIT_ERROR = 4
@ -55,6 +57,7 @@ class Message:
""" """
def __init__(self, job, level, logTime, componente): def __init__(self, job, level, logTime, componente):
# (self, componente, out, level): # (self, componente, out, level):
self.job = job
self.componente = componente # dezantrales Logsystem self.componente = componente # dezantrales Logsystem
verify = LIMIT_DEBUG verify = LIMIT_DEBUG
self.initErrorTyp() self.initErrorTyp()
@ -191,6 +194,16 @@ class Message:
self.setRc(RC_MSG, text) self.setRc(RC_MSG, text)
self.logInfo(text) self.logInfo(text)
def getMessageText(self, text, args):
out = ""
constName = ""
for i in range(0, len(T.LIST_EXP_TEXT)):
if text == T.LIST_EXP_TEXT[i]:
constName = T.LIST_EXP_CONST[i]
txt = utils.i18n_tool.I18n.getInstance().getMessage(self.job, constName, args)
out = txt.format(args)
return out
def logFatal(self, text): def logFatal(self, text):
self.log(LIMIT_FATAL, "FATAL: " + text) self.log(LIMIT_FATAL, "FATAL: " + text)
self.debug(LIMIT_FATAL, "FATAL: " + text) self.debug(LIMIT_FATAL, "FATAL: " + text)

7
basic/text_const.py

@ -0,0 +1,7 @@
# -----------------
EXP_KEY_MISSING = "key is missing {}"
EXP_KEY_DOESNT_EXIST = "key {} doesnt exist in domain {}"
LIST_EXP_TEXT = [EXP_KEY_MISSING, EXP_KEY_DOESNT_EXIST]
LIST_EXP_CONST = ["EXP_KEY_MISSING", "EXP_KEY_DOESNT_EXIST"]

18
basic/toolHandling.py

@ -50,18 +50,18 @@ def getCompAttr(comp, topic, attr, table=""):
def getTool(technicType, comp, job): def getTool(technicType, comp, job):
if technicType == B.TOPIC_NODE_DB: if technicType == B.TOPIC_NODE_DB:
return getDbTool(comp, job) return getDbTool(job, comp)
if technicType == B.TOPIC_NODE_CLI: if technicType == B.TOPIC_NODE_CLI:
return getCliTool(comp, job) return getCliTool(job, comp)
if technicType == B.TOPIC_NODE_API: if technicType == B.TOPIC_NODE_API:
return getApiTool(comp, job) return getApiTool(job, comp)
if technicType == B.TOPIC_NODE_FILE: if technicType == B.TOPIC_NODE_FILE:
# TODO im Allgemeinen keine konrete Implementierung aufrufen, # TODO im Allgemeinen keine konrete Implementierung aufrufen,
# denn zu einer Komponente koennen unterschiedliche Dateien vorkommen # denn zu einer Komponente koennen unterschiedliche Dateien vorkommen
return getFileTool(job, comp, "") return getFileTool(job, comp, "")
# class ToolManager: # class ToolManager:
def getDbTool(comp, job): def getDbTool(job, comp, dbtype=""):
verify = int(job.getDebugLevel("db_tool")) verify = int(job.getDebugLevel("db_tool"))
dbtype = getCompAttr(comp, B.TOPIC_NODE_DB, B.ATTR_TYPE, "") dbtype = getCompAttr(comp, B.TOPIC_NODE_DB, B.ATTR_TYPE, "")
toolname = "db"+dbtype+"_tool" toolname = "db"+dbtype+"_tool"
@ -75,7 +75,7 @@ def getDbTool(comp, job):
c.setComp(comp) c.setComp(comp)
return c return c
def getCliTool(comp, job): def getCliTool(job, comp):
verify = int(job.getDebugLevel("db_tool")) verify = int(job.getDebugLevel("db_tool"))
clitype = getCompAttr(comp, B.TOPIC_NODE_CLI, B.ATTR_TYPE, "") clitype = getCompAttr(comp, B.TOPIC_NODE_CLI, B.ATTR_TYPE, "")
toolname = "cli"+clitype+"_tool" toolname = "cli"+clitype+"_tool"
@ -89,7 +89,7 @@ def getCliTool(comp, job):
c.setComp(comp) c.setComp(comp)
return c return c
def getApiTool(comp, job): def getApiTool(job, comp):
verify = int(job.getDebugLevel("db_tool")) verify = int(job.getDebugLevel("db_tool"))
apitype = getCompAttr(comp, B.TOPIC_NODE_API, B.ATTR_TYPE, "") apitype = getCompAttr(comp, B.TOPIC_NODE_API, B.ATTR_TYPE, "")
toolname = "api"+apitype+"_tool" toolname = "api"+apitype+"_tool"
@ -104,9 +104,11 @@ def getApiTool(comp, job):
return c return c
def getFileTool(job, comp, filenode=""): def getFileTool(job, comp, filenode=""):
verify = int(job.getDebugLevel("db_tool")) verify = int(job.getDebugLevel("file_tool"))
if len(filenode) > 3 and filenode[-1:] != ".": if len(filenode) > 3 and "." in filenode and filenode[-1:] != ".":
filetype = utils.config_tool.getAttribute(comp, filenode, B.ATTR_ARTS_TYPE, job) filetype = utils.config_tool.getAttribute(comp, filenode, B.ATTR_ARTS_TYPE, job)
elif len(filenode) > 2 and len(filenode) < 5:
filetype = filenode
else: else:
filetype = getCompAttr(comp, B.TOPIC_NODE_FILE, B.ATTR_TYPE, "") filetype = getCompAttr(comp, B.TOPIC_NODE_FILE, B.ATTR_TYPE, "")
toolname = "file"+filetype+"_tool" toolname = "file"+filetype+"_tool"

13
test/test_24gen.py

@ -33,6 +33,19 @@ class MyTestCase(unittest.TestCase):
print((str(res))) print((str(res)))
res = utils.gen_tool.getElemList(G.KEY_LIST, "cat:countries", 6, job) res = utils.gen_tool.getElemList(G.KEY_LIST, "cat:countries", 6, job)
print((str(res))) print((str(res)))
for cnt in [3, 15, 75, 400]:
res = utils.gen_tool.getElemList(G.KEY_LIST, "A, B,C , D", cnt, job)
self.assertEqual(len(res), cnt)
cnttest += 1
for cnt in [3, 15, 75, 400]:
res = utils.gen_tool.getElemList(G.KEY_LIST, "cat:countries", cnt, job)
self.assertEqual(len(res), cnt)
cnttest += 1
for cnt in [3, 15, 75, 400]:
res = utils.gen_tool.getElemList(G.KEY_LIST, "0 .. 4", cnt, job)
self.assertEqual(len(res), cnt)
cnttest += 1
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)

2
test/test_31db.py

@ -77,7 +77,7 @@ class MyTestCase(unittest.TestCase):
comp.conf[B.SUBJECT_CONN] = {} comp.conf[B.SUBJECT_CONN] = {}
comp.conf[B.SUBJECT_CONN][B.TOPIC_NODE_DB] = {} comp.conf[B.SUBJECT_CONN][B.TOPIC_NODE_DB] = {}
comp.conf[B.SUBJECT_CONN][B.TOPIC_NODE_DB][B.ATTR_TYPE] = "shive" comp.conf[B.SUBJECT_CONN][B.TOPIC_NODE_DB][B.ATTR_TYPE] = "shive"
tool = basic.toolHandling.getDbTool(comp) tool = basic.toolHandling.getDbTool(job, comp)
self.assertRegex(str(type(tool)), 'dbshive_tool.DbFcts') self.assertRegex(str(type(tool)), 'dbshive_tool.DbFcts')
attr = tool.getDbAttributes("xx") attr = tool.getDbAttributes("xx")
self.assertRegex(attr[B.ATTR_DB_PARTITION], 'n') self.assertRegex(attr[B.ATTR_DB_PARTITION], 'n')

1
utils/data_const.py

@ -25,6 +25,7 @@ DDL_TYPE = "type"
DFILE_TYPE_YML = "yml" DFILE_TYPE_YML = "yml"
DFILE_TYPE_JSON = "json" DFILE_TYPE_JSON = "json"
DFILE_TYPE_CSV = "csv" DFILE_TYPE_CSV = "csv"
DFILE_TYPE_XML = "xml"
DFILE_TESTCASE_NAME = "testspec" DFILE_TESTCASE_NAME = "testspec"
DFILE_TESTSUITE_NAME = "testsuite" DFILE_TESTSUITE_NAME = "testsuite"
DFILE_TABLE_PREFIX = "table_" DFILE_TABLE_PREFIX = "table_"

20
utils/file_abstract.py

@ -5,6 +5,7 @@
# Source : gitea.ucarmesin.de # Source : gitea.ucarmesin.de
# --------------------------------------------------------------------------------------------------------- # ---------------------------------------------------------------------------------------------------------
import os import os
import re
import basic.program import basic.program
import basic.catalog import basic.catalog
import utils.config_tool import utils.config_tool
@ -13,16 +14,8 @@ import basic.toolHandling
import utils.data_const as D import utils.data_const as D
import utils.file_tool import utils.file_tool
import utils.path_tool import utils.path_tool
import xml.etree.ElementTree as ET
""" import basic.catalog
# TODO Beschreibung file-tools
* fileXml_tool
* fileJson_tool
* fileYaml_tool
* fileCsv_tool
* fileHtml_tool
...
"""
class FileFcts(): class FileFcts():
@ -46,7 +39,6 @@ class FileFcts():
:return: :return:
""" """
def file2dict(self): def file2dict(self):
pass pass
@ -84,7 +76,7 @@ class FileFcts():
#txt = self.createDict() #txt = self.createDict()
utils.file_tool.writeFileText(self.comp.m, archivpath, txt) utils.file_tool.writeFileText(self.comp.m, archivpath, txt)
def send_request(self, step): def send_request(self, job, step):
archivpath = "" archivpath = ""
filename = step.args["filename"] filename = step.args["filename"]
technique = step.args["technique"] technique = step.args["technique"]
@ -95,11 +87,11 @@ class FileFcts():
continue continue
envpath = o["envpath"] envpath = o["envpath"]
envpath = utils.path_tool.composePattern(envpath, self.comp) envpath = utils.path_tool.composePattern(envpath, self.comp)
fct = basic.toolHandling.getCliTool(self.comp) fct = basic.toolHandling.getCliTool(job, self.comp)
fct.copy(self.job, archivpath, envpath) fct.copy(self.job, archivpath, envpath)
elif technique == "api": elif technique == "api":
txt = utils.file_tool.readFileText(archivpath, self.comp.m) txt = utils.file_tool.readFileText(archivpath, self.comp.m)
fct = basic.toolHandling.getApiTool(self.comp) fct = basic.toolHandling.getApiTool(job, self.comp)
response = fct.send(self.job, self.comp, txt) response = fct.send(self.job, self.comp, txt)
archivpath = os.path.join(utils.path_tool.composePattern("{tcresult}/response", self.comp), filename) archivpath = os.path.join(utils.path_tool.composePattern("{tcresult}/response", self.comp), filename)

1
utils/filejson_tool.py

@ -17,3 +17,4 @@ class FileFcts(utils.file_abstract.FileFcts):
def __init__(self): def __init__(self):
pass pass

5
utils/filexml_tool.py

@ -4,6 +4,7 @@
# Author : Ulrich Carmesin # Author : Ulrich Carmesin
# Source : gitea.ucarmesin.de # Source : gitea.ucarmesin.de
# --------------------------------------------------------------------------------------------------------- # ---------------------------------------------------------------------------------------------------------
import xmltodict
import basic.program import basic.program
import utils.config_tool import utils.config_tool
import utils.file_abstract import utils.file_abstract
@ -17,3 +18,7 @@ class FileFcts(utils.file_abstract.FileFcts):
def __init__(self): def __init__(self):
pass pass
def parseFile2Dict(self):
pass

3
utils/gen_tool.py

@ -122,9 +122,6 @@ def getElemList(formula, values, count, job):
temp = catalog.getKeys(domain, job) temp = catalog.getKeys(domain, job)
if not isinstance(temp, list): if not isinstance(temp, list):
temp = [] temp = []
max = 3
while len(temp) > 0 and len(out) < count: while len(temp) > 0 and len(out) < count:
out += temp out += temp
max -= 1
if max < 0: break
return out[0:count] return out[0:count]

11
utils/i18n_tool.py

@ -37,6 +37,12 @@ class I18n:
return I18n.__instance return I18n.__instance
def getMessage(self, job, key, args=[]):
print("getMessage "+key+" "+str(args))
out = self.getText(key, job)
out = out.format(args)
return out
def getText(self, key, job=None): def getText(self, key, job=None):
""" """
this function gets the text depending on language which is set in job.conf this function gets the text depending on language which is set in job.conf
@ -52,8 +58,9 @@ class I18n:
language = "en" language = "en"
if language not in self.cache: if language not in self.cache:
raise Exception(EXP_KEY_MISSING, (key)) raise Exception(EXP_KEY_MISSING, (key))
out = self.extractText(key) if "=" in key:
key = self.extractKey(key) out = self.extractText(key)
key = self.extractKey(key)
if key in self.cache[language]: if key in self.cache[language]:
out = self.cache[language][key] out = self.cache[language][key]
elif key in self.cache[DEFAULT_LANGUAGE]: elif key in self.cache[DEFAULT_LANGUAGE]:

Loading…
Cancel
Save