|
@ -2,9 +2,9 @@ import unittest |
|
|
import os |
|
|
import os |
|
|
import inspect |
|
|
import inspect |
|
|
import shutil |
|
|
import shutil |
|
|
|
|
|
""" |
|
|
import execute_testcase |
|
|
import execute_testcase |
|
|
import utils.path_tool |
|
|
import tools.path_tool |
|
|
from basic.program import Job |
|
|
from basic.program import Job |
|
|
from basic.componentHandling import ComponentManager |
|
|
from basic.componentHandling import ComponentManager |
|
|
import basic.step |
|
|
import basic.step |
|
@ -12,211 +12,37 @@ import init_testcase |
|
|
import test_executer |
|
|
import test_executer |
|
|
import test.constants |
|
|
import test.constants |
|
|
import basic.constants as B |
|
|
import basic.constants as B |
|
|
import test.constants as T |
|
|
|
|
|
import basic.componentHandling |
|
|
import basic.componentHandling |
|
|
import utils.file_tool |
|
|
import tools.file_tool |
|
|
|
|
|
""" |
|
|
|
|
|
import basic.program |
|
|
|
|
|
import tools.job_tool as job_tool |
|
|
|
|
|
import test.constants as T |
|
|
|
|
|
import test.testtools |
|
|
|
|
|
|
|
|
HOME_PATH = test.constants.HOME_PATH |
|
|
HOME_PATH = T.HOME_PATH |
|
|
PYTHON_CMD = "python" |
|
|
PYTHON_CMD = "python" |
|
|
TEST_FUNCTIONS = ["test_tdata", "test_getCsvSpec_data", "test_getCsvSpec_tree", "test_getCsvSpec_key", |
|
|
#TEST_FUNCTIONS = [ "test_smokeTestcase"] |
|
|
"test_getCsvSpec_conf", "test_extractPattern", "test_parseCsv", "test_smokeTestcase"] |
|
|
TEST_FUNCTIONS = ["test_actProgram"] |
|
|
TEST_FUNCTIONS = ["test_smokeTestcase"] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PROGRAM_NAME = "unit_tester" |
|
|
|
|
|
|
|
|
class MyTestCase(unittest.TestCase): |
|
|
class MyTestCase(unittest.TestCase): |
|
|
mymsg = "--------------------------------------------------------------" |
|
|
mymsg = "--------------------------------------------------------------" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_01create(self): |
|
|
def test_actProgram(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 |
|
|
|
|
|
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) |
|
|
|
|
|
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) |
|
|
|
|
|
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) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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" |
|
|
|
|
|
# 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 " |
|
|
|
|
|
# "-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) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
|
|
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 |
|
|
# basic parameter |
|
|
job = test.testtools.getTestJob() |
|
|
programs = ["copy_precondition", "init_testcase", "copy_postcondition", "execute_testcase", |
|
|
print("test_actProgram ++++++++++++++++++") |
|
|
"collect_testcase", "compare_testcase"] |
|
|
print("job "+str(job.__dict__)) |
|
|
programs = ["execute_testcase"] |
|
|
args = job_tool.read_child_args(job) |
|
|
testcase = "TC0001" |
|
|
print("args "+str(args)) |
|
|
timexec = "2022-09-17_08-23-34" |
|
|
job_tool.start_child_process(job, args) |
|
|
fct = "read_TData" |
|
|
|
|
|
if "init_testcase" in programs: |
|
|
|
|
|
program = "init_testcase" |
|
|
|
|
|
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} |
|
|
|
|
|
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" |
|
|
|
|
|
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} |
|
|
|
|
|
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) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
|
if __name__ == '__main__': |
|
|