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.
 
 
 

188 lines
7.9 KiB

#!/usr/bin/python
# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------------------------------------------
# Author : Ulrich Carmesin
# Source : gitea.ucarmesin.de
# ---------------------------------------------------------------------------------------------------------
import unittest
import inspect
import basic.program
import utils.path_tool
import basic.toolHandling
import test.constants
import basic.component
import basic.constants as B
import tools.db_abstract
import test.testtools
import utils.config_tool
import utils.data_const as D
import basic.user
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_formatDbRows", "test_10insertion", "test_11selection", "test_12deletion"]
#TEST_FUNCTIONS = ["test_10insertion", "test_11selection"]
TEST_FUNCTIONS = ["test_10insertion","test_12deletion"]
class MyTestCase(unittest.TestCase):
mymsg = "--------------------------------------------------------------"
def test_parseSql(self):
global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
if actfunction not in TEST_FUNCTIONS:
return
job = test.testtools.getJob()
obj = tools.db_abstract.parseConditions("family like !%utz%! and state = !+reg+!")
self.assertEqual(obj[0][3], "and")
self.assertEqual(obj[0][1], "family")
self.assertEqual(obj[1][3], "end")
self.assertEqual(obj[1][1], "state")
obj = tools.db_abstract.parseConditions("family like !%utz%! or state = !+reg+!")
self.assertEqual(obj[0][3], "or")
self.assertEqual(obj[0][1], "family")
self.assertEqual(obj[1][3], "end")
self.assertEqual(obj[1][1], "state")
ddl = utils.config_tool.getConfig(job, D.DDL_FILENAME, "testb1", "lofts")
dbwhere = tools.db_abstract.parseSQLwhere("street like !%utz%! and state = !+reg+!", ddl["testb1"]["lofts"])
self.assertIn("state", dbwhere)
self.assertNotIn("family", dbwhere)
dbwhere = tools.db_abstract.parseSQLwhere("street like !%utz%! and state = !+reg+!", ddl["testb1"]["lofts"])
self.assertIn("state", dbwhere)
self.assertIn("street", dbwhere)
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)
def test_toolhandling(self):
global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
if actfunction not in TEST_FUNCTIONS:
return
job = basic.program.Job("unit")
args = {"application": "TEST", "environment": "ENV01", "modus": "unit", "loglevel": "debug", "tool": "config_tool",
"modus": "unit"}
job.par.setParameterArgs(job, args)
#t = basic.toolHandling.ToolManager()
comp = basic.component.Component()
comp.name = "testb1"
table = "lofts"
comp.conf = {}
comp.conf[B.DATA_NODE_DDL] = {}
comp.conf[B.DATA_NODE_DDL][table] = utils.config_tool.getConfig(job, D.DDL_FILENAME, comp.name, table)
comp.conf[B.SUBJECT_ARTIFACTS] = {}
comp.conf[B.SUBJECT_ARTIFACTS][B.TOPIC_NODE_DB] = {}
comp.conf[B.TOPIC_CONN] = {}
comp.conf[B.TOPIC_CONN][B.TOPIC_NODE_DB] = {}
comp.conf[B.TOPIC_CONN][B.TOPIC_NODE_DB][B.ATTR_TYPE] = "shive"
tool = basic.toolHandling.getDbTool(job, comp)
self.assertRegex(str(type(tool)), 'dbshive_tool.DbFcts')
attr = tool.getDbAttributes(job, "xx")
self.assertRegex(attr[B.ATTR_DB_PARTITION], 'n')
comp.conf[B.TOPIC_CONN][B.TOPIC_NODE_DB][B.ATTR_DB_PARTITION] = "y"
attr = tool.getDbAttributes(job, "xx")
self.assertRegex(attr[B.ATTR_DB_PARTITION], 'y')
comp.conf[B.SUBJECT_ARTIFACTS][B.TOPIC_NODE_DB][B.ATTR_DB_PARTITION] = "z"
attr = tool.getDbAttributes(job, "xx")
self.assertRegex(attr[B.ATTR_DB_PARTITION], 'z')
#
sqls = comp.composeSqlClauses(job, "SELECT * FROM lofts")
print(sqls)
self.assertEqual(sqls["ALL"], "SELECT * FROM .lofts ORDER BY id")
setattr(job.par, B.PAR_DB_WHERE, "street like !%utz%! and state = !+reg+!")
comp.conf[B.SUBJECT_ARTIFACTS][B.TOPIC_NODE_DB][B.ATTR_DB_PARTITION] = "+reg+"
sqls = comp.composeSqlClauses(job, "SELECT * FROM lofts")
print(sqls)
# dummy-comp does not correspond with any comp
#self.assertIn("street", sqls["ALL"]) #assertEqual(("street" in sqls), True)
#self.assertIn("state", sqls["ALL"])
setattr(job.par, B.PAR_DB_WHERE, "family like !%utz%! and state = !+reg+!")
comp.conf[B.SUBJECT_ARTIFACTS][B.TOPIC_NODE_DB][B.ATTR_DB_PARTITION] = "+reg+"
sqls = comp.composeSqlClauses(job, "SELECT * FROM lofts")
print(sqls)
self.assertIn("family", sqls["ALL"])
self.assertIn("state", sqls["ALL"])
setattr(job.par, B.PAR_DB_PARTITION, "BA,FV")
#sqls = comp.composeSqlClauses("SELECT * FROM lofts")
print(sqls)
#tool.deleteRows("deltable")
#tool.selectRows("deltable")
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)
def test_formatDbRows(self):
global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
if actfunction not in TEST_FUNCTIONS:
return
job = test.testtools.getJob()
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)
def test_10insertion(self):
global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
if actfunction not in TEST_FUNCTIONS:
return
job = basic.program.Job("webflask", {})
if B.TOPIC_NODE_DB in job.conf:
dbtype = job.conf[B.TOPIC_NODE_DB][B.ATTR_TYPE]
userentity = basic.user.User(job)
dbi = basic.toolHandling.getDbTool(job, userentity, dbtype)
data = {}
data["user"] = {}
data["user"][B.DATA_NODE_HEADER] = userentity.conf[B.DATA_NODE_DDL]["user"][B.DATA_NODE_HEADER]
data["user"][B.DATA_NODE_DATA] = []
row = {"username": "alfons", "password": "alfons-secret"}
data["user"][B.DATA_NODE_DATA].append(row)
dbi.insertRows("user", data["user"][B.DATA_NODE_DATA], job)
def test_11selection(self):
global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
if actfunction not in TEST_FUNCTIONS:
return
job = basic.program.Job("webflask", {})
if B.TOPIC_NODE_DB in job.conf:
dbtype = job.conf[B.TOPIC_NODE_DB][B.ATTR_TYPE]
userentity = basic.user.User(job)
dbi = basic.toolHandling.getDbTool(job, userentity, dbtype)
rows = dbi.selectRows("user", job)
print (str(rows))
MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest)
def test_12deletion(self):
global mymsg
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
if actfunction not in TEST_FUNCTIONS:
return
job = basic.program.Job("webflask", {})
if B.TOPIC_NODE_DB in job.conf:
dbtype = job.conf[B.TOPIC_NODE_DB][B.ATTR_TYPE]
userentity = basic.user.User(job)
dbi = basic.toolHandling.getDbTool(job, userentity, dbtype)
rows = dbi.selectRows("user", job, "WHERE username = \'alfons\'")
cntpre = len(rows)
print (str(rows))
dbi.deleteRows(job, "user", "WHERE username = \'alfons\'")
rows = dbi.selectRows("user", job, "WHERE username = \'alfons\'")
print (str(rows))
cntpost = len(rows)
self.assertGreaterEqual(cntpre, cntpost)
def test_zzz(self):
print(MyTestCase.mymsg)
if __name__ == '__main__':
unittest.main()