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.

224 lines
10 KiB

3 years ago
import unittest
import os
import inspect
import shutil
2 years ago
import execute_testcase
import utils.path_tool
3 years ago
from basic.program import Job
from basic.componentHandling import ComponentManager
import basic.step
import init_testcase
import test_executer
import test.constants
import basic.constants as B
import test.constants as T
import basic.componentHandling
import utils.file_tool
3 years ago
HOME_PATH = test.constants.HOME_PATH
PYTHON_CMD = "python"
TEST_FUNCTIONS = ["test_tdata", "test_getCsvSpec_data", "test_getCsvSpec_tree", "test_getCsvSpec_key",
"test_getCsvSpec_conf", "test_extractPattern", "test_parseCsv", "test_smokeTestcase"]
2 years ago
TEST_FUNCTIONS = ["test_smokeTestcase"]
3 years ago
class MyTestCase(unittest.TestCase):
mymsg = "--------------------------------------------------------------"
def test_01create(self):
global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
if actfunction not in TEST_FUNCTIONS:
return
job = basic.program.createJob()
print(str(job))
args = { "application" : "TESTAPP" , "environment" : "ENV01", "step": "2", "tcdir": "/home/ulrich/workspace/Datest/data/lauf/TC0001/2022-09-10_12-12-08"}
job.par.setParameterArgs(job, args)
self.assertEqual(getattr(job.par, B.PAR_TESTCASE), "TC0001")
self.assertEqual(getattr(job.par, B.PAR_TCTIME), "2022-09-10_12-12-08")
job.setProgram("init_testcase")
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)
def test_00create(self):
global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
if actfunction not in TEST_FUNCTIONS:
return
#
# start a webflask-job - a temp. job for responding an html-request, - with session-parameter?
args = {}
job = basic.program.Job("webflask", args)
print(str(job.par))
args = { B.PAR_APP: "TESTAPP" , B.PAR_ENV: "ENV01", B.PAR_STEP: "2",
B.PAR_TCDIR: "/home/ulrich/workspace/Datest/data/lauf/TC0001/2022-09-10_12-12-08"}
job = basic.program.Job("unit", args)
print(str(job))
#job.par.setParameterArgs(job, args)
self.assertEqual(hasattr(job.par, B.PAR_TESTCASE), False)
self.assertEqual(hasattr(job.par, B.PAR_TCTIME), False)
self.assertEqual(True, hasattr(job, "m"))
msg = job.m
self.assertNotIn("testdata", msg.logfile.name)
#
# start a testing-job as unit-test - without log ?! - artifacts would be saved in tcdir
# in unit-tests often there is a dir not necessary
args = { B.PAR_APP: "TESTAPP" , B.PAR_ENV: "ENV01", B.PAR_STEP: "1", B.PAR_MODUS: "unit",
B.PAR_TCDIR: "/home/ulrich/workspace/Datest/data/lauf/TC0001/2022-09-10_12-12-08"}
job = basic.program.Job("init_testcase", args)
print(str(job))
self.assertEqual(getattr(job.par, B.PAR_TESTCASE), "TC0001")
self.assertEqual(getattr(job.par, B.PAR_TCTIME), "2022-09-10_12-12-08")
self.assertEqual(hasattr(job, "m"), True)
self.assertNotIn("testdata", msg.logfile.name)
args = { B.PAR_APP: "TESTAPP" , B.PAR_ENV: "ENV01", B.PAR_STEP: "1",
B.PAR_TCDIR: "/home/ulrich/workspace/Datest/data/lauf/TC0001/2022-09-10_12-22-08"}
job = basic.program.Job("init_testcase", args)
print(str(job))
self.assertEqual(getattr(job.par, B.PAR_TESTCASE), "TC0001")
self.assertEqual(getattr(job.par, B.PAR_TCTIME), "2022-09-10_12-22-08")
self.assertEqual(hasattr(job, "m"), True)
self.assertNotIn("testdata", msg.logfile.name)
#
# start a job for workspace-reorganization - appending to central log
args = { B.PAR_APP: "TESTAPP",
B.PAR_TCDIR: "/home/ulrich/workspace/Datest/data/lauf/TC0001/2022-09-10_12-22-08"}
job = basic.program.Job("declare_result", args)
print(str(job.par))
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)
def test_parameter(self):
global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
if actfunction not in TEST_FUNCTIONS:
return
3 years ago
job = Job("unit")
args = { "application" : "TEST" , "environment" : "ENV01", B.PAR_MODUS : "unit", "loglevel" : "debug",
"tool" : "job_tool", "function": "reset_TData,load_TData" }
job.par.setParameterArgs(job, args)
3 years ago
self.assertEqual(job.hascomponente("TestA"), True)
self.assertEqual(job.hasTool("TestA"), False)
self.assertEqual(job.hasTool("job_tool"), True)
self.assertEqual(job.getDebugLevel("file_tool"), 23)
self.assertEqual(job.getDebugLevel("job_tool"), 23)
self.assertEqual(job.hasFunction("reset_TData"), True)
self.assertEqual(job.hasFunction("load_TData"), True)
self.assertEqual(job.hasFunction("read_TData"), False)
3 years ago
args = { "application" : "TEST" , "environment" : "ENV01", "modus" : "unit", "loglevel" : "debug",
"tool" : "job_tool", "tsdir": os.path.join(HOME_PATH, "test", "lauf", "V0.1", "startjob", "2021-08-21_18-ß2-01")}
job.par.setParameterArgs(job, args)
3 years ago
def test_run(self):
global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
if actfunction not in TEST_FUNCTIONS:
return
programs = ["init_testcase"]
testcase = "TC0001"
timexec = "2022-06-28_21-23-34"
fct = "read_TData"
3 years ago
# os.system("python "+os.path.join(HOME_PATH, "check_environment.py")+" -a TEST -e ENV01")
# os.system("python "+os.path.join(HOME_PATH, "init_testsuite.py")+" -a TEST -e ENV01 "
3 years ago
# "-ts "+os.path.join(HOME_PATH, "test","lauf","V0.1","implement_2021-08-28_23-50-51")+" -dt csv -ds implement -dn firstunit")
#os.system(PYTHON_CMD+" "+os.path.join(HOME_PATH,"init_testcase.py")+" -a TEST -e ENV01 "
# "-tc "+os.path.join(HOME_PATH,"test","lauf","V0.1","TC0001","2021-08-28_23-50-51")+" -dt csv -ds implement -dn TC0001")
#args = { "application": "TEST", "environment": "ENV01", "modus": "unit",
# "tool": "job_tool", "tsdir": os.path.join(HOME_PATH,"test","conf","lauf","V0.1","TC0001_2021-08-28_23-50-51")}
#"loglevel": "debug", "tdtyp": "dir",
# "tdsrc": "TC0001", "tdname": "xxx",
if "init_testcase" in programs:
program = "init_testcase"
job = Job("unit")
args = { B.PAR_APP: "TESTAPP", B.PAR_ENV: "ENV01", "modus": "unit", B.PAR_FCT: fct,
B.PAR_TCDIR: os.path.join(job.conf.confs[B.SUBJECT_PATH][B.ATTR_PATH_ARCHIV], testcase, timexec),
"step": 1 }
# "usecase": "TST001", "tstime": "2022-03-17_17-28"}
job.par.setParameterArgs(job, args)
job.setProgram(program)
init_testcase.startPyJob(job)
job.startJob()
#test_executer.start(job)
job.stopJob(1)
3 years ago
def test_smokeTestcase(self):
"""
the functions starts a test-roundtrip with dry unit-tests
1. simulate the test-object - copy results from testdata_preconditions into local env-directory
2. init_testcase - databases as csv in local env-directory
3. simulate the test-object - copy results from testdata_postconditions into local env-directory
4. execute_testcase - send=copy to local env-directory
- receive=read from local env-directory
5. collect_testcase - read from local env-directory
6. compare_testcase -
:return:
"""
global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
if actfunction not in TEST_FUNCTIONS:
return
# basic parameter
programs = ["copy_precondition", "init_testcase", "copy_postcondition", "execute_testcase",
"collect_testcase", "compare_testcase"]
programs = ["execute_testcase"]
testcase = "TC0001"
2 years ago
timexec = "2022-09-17_08-23-34"
fct = "read_TData"
if "init_testcase" in programs:
program = "init_testcase"
2 years ago
ujob = Job("unit", {})
args = {B.PAR_APP: "TESTAPP", B.PAR_ENV: "ENV01",
B.PAR_TCDIR: os.path.join(ujob.conf.confs[B.SUBJECT_PATH][B.ATTR_PATH_ARCHIV], testcase, timexec),
"step": 1}
2 years ago
job = Job("init_testcase", args)
if "copy_precondition" in programs:
copyAppData(job, program, "tdpreexec")
pass
job.startJob()
init_testcase.startPyJob(job)
job.stopJob(1)
if "execute_testcase" in programs:
program = "execute_testcase"
step = basic.step.Step()
step.start = "execute_testcase"
2 years ago
ujob = Job("unit", {})
args = {B.PAR_APP: "TESTAPP", B.PAR_ENV: "ENV01",
B.PAR_TCDIR: os.path.join(ujob.conf.confs[B.SUBJECT_PATH][B.ATTR_PATH_ARCHIV], testcase, timexec),
"step": 2}
2 years ago
job = Job("execute_testcase", args)
job.startJob()
execute_testcase.startPyJob(job)
job.stopJob(1)
print("fertig")
def copyAppData(job, program, tdsource):
cm = basic.componentHandling.ComponentManager.getInstance(job, "init")
print("cm " + str(cm))
cm.initComponents()
comps = cm.getComponents(program)
for c in comps:
comp = cm.getComponent(c)
tdatapath = utils.path_tool.composePattern(job, "{"+tdsource+"}", comp)
envapppath = utils.path_tool.composePattern(job, "{envappdir}", comp)
if os.path.exists(tdatapath):
files = utils.file_tool.getFiles(job.m, job, tdatapath, ".+\.csv", None)
for f in files:
# shutil.copy()
print("cp " + os.path.join(tdatapath, f) + " " + os.path.join(envapppath, f))
utils.file_tool.mkPaths(job, os.path.join(envapppath, f), job.m)
shutil.copy(os.path.join(tdatapath, f), os.path.join(envapppath, f))
print(tdatapath)
3 years ago
if __name__ == '__main__':
unittest.main()