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.
 
 
 

185 lines
7.2 KiB

import traceback
import unittest
import inspect
import basic.program
import tools.path_tool
import basic.componentHandling
import test.constants
import model.component
import basic.constants as B
import tools.db_abstract
import test.testtools
import tools.config_tool
import tools.conn_tool
HOME_PATH = test.constants.HOME_PATH
DATA_PATH = test.constants.DATA_PATH
conf = {}
# here you can select single testfunction for developping the tests
TEST_FUNCTIONS = ["test_00entity", "test_01read_entity",
"test_10actHandler", "test_21createInstance", "test_22createComponent",
"test_23getComponents", "test_24getComponent"]
TEST_FUNCTIONS = ["test_00entity"]
class MyTestCase(unittest.TestCase):
mymsg = "--------------------------------------------------------------"
def test_00entity(self):
"""
test if the class with all interfaces are implemented
:return:
"""
global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
if actfunction not in TEST_FUNCTIONS:
return
job = test.testtools.getJob()
comp = model.component.Component(job)
faults = 0
functionList = ["read_entity", "write_entity", "remove_entity",
"select_entity", "update_entity", "delete_entity"]
try:
func = getattr(comp, "get_schema")
func()
except Exception as e:
print("get_schema: " + str(e))
faults += 1
for function in functionList:
try:
func = getattr(comp, function)
func(job, "testacnt")
except Exception as e:
print(function + ": " +str(e))
faults += 1
self.assertEqual(0, faults)
def test_01read_entity(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 = model.component.Component(job)
comp.read_entity(job, "testact")
def test_22createComponent(self):
global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
if actfunction not in TEST_FUNCTIONS:
return
job = test.testtools.getJob()
cm = basic.componentHandling.ComponentManager.getInstance(job)
cm.createComponent("testpoldb", 0, "")
self.assertIn("testpoldb", cm.comps, "component must be stored")
self.assertEqual(len(cm.comps), 1, "component without subcomponents")
cnttest += 2
cm.createComponent("testprd", 0, "")
self.assertIn("testprd", cm.comps, "component must be stored")
self.assertIn("testprddb", cm.comps, "subcomponent must be stored")
self.assertEqual(len(cm.comps), 3, "2 component with 1 subcomponents")
cnttest += 2
cm.createComponent("testcm", 0, "")
self.assertIn("testcm_01", cm.comps, "multiple component must be stored")
self.assertIn("testcm_02", cm.comps, "multiple component must be stored")
self.assertEqual(len(cm.comps), 6, "2 component with 2 subcomponents and 2 sub-subcomponents")
cnttest += 2
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)
def test_21createInstance(self):
global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
if actfunction not in TEST_FUNCTIONS:
return
job = test.testtools.getJob()
cm = basic.componentHandling.ComponentManager.getInstance(job, "J")
componentName = "testcm"
confs = tools.config_tool.getConfig(job, "comp", componentName)
conns = tools.conn_tool.getConnections(job, componentName)
c = cm.createInstance(componentName, None, confs, conns, 1)
self.assertEqual(hasattr(c, "conf"), True, "config-dict must be")
self.assertEqual(hasattr(c, "m"), True, "message-object must be")
self.assertEqual(c.name, "testcm_01", "classname with number") # classname with number
cnttest += 3
self.assertEqual(c.conf[B.TOPIC_INST][B.ATTR_INST_CNT], 2, "conn-attribute overwrites config-attribute")
cnttest += 1 # it overwrites
self.assertEqual(c.conf[B.TOPIC_INST][B.ATTR_INST_SGL], "n", "without conn-attribute the config-attribute keeps")
cnttest += 1 # it keep
componentName = "testprddb"
confs = tools.config_tool.getConfig(job, "comp", componentName)
conns = tools.conn_tool.getConnections(job, componentName)
c = cm.createInstance(componentName, None, confs, conns, 0)
self.assertEqual(c.name, "testprddb")
self.assertIn(B.ATTR_DB_TYPE, c.conf[B.SUBJECT_ARTIFACTS][B.TOPIC_NODE_DB], "conn-attribute creates missing config-attribute")
cnttest += 2 # new attributes
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)
def test_10actHandler(self):
global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
if actfunction not in TEST_FUNCTIONS:
return
job = test.testtools.getJob()
cm = basic.componentHandling.ComponentManager.getInstance(job, "J")
self.assertIsNotNone(cm)
self.assertEqual(len(cm.components), 0)
cnttest += 2
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)
def test_23getComponents(self):
global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
if actfunction not in TEST_FUNCTIONS:
return
job = test.testtools.getJob()
cm = basic.componentHandling.ComponentManager.getInstance(job)
cm.createComponent("testcm", 0, "")
cm.createComponent("testcrm", 0, "")
prog = "init_testcase"
comps = cm.getComponents(prog)
self.assertEqual(len(comps), 7, "not all created comps for program "+prog)
prog = "check_environment"
comps = cm.getComponents(prog)
self.assertEqual(len(comps), 8, "all created comps for program "+prog)
cnttest += 2
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)
def test_24getComponent(self):
global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
if actfunction not in TEST_FUNCTIONS:
return
job = test.testtools.getJob()
print("jobid "+job.jobid)
cm = basic.componentHandling.ComponentManager.getInstance(job)
cm.createComponent("testcm", 0, "")
self.assertEqual(len(cm.comps), 6, "6 components inside")
comp = cm.getComponent("testprd")
self.assertEqual(len(cm.comps), 6, "6 components inside")
self.assertEqual(comp.name, "testprd", "component found")
cnttest += 2
comp = cm.getComponent("testcrm")
self.assertEqual(len(cm.comps), 6, "6 components inside and nothing added")
self.assertIsNotNone("terstcrm")
cnttest += 2
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)
def test_zzz(self):
print(MyTestCase.mymsg)
if __name__ == '__main__':
unittest.main()