Data-Test-Executer Framework speziell zum Test von Datenverarbeitungen mit Datengenerierung, Systemvorbereitungen, Einspielungen, ganzheitlicher diversifizierender Vergleich
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

197 lines
7.7 KiB

#!/usr/bin/python
# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------------------------------------------
# Author : Ulrich Carmesin
# Source : gitea.ucarmesin.de
# ---------------------------------------------------------------------------------------------------------
import unittest
import inspect
import os
import json
import basic.program
import utils.path_tool
import utils.path_const as P
import utils.config_tool
import utils.data_const as D
import basic.toolHandling
import test.constants
import basic.component
import basic.constants as B
import utils.map_tool
import utils.file_tool
import test.testtools
import utils.tdata_tool
HOME_PATH = test.constants.HOME_PATH
conf = {}
# here you can select single testfunction for developping the tests
# "test_toolhandling", "test_parseSql" -> test of components
TEST_FUNCTIONS = ["test_02getIds", "test_03extractIds", "test_04getFieldVal", "test_05getValue",
"test_11mapTdata"]
TEST_FUNCTIONS = ["test_11mapTdata"]
verbose = False
class MyTestCase(unittest.TestCase):
mymsg = "--------------------------------------------------------------"
def test_03extractIds(self):
global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
if actfunction not in TEST_FUNCTIONS:
return
job = test.testtools.getJob()
res = utils.map_tool.extractIds(job, "1")
self.assertEqual(res, ["1"])
res = utils.map_tool.extractIds(job, "1, 2")
self.assertEqual(res, "1,2".split(","))
res = utils.map_tool.extractIds(job, "1-3")
self.assertEqual(res, "1,2,3".split(","))
res = utils.map_tool.extractIds(job, "1, 3-6, 8")
self.assertEqual(res, "1,3,4,5,6,8".split(","))
cnttest += 4
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)
def test_02getIds(self):
global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
if actfunction not in TEST_FUNCTIONS:
return
job = test.testtools.getJob()
path = utils.config_tool.getConfigPath(P.KEY_TESTCASE, "TC0001", "", job)
tdata = utils.tdata_tool.getCsvSpec(job.m, path, D.CSV_SPECTYPE_DATA)
args = {}
args[B.DATA_NODE_DATA] = tdata
args[B.DATA_NODE_STEPS] = tdata[B.DATA_NODE_STEPS][0]
args[utils.map_tool.ACT_ID] = {}
args[utils.map_tool.ID_LIST] = {}
ids = {}
res = utils.map_tool.getIds(job, args, "msgid={_steps._nr}")
print(res)
self.assertEqual(res[0], "1")
self.assertIn("msgid", args[utils.map_tool.ID_LIST])
cnttest += 1
res = utils.map_tool.getIds(job, args, "sender={_data.person._sender(_steps._nr)}")
print(res)
self.assertEqual(res[0], "firma")
args[B.DATA_NODE_STEPS] = tdata[B.DATA_NODE_STEPS][1]
res = utils.map_tool.getIds(job, args, "msgid={_steps._nr}")
self.assertEqual(res[1], "2")
self.assertIn("msgid", args[utils.map_tool.ID_LIST])
cnttest += 1
args[utils.map_tool.ACT_ID]["msgid"] = "1"
res = utils.map_tool.getIds(job, args, "posid={_data.product._nr,_pos(msgid)}")
self.assertEqual(res[0], ("1", "4"))
self.assertEqual(res[1], ("1", "5"))
cnttest += 1
compName = "testcrmdb"
args[B.DATA_NODE_COMP] = test.testtools.getComp(compName)
comp = args[B.DATA_NODE_COMP]
conf = utils.config_tool.getConfig(D.DDL_FILENAME, compName, "person")
comp.conf[B.DATA_NODE_DDL] = {}
comp.conf[B.DATA_NODE_DDL]["person"] = conf
res = utils.map_tool.getIds(job, args, "fields={_comp.ddl.person}")
print(res)
args[utils.map_tool.ACT_ID]["posid"] = ("1", "4")
res = utils.map_tool.getConditions(job, args, "{posid}")
print(res)
self.assertEqual(res[0], ("1", "4"))
#self.assertEqual(res[1], "4")
cnttest += 1
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)
def test_04getFieldVal(self):
global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
if actfunction not in TEST_FUNCTIONS:
return
job = test.testtools.getJob()
path = utils.config_tool.getConfigPath(P.KEY_TESTCASE, "TC0001", "", job)
tdata = utils.tdata_tool.getCsvSpec(job.m, path, D.CSV_SPECTYPE_DATA)
condIds = [["1"]]
args = {}
args[B.DATA_NODE_DATA] = tdata
res = utils.map_tool.getFieldVal(job, args, "person", "_sender", condIds)
print(res)
condIds = [["1"], ["4"]]
res = utils.map_tool.getFieldVal(job, args, "product", "descript", condIds)
print(res)
def test_05getValue(self):
global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
if actfunction not in TEST_FUNCTIONS:
return
job = test.testtools.getJob()
path = utils.config_tool.getConfigPath(P.KEY_TESTCASE, "TC0001", "", job)
tdata = utils.tdata_tool.getCsvSpec(job.m, path, D.CSV_SPECTYPE_DATA)
condIds = [["1"]]
args = {}
args[B.DATA_NODE_DATA] = tdata
args[B.DATA_NODE_STEPS] = tdata[B.DATA_NODE_STEPS][0]
args[utils.map_tool.ACT_ID] = {}
args[utils.map_tool.ID_LIST] = {}
#res = utils.map_tool.getValue(job, args, "msgid={_steps._nr}")
#-print(res)
#self.assertEqual(res, ['1'])
args[utils.map_tool.ACT_ID]["msgid"] = ['1']
#res = utils.map_tool.getValue(job, args, "sender={_data.person._sender(msgid)}")
#self.assertEqual(res, ["firma"])
#print(res)
print(args[utils.map_tool.ID_LIST])
args[utils.map_tool.ACT_ID]["sender"] = "firma"
res = utils.map_tool.getValue(job, args, "{_catalog.sender.depart(sender)}")
self.assertEqual(res, "main")
res = utils.map_tool.getValue(job, args, "{_steps.args.action}")
print(res)
res = utils.map_tool.getValue(job, args, "{_par.tctime}")
print(res)
args[utils.map_tool.ACT_ID]["msgid"] = "1"
res = utils.map_tool.getValue(job, args, "{_data.person.famname(msgid)}")
print(res)
self.assertEqual(res, "Brecht")
args[utils.map_tool.ACT_ID]["msgid"] = "1"
# select row if field is missing
res = utils.map_tool.getValue(job, args, "{_data.person(msgid)}")
print(res)
res = utils.map_tool.getValue(job, args, "hier ist ein Text")
print(res)
# it is one row [{f_1: v_2, ...}]
def test_11mapTdata(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("testrest")
path = os.path.join(job.conf.confs[B.SUBJECT_PATH][B.ATTR_PATH_COMPS], "testrest", "mapping-rest.yml")
mapping = utils.file_tool.readFileDict(path, job.m)
path = utils.config_tool.getConfigPath(P.KEY_TESTCASE, "TC0001", "", job)
tdata = utils.tdata_tool.getCsvSpec(job.m, path, D.CSV_SPECTYPE_DATA)
res = utils.map_tool.mapTdata(job, mapping, tdata, tdata[B.DATA_NODE_STEPS][1], comp)
print(res)
for format in ["xml", "yml", "json"]:
path = os.path.join(job.conf.confs[B.SUBJECT_PATH][B.ATTR_PATH_TDATA], "temp", "result-rest."+format)
print(path)
utils.file_tool.writeFileDict(job.m, path, res)
doc = json.dumps(res, indent=0)
print(doc)
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)
def test_zzz(self):
print(MyTestCase.mymsg)
if __name__ == '__main__':
verbose = True
unittest.main()