Browse Source

additional database-attribute

master
Ulrich Carmesin 3 years ago
parent
commit
782c599cd0
  1. 2
      basic/constants.py
  2. 3
      components/testexec.py
  3. 30
      test/test_compare.py
  4. 14
      test/test_report.py
  5. 3
      utils/data_const.py
  6. 2
      utils/date_tool.py
  7. 36
      utils/db_abstract.py
  8. 34
      utils/match_tool.py
  9. 2
      utils/report_tool.py

2
basic/constants.py

@ -48,9 +48,11 @@ PAR_STEP = 'step'
PAR_DESCRIPT = 'desription' PAR_DESCRIPT = 'desription'
""" """ """ """
PAR_TESTCASE = "testcase" PAR_TESTCASE = "testcase"
PAR_TESTCASES = "testcases"
PAR_TESTSUITE = "usecase" PAR_TESTSUITE = "usecase"
PAR_TCTIME = "tctime" PAR_TCTIME = "tctime"
PAR_TSTIME = "tstime" PAR_TSTIME = "tstime"
PAR_TESTINSTANCES = "testinstances"
""" name of testcase extracted from PAR_TCDIR """ """ name of testcase extracted from PAR_TCDIR """

3
components/testexec.py

@ -128,7 +128,8 @@ class Testexecuter():
if "db" in self.conf[B.SUBJECT_ARTS]: if "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) dbi = basic.toolHandling.getDbTool(self)
dbi.selectTables() tdata = dbi.selectTables()
utils.tdata_tool.writeCsvData("", tdata, self)
if B.ATTR_ARTS_LOB in self.conf[B.SUBJECT_ARTS]: if B.ATTR_ARTS_LOB in self.conf[B.SUBJECT_ARTS]:
self.m.logInfo("check lob if is deleted with flaskdb "+ self.name) self.m.logInfo("check lob if is deleted with flaskdb "+ self.name)
self.m.setMsg("readInstance for " + self.name + " is OK") self.m.setMsg("readInstance for " + self.name + " is OK")

30
test/test_compare.py

@ -28,7 +28,10 @@ tdata = {
"database": { "database": {
"scheme": { "scheme": {
"table": { "table": {
"_data": [ D.DATA_ATTR_COUNT: 4,
D.DATA_ATTR_DATE: "15.05.2022",
B.DATA_NODE_HEADER: ["id", "name", "year", "position", "hobby"],
B.DATA_NODE_DATA: [
{"id": 1, "name": "Brecht", "year": 2014, "position": "top", "hobby": "meaning"}, {"id": 1, "name": "Brecht", "year": 2014, "position": "top", "hobby": "meaning"},
{"id": 2, "name": "Meier", "year": 2015, "position": "first", "hobby": "reading" }, {"id": 2, "name": "Meier", "year": 2015, "position": "first", "hobby": "reading" },
{"id": 3, "name": "Smith", "year": 2018, "position": "second", "hobby": "writing"}, {"id": 3, "name": "Smith", "year": 2018, "position": "second", "hobby": "writing"},
@ -45,7 +48,10 @@ tdata = {
"database": { "database": {
"scheme": { "scheme": {
"table": { "table": {
"_data": [ D.DATA_ATTR_COUNT: 4,
D.DATA_ATTR_DATE: "15.05.2022",
B.DATA_NODE_HEADER: ["id", "name", "year", "position", "hobby"],
B.DATA_NODE_DATA: [
{"id": 1, "name": "Brecht", "year": 2014, "position": "top", "hobby": "meaning"}, {"id": 1, "name": "Brecht", "year": 2014, "position": "top", "hobby": "meaning"},
{"id": 2, "name": "Maier", "year": 2015, "position": "first", "hobby": "reading"}, {"id": 2, "name": "Maier", "year": 2015, "position": "first", "hobby": "reading"},
{"id": 4, "name": "Smith", "year": 2018, "position": "second", "hobby": "writing"}, {"id": 4, "name": "Smith", "year": 2018, "position": "second", "hobby": "writing"},
@ -115,8 +121,8 @@ class MyTestCase(unittest.TestCase):
matching = self.getMatching() matching = self.getMatching()
utils.match_tool.setMatchkeys(matching, ":database:scheme:table:_data") utils.match_tool.setMatchkeys(matching, ":database:scheme:table:_data")
utils.match_tool.getSimilarity(matching, utils.match_tool.getSimilarity(matching,
tdata[M.MATCH_SIDE_PREACTUAL]["data"]["database"]["scheme"]["table"]["_data"][0], tdata[M.MATCH_SIDE_PREACTUAL]["data"]["database"]["scheme"]["table"][B.DATA_NODE_DATA][0],
tdata[M.MATCH_SIDE_POSTACTUAL]["data"]["database"]["scheme"]["table"]["_data"][0], 1) tdata[M.MATCH_SIDE_POSTACTUAL]["data"]["database"]["scheme"]["table"][B.DATA_NODE_DATA][0], 1)
def test_bestfit(self): def test_bestfit(self):
job = Job("unit") job = Job("unit")
@ -127,8 +133,8 @@ class MyTestCase(unittest.TestCase):
comp.conf = conf comp.conf = conf
matching = utils.match_tool.Matching(comp) matching = utils.match_tool.Matching(comp)
matching.matchtype = M.MATCH_SUCCESS matching.matchtype = M.MATCH_SUCCESS
matching.sideA = tdata[M.MATCH_SIDE_PREACTUAL]["data"]["database"]["scheme"]["table"]["_data"] matching.sideA = tdata[M.MATCH_SIDE_PREACTUAL]["data"]["database"]["scheme"]["table"][B.DATA_NODE_DATA]
matching.sideB = tdata[M.MATCH_SIDE_POSTACTUAL]["data"]["database"]["scheme"]["table"]["_data"] matching.sideB = tdata[M.MATCH_SIDE_POSTACTUAL]["data"]["database"]["scheme"]["table"][B.DATA_NODE_DATA]
utils.match_tool.matchBestfit(matching, ":database:scheme:table:_data") utils.match_tool.matchBestfit(matching, ":database:scheme:table:_data")
print(json.dumps(matching.linksA)) print(json.dumps(matching.linksA))
print(json.dumps(matching.linksB)) print(json.dumps(matching.linksB))
@ -147,16 +153,16 @@ class MyTestCase(unittest.TestCase):
comp.conf = conf comp.conf = conf
matching = self.getMatching() matching = self.getMatching()
matching.matchtype = M.MATCH_SUCCESS matching.matchtype = M.MATCH_SUCCESS
matching.sideA = tdata[M.MATCH_SIDE_PREACTUAL]["data"]["database"]["scheme"]["table"]["_data"] matching.sideA = tdata[M.MATCH_SIDE_PREACTUAL]["data"]["database"]["scheme"]["table"][B.DATA_NODE_DATA]
matching.sideB = tdata[M.MATCH_SIDE_POSTACTUAL]["data"]["database"]["scheme"]["table"]["_data"] matching.sideB = tdata[M.MATCH_SIDE_POSTACTUAL]["data"]["database"]["scheme"]["table"][B.DATA_NODE_DATA]
ddl = conf[B.DATA_NODE_DDL]["database"]["scheme"]["table"] ddl = conf[B.DATA_NODE_DDL]["database"]["scheme"]["table"]
header = [] header = []
for f in ddl["_header"]: for f in ddl["_header"]:
header.append({D.DDL_FNAME: f, D.DDL_TYPE: ddl[f][D.DDL_TYPE], D.DDL_ACCEPTANCE: ddl[f][D.DDL_ACCEPTANCE]}) header.append({D.DDL_FNAME: f, D.DDL_TYPE: ddl[f][D.DDL_TYPE], D.DDL_ACCEPTANCE: ddl[f][D.DDL_ACCEPTANCE]})
i = 1 i = 1
text = utils.match_tool.compareRow(matching, header, tdata[M.MATCH_SIDE_PREACTUAL]["data"]["database"]["scheme"]["table"]["_data"][i], text = utils.match_tool.compareRow(matching, header, tdata[M.MATCH_SIDE_PREACTUAL]["data"]["database"]["scheme"]["table"][B.DATA_NODE_DATA][i],
tdata[M.MATCH_SIDE_POSTACTUAL]["data"]["database"]["scheme"]["table"]["_data"][i]) tdata[M.MATCH_SIDE_POSTACTUAL]["data"]["database"]["scheme"]["table"][B.DATA_NODE_DATA][i])
print(text) print(text)
def test_compareRows(self): def test_compareRows(self):
@ -169,8 +175,8 @@ class MyTestCase(unittest.TestCase):
basic.componentHandling.comps["component"] = comp basic.componentHandling.comps["component"] = comp
matching = self.getMatching() matching = self.getMatching()
comp.name = "component" comp.name = "component"
matching.sideA = tdata[M.MATCH_SIDE_PREACTUAL]["data"]["database"]["scheme"]["table"]["_data"] matching.sideA = tdata[M.MATCH_SIDE_PREACTUAL]["data"]["database"]["scheme"]["table"][B.DATA_NODE_DATA]
matching.sideB = tdata[M.MATCH_SIDE_POSTACTUAL]["data"]["database"]["scheme"]["table"]["_data"] matching.sideB = tdata[M.MATCH_SIDE_POSTACTUAL]["data"]["database"]["scheme"]["table"][B.DATA_NODE_DATA]
linksA = {"a0001": "b0001", "a0002": "b0002" } linksA = {"a0001": "b0001", "a0002": "b0002" }
matching.linksA = linksA matching.linksA = linksA
text = utils.match_tool.compareRows(matching, ":database:scheme:table:_data") text = utils.match_tool.compareRows(matching, ":database:scheme:table:_data")

14
test/test_report.py

@ -9,7 +9,8 @@ import init_testcase
import test_executer import test_executer
import test.constants import test.constants
import utils.report_tool import utils.report_tool
import utils.match_tool as M import utils.match_tool
import utils.match_const as M
import basic.constants as B import basic.constants as B
HOME_PATH = test.constants.HOME_PATH HOME_PATH = test.constants.HOME_PATH
@ -98,6 +99,7 @@ class MyTestCase(unittest.TestCase):
cm = basic.componentHandling.ComponentManager() cm = basic.componentHandling.ComponentManager()
for c in ["comp02"]: for c in ["comp02"]:
comp = components.component.Component() comp = components.component.Component()
comp.conf = {}
comp.name = c comp.name = c
basic.componentHandling.comps[c] = comp basic.componentHandling.comps[c] = comp
report = self.getReport() report = self.getReport()
@ -112,6 +114,7 @@ class MyTestCase(unittest.TestCase):
cm = basic.componentHandling.ComponentManager() cm = basic.componentHandling.ComponentManager()
for c in ["comp02"]: for c in ["comp02"]:
comp = components.component.Component() comp = components.component.Component()
comp.conf = {}
comp.name = c comp.name = c
basic.componentHandling.comps[c] = comp basic.componentHandling.comps[c] = comp
print(" ---------- test_headlines") print(" ---------- test_headlines")
@ -123,7 +126,7 @@ class MyTestCase(unittest.TestCase):
html = report.getArtefactBlock("TC0001", "comp02", "arte01") html = report.getArtefactBlock("TC0001", "comp02", "arte01")
print(html) print(html)
def test_reportS(self): def xtest_reportS(self):
job = basic.program.Job.getInstance() job = basic.program.Job.getInstance()
setattr(job.par, "testcase", "TC0001") setattr(job.par, "testcase", "TC0001")
setattr(job.par, "testcases", ["TC0001", "TC0002"]) setattr(job.par, "testcases", ["TC0001", "TC0002"])
@ -147,9 +150,10 @@ class MyTestCase(unittest.TestCase):
print(html_2) print(html_2)
print("<<---------------------------------- TC0002") print("<<---------------------------------- TC0002")
report.extractTestcase("TC0002", html_2) report.extractTestcase("TC0002", html_2)
setattr(job.par, "testsuite", "TST001") # setattr(job.par, B.PAR_TESTCASES, ["TST001"])
html = report.reportTestsuite() setattr(job.par, B.PAR_TESTCASES, ["TC0001", "TC0002"])
print(html) #html = report.reportTestsuite()
#print(html)
print("<<---------------------------------- TST001") print("<<---------------------------------- TST001")
if __name__ == '__main__': if __name__ == '__main__':

3
utils/data_const.py

@ -26,6 +26,9 @@ DFILE_TYPE_CSV = "csv"
DATA_SRC_DIR = "dir" DATA_SRC_DIR = "dir"
DATA_SRC_CSV = "csv" DATA_SRC_CSV = "csv"
DATA_ATTR_COUNT = "_count"
DATA_ATTR_DATE = "_date"
CSV_HEADER_START = ["node", "table", "tabelle"] CSV_HEADER_START = ["node", "table", "tabelle"]
CSV_DELIMITER = ";" CSV_DELIMITER = ";"

2
utils/date_tool.py

@ -6,6 +6,8 @@ additionally functions for calculating date with formulas like [DATE+2M] and for
import datetime import datetime
F_DIR = "%Y-%m-%d_%H-%M-%S" F_DIR = "%Y-%m-%d_%H-%M-%S"
F_DE = "%d.%m.%Y"
def getActdate(format): def getActdate(format):
return getFormatdate(datetime.datetime.now(), format) return getFormatdate(datetime.datetime.now(), format)

36
utils/db_abstract.py

@ -42,6 +42,7 @@ import basic.program
import utils.config_tool import utils.config_tool
import basic.constants as B import basic.constants as B
import utils.data_const as D import utils.data_const as D
import utils.date_tool
import os import os
@ -170,37 +171,6 @@ class DbFcts():
""" """
return getDbAttributes(self.comp, table) return getDbAttributes(self.comp, table)
def xxgetDbAttributes(self, table):
out = {
B.ATTR_DB_TABNAME: "",
B.ATTR_DB_PARTITION: D.DFLT_DB_PARTITION,
B.ATTR_DB_CONN_JAR: D.DFLT_DB_CONN_JAR
}
for attr in out.keys():
print(attr)
if (table in self.comp.conf[B.SUBJECT_ARTS][B.TOPIC_NODE_DB]) \
and (attr in self.comp.conf[B.SUBJECT_ARTS][B.TOPIC_NODE_DB][table]):
out[attr] = self.comp.conf[B.SUBJECT_ARTS][B.TOPIC_NODE_DB][table][attr]
print("a "+attr+" "+out[attr])
elif (attr in self.comp.conf[B.SUBJECT_ARTS][B.TOPIC_NODE_DB]):
out[attr] = self.comp.conf[B.SUBJECT_ARTS][B.TOPIC_NODE_DB][attr]
print("b "+attr+" "+out[attr])
elif (B.TOPIC_NODE_DB in self.comp.conf[B.SUBJECT_CONN]) \
and (table in self.comp.conf[B.SUBJECT_CONN][B.TOPIC_NODE_DB]) \
and (attr in self.comp.conf[B.SUBJECT_CONN][table][B.TOPIC_NODE_DB]):
out[attr] = self.comp.conf[B.SUBJECT_CONN][table][B.TOPIC_NODE_DB][attr]
print("c " + attr+" "+out[attr])
elif (B.TOPIC_NODE_DB in self.comp.conf[B.SUBJECT_CONN]) \
and (attr in self.comp.conf[B.SUBJECT_CONN][B.TOPIC_NODE_DB]):
out[attr] = self.comp.conf[B.SUBJECT_CONN][B.TOPIC_NODE_DB][attr]
print("d "+attr+" "+out[attr])
elif (attr in self.comp.conf[B.SUBJECT_CONN]):
out[attr] = self.comp.conf[B.SUBJECT_CONN][attr]
print("e " + attr+" "+out[attr])
else:
print("f " + attr+" "+out[attr])
return out
def selectTables(self, subdir): def selectTables(self, subdir):
""" method to delete rows from a database """ method to delete rows from a database
@ -210,6 +180,10 @@ class DbFcts():
tdata[subdir] = {} tdata[subdir] = {}
for t in self.comp.conf[B.DATA_NODE_DDL]: for t in self.comp.conf[B.DATA_NODE_DDL]:
tdata[subdir][t] = self.selectRows(t) tdata[subdir][t] = self.selectRows(t)
if B.DATA_NODE_DATA not in tdata[subdir][t]:
raise Exception("missing data node in table")
tdata[subdir][t][D.DATA_ATTR_COUNT] = len(tdata[subdir][t][B.DATA_NODE_DATA])
tdata[subdir][t][D.DATA_ATTR_DATE] = utils.date_tool.getActdate(utils.date_tool.F_DE)
return tdata return tdata
def selectRows(self, statement): def selectRows(self, statement):

34
utils/match_tool.py

@ -336,36 +336,36 @@ def getEvaluation(matching, type, acceptance, sideA, sideB):
return [result, classA, classB] return [result, classA, classB]
def matchDict(matching, A, B, path): def matchDict(matching, sideA, sideB, path):
""" travers through the datatree """ """ travers through the datatree """
job = basic.program.Job.getInstance() job = basic.program.Job.getInstance()
verify = int(job.getDebugLevel("match_tool")) - 4 verify = int(job.getDebugLevel("match_tool")) - 4
job.debug(verify, "matchDict " + path) job.debug(verify, "matchDict " + path)
if (A is not None): if (sideA is not None):
for k in A: for k in sideA:
job.debug(verify, "matchDict 400 " + k + ".") job.debug(verify, "matchDict 400 " + k + ".")
if k in ["_match"]: if k in ["_match", D.DATA_ATTR_COUNT, D.DATA_ATTR_DATE, B.DATA_NODE_HEADER]:
continue continue
if (B is not None) and (k in B): if (sideB is not None) and (k in sideB):
if (isinstance(A[k], dict)): A[k]["_match"] = "Y" if (isinstance(sideA[k], dict)): sideA[k]["_match"] = "Y"
if (isinstance(B[k], dict)): B[k]["_match"] = "Y" if (isinstance(sideB[k], dict)): sideB[k]["_match"] = "Y"
job.debug(verify, "matchDict 404 " + k + "." + path) job.debug(verify, "matchDict 404 " + k + "." + path)
matchElement(matching, A[k], B[k], path + ":" + k) matchElement(matching, sideA[k], sideB[k], path + ":" + k)
else: else:
if (isinstance(A[k], dict)): A[k]["_match"] = "N" if (isinstance(sideA[k], dict)): sideA[k]["_match"] = "N"
job.debug(verify, "matchDict 408 " + path) job.debug(verify, "matchDict 408 " + path)
matchElement(matching, A[k], None, path + ":" + k) matchElement(matching, sideA[k], None, path + ":" + k)
if (B is not None): if (sideB is not None):
for k in B: for k in sideB:
job.debug(verify, "matchDict 412 " + k + ".") job.debug(verify, "matchDict 412 " + k + ".")
if k in ["_match"]: if k in ["_match", D.DATA_ATTR_COUNT, D.DATA_ATTR_DATE, B.DATA_NODE_HEADER]:
continue continue
if (A is not None) and (k in A): if (sideA is not None) and (k in sideA):
continue continue
elif (A is None) or (k not in A): elif (sideA is None) or (k not in sideA):
if (A is not None) and (isinstance(A[k], dict)): B[k]["_match"] = "N" if (sideA is not None) and (isinstance(sideA[k], dict)): sideB[k]["_match"] = "N"
job.debug(verify, "matchDict 418 " + k + "." + path) job.debug(verify, "matchDict 418 " + k + "." + path)
matchElement(matching, None, B[k], path + ":" + k) matchElement(matching, None, sideB[k], path + ":" + k)
job.debug(verify, "matchDict 420 ...<<---") job.debug(verify, "matchDict 420 ...<<---")
return matching return matching

2
utils/report_tool.py

@ -258,7 +258,7 @@ class Report:
def reportTestsuite(self): def reportTestsuite(self):
job = basic.program.Job.getInstance() job = basic.program.Job.getInstance()
verify = int(job.getDebugLevel(TOOL_NAME)) - 1 verify = int(job.getDebugLevel(TOOL_NAME)) - 1
testinstances = getattr(job.par, "testinstances") testinstances = getattr(job.par, B.PAR_TESTCASES)
html = self.getHeader() html = self.getHeader()
html += self.getTitle() html += self.getTitle()
i = 0 i = 0

Loading…
Cancel
Save