Browse Source

refactor model and test

refactor
Ulrich 1 year ago
parent
commit
351962f1de
  1. 4
      basic/Testserver.py
  2. 2
      basic/connection.py
  3. 141
      model/application.py
  4. 8
      model/entity.py
  5. 9
      model/factory.py
  6. 9
      model/project.py
  7. 8
      model/release.py
  8. 8
      model/story.py
  9. 2
      model/table.py
  10. 8
      model/user.py
  11. 4
      test/test_14table.py
  12. 12
      test/test_15user.py
  13. 33
      test/test_16project.py
  14. 27
      test/test_17release.py
  15. 15
      test/test_17story.py
  16. 13
      test/test_20application.py
  17. 2
      test/test_90testserver.py
  18. 17
      tools/db_abstract.py
  19. 27
      tools/dbmysql_tool.py
  20. 3
      tools/job_tool.py
  21. 3
      unit_tester.py

4
basic/Testserver.py

@ -9,6 +9,7 @@ import tools.data_const as D
import tools.file_tool import tools.file_tool
import tools.filecsv_fcts import tools.filecsv_fcts
import model.table import model.table
import model.factory
import tools.value_tool import tools.value_tool
import tools.data_tool import tools.data_tool
@ -20,6 +21,7 @@ COMP_TABLES = ["application", "ap_component", "ap_project", "ap_application",
class Testserver(): class Testserver():
""" """
the Testserver represents the workspace with all resources for the automation the Testserver represents the workspace with all resources for the automation
""" """
tables = {} tables = {}
def __init__(self, job): def __init__(self, job):
@ -39,7 +41,7 @@ class Testserver():
# TODO was muss auf dem Testserver initial geladen werden? # TODO was muss auf dem Testserver initial geladen werden?
self.model = {} self.model = {}
for s in B.LIST_SUBJECTS: for s in B.LIST_SUBJECTS:
self.model[tools.data_tool.getSingularKeyword(s)] = {} self.model[tools.data_tool.getSingularKeyword(s)] = model.factory.get_entity_object(job, s, {})
def restInit(self): def restInit(self):
if not B.DATA_NODE_DDL in self.conf: if not B.DATA_NODE_DDL in self.conf:

2
basic/connection.py

@ -5,7 +5,7 @@
# Source : gitea.ucarmesin.de # Source : gitea.ucarmesin.de
# --------------------------------------------------------------------------------------------------------- # ---------------------------------------------------------------------------------------------------------
import basic.toolHandling import basic.toolHandling
import utils.data_const as D import tools.data_const as D
import basic.constants as B import basic.constants as B
import model.entity import model.entity

141
model/application.py

@ -5,6 +5,7 @@
print("is importing module.app") print("is importing module.app")
import os import os
import basic.program
import basic.toolHandling import basic.toolHandling
import basic.constants as B import basic.constants as B
import model.entity import model.entity
@ -232,14 +233,16 @@ def insertEntities(job,applData, dbTime, dbi):
class Application(model.entity.Entity): class Application(model.entity.Entity):
table = "application" """ table = "application"
job = None
name = "" name = ""
description = "" description = ""
reference = "" reference = ""
components = {} components = {}
project = {} project = {}
"""
def __int__(self, job, project=""): def __init__(self, job):
self.job = job self.job = job
def read_unique_names(self, job, project, application, gran, args): def read_unique_names(self, job, project, application, gran, args):
@ -300,137 +303,3 @@ class Application(model.entity.Entity):
:return: :return:
""" """
return self.name return self.name
class Application_old(model.entity.Entity):
table = "application"
name = ""
description = ""
reference = ""
component = []
project = {}
def __init__(self, job, name=""):
"""
to be initialized by readSpec
:param job:
"""
self.job = job
if len(name) > 1:
self.getEntity(job, name)
def getEntity(self, job, name):
if B.TOPIC_NODE_DB in job.conf:
self.select_entity(job, name)
#self.read_entity(job, name)
else:
self.read_entity(job, name)
def read_entity(self, job, app):
apppath = tools.config_tool.select_config_path(job, P.KEY_BASIC, B.SUBJECT_APPS, "")
repopath = apppath[len(job.conf[B.TOPIC_PATH][B.ATTR_PATH_COMPS]) + 1:]
gitresult = tools.git_tool.gitLog(job, B.ATTR_PATH_COMPS, repopath, 1)
applData = tools.config_tool.getConfig(job, P.KEY_BASIC, B.SUBJECT_APPS)
# main object
for f in job.testserver.conf[B.DATA_NODE_DDL][TABLE_NAMES[0]][B.DATA_NODE_HEADER]:
if f == model.entity.ENTITY_NAME:
setattr(self, f, app)
elif f == model.entity.ENTITY_ATTRIBUTES:
setattr(self, f, {})
elif f in applData[B.SUBJECT_APPS][app]:
setattr(self, f, applData[B.SUBJECT_APPS][app][f])
elif f in model.entity.ENTITY_FIELDS:
setattr(self, f, model.entity.getEntityValue(job, f, gitresult[0]))
else:
setattr(self, f, "xx")
project = {}
if applData[B.SUBJECT_APPS][app][B.SUBJECT_PROJECTS] is not None:
for proj in applData[B.SUBJECT_APPS][app][B.SUBJECT_PROJECTS]:
project[proj] = {}
for f in job.testserver.conf[B.DATA_NODE_DDL][TABLE_NAMES[1]][B.DATA_NODE_HEADER]:
if f == model.entity.ENTITY_NAME:
project[proj][f] = proj
elif f == "project":
project[proj][f] = proj
elif f == model.entity.ENTITY_ATTRIBUTES:
project[proj][f] = {}
elif f in applData[B.SUBJECT_PROJECTS][proj]:
project[proj][f] = applData[B.SUBJECT_PROJECTS][proj][f]
elif f in model.entity.ENTITY_FIELDS:
project[proj][f] = model.entity.getEntityValue(job, f, gitresult[0])
else:
project[proj][f] = "xx"
setattr(self, "project", project)
component = []
if applData[B.SUBJECT_APPS][app][B.SUBJECT_COMPS] is not None:
for comp in applData[B.SUBJECT_APPS][app][B.SUBJECT_COMPS]:
component.append(comp)
setattr(self, "component", component)
def getApplicationRows(self, job):
rows = []
row = {}
for f in job.testserver.conf[B.DATA_NODE_DDL][TABLE_NAMES[0]][B.DATA_NODE_HEADER]:
row[f] = getattr(self, f)
rows.append(row)
return rows
def getAppProjectRows(self, job, apid):
rows = []
for proj in self.project:
row = {}
for f in job.testserver.conf[B.DATA_NODE_DDL][TABLE_NAMES[1]][B.DATA_NODE_HEADER]:
if f == "apid":
row[f] = apid
elif f in self.project[proj]:
row[f] = self.project[proj][f]
rows.append(row)
return rows
def getAppComponentRows(self, job, apid):
rows = []
for comp in self.component:
row = {}
row["apid"] = apid
row["component"] = comp
rows.append(row)
return rows
def select_entity(self, job, app):
dbi = basic.toolHandling.getDbTool(job, job.testserver, job.conf[B.TOPIC_NODE_DB][B.ATTR_TYPE])
data = dbi.selectRows(TABLE_NAMES[0], job, "WHERE name = \'" + app +"\' AND actual = " + model.entity.ENTITY_ACTUAL)
# main object
self.setAppRow(data[B.DATA_NODE_DATA][0], app)
apid = getattr(self, "apid")
data = dbi.selectRows(TABLE_NAMES[1], job, "WHERE apid = "+str(apid))
self.setProjRow(data[B.DATA_NODE_DATA])
data = dbi.selectRows(TABLE_NAMES[2], job, "WHERE apid = " + str(apid))
self.setCompRow(data[B.DATA_NODE_DATA])
def setAppRow(self, row, app):
for f in self.job.testserver.conf[B.DATA_NODE_DDL][TABLE_NAMES[0]][B.DATA_NODE_HEADER]:
if f not in row and f == model.entity.ENTITY_NAME:
setattr(self, f, app)
else:
setattr(self, f, str(row[f]))
def setProjRow(self, rows):
project = {}
for row in rows:
project[row["project"]] = row
setattr(self, "project", project)
def setCompRow(self, rows):
component = []
for row in rows:
component.append(row["component"])
setattr(self, "component", component)
def insertEntity(self, dbi=None):
job = self.job
rows = self.getApplicationRows(job)
apid = dbi.insertRows(job, TABLE_NAMES[0], rows)
rows = self.getAppProjectRows(job, apid)
dbi.insertRows(job, TABLE_NAMES[1], rows)
rows = self.getAppComponentRows(job, apid)
dbi.insertRows(job, TABLE_NAMES[2], rows)
def writeEntity(self):
pass

8
model/entity.py

@ -55,10 +55,10 @@ def getEntityValue(job, field, gitcommit):
class Entity: class Entity:
def __int__(self, job): def __init__(self, job, name=""):
self.job = job self.job = job
self.table = "" if len(name) > 1:
self.testserver = None self.getEntity(job, name)
def get_unique_names(self, job, storage="", project="", application="", gran="", args={}): def get_unique_names(self, job, storage="", project="", application="", gran="", args={}):
""" """
@ -314,6 +314,8 @@ class Entity:
verify = False verify = False
if not job is None: if not job is None:
self.job = job self.job = job
if rootname not in config:
return self
for k in fields + nodes: for k in fields + nodes:
key = tools.data_tool.getExistKeyword(k, config[rootname]) key = tools.data_tool.getExistKeyword(k, config[rootname])
if verify: print("setFields " + k + " / " + key) if verify: print("setFields " + k + " / " + key)

9
model/factory.py

@ -2,6 +2,7 @@ import model.entity
import basic.constants as B import basic.constants as B
def get_entity_object(job, name, args): def get_entity_object(job, name, args):
if name in B.SUBJECT_STEPS: if name in B.SUBJECT_STEPS:
entity = getStep(job) entity = getStep(job)
elif name in B.SUBJECT_STORIES: elif name in B.SUBJECT_STORIES:
@ -13,7 +14,7 @@ def get_entity_object(job, name, args):
elif name in B.SUBJECT_USECASES: elif name in B.SUBJECT_USECASES:
entity = getUsecase(job) entity = getUsecase(job)
elif name in B.SUBJECT_PROJECTS: elif name in B.SUBJECT_PROJECTS:
entity = getApplication(job) entity = getProject(job)
elif name in B.SUBJECT_APPS: elif name in B.SUBJECT_APPS:
entity = getApplication(job) entity = getApplication(job)
elif name in B.SUBJECT_COMPS: elif name in B.SUBJECT_COMPS:
@ -33,9 +34,9 @@ def getEnvironment(job=None):
import model.environment import model.environment
return model.environment.Environment(job) return model.environment.Environment(job)
def getApplication(job=None, name=""): def getApplication(job=None, args={}, name=""):
import model.application import model.application
return model.application.Application() return model.application.Application(job)
def getProject(job=None, name=""): def getProject(job=None, name=""):
import model.project import model.project
@ -63,7 +64,7 @@ def getStep(job=None, project="", name=""):
def getStory(job=None, project="", name=""): def getStory(job=None, project="", name=""):
import model.story import model.story
return model.story.Story(job, project, name) return model.story.Story(job, name)
def getUsecase(job=None, project="", name=""): def getUsecase(job=None, project="", name=""):
import model.usecase import model.usecase

9
model/project.py

@ -35,11 +35,6 @@ class Project(model.entity.Entity):
description = "" description = ""
reference = "" reference = ""
def __int__(self, job, name=""):
self.job = job
if len(name) > 1:
self.getEntity(job, name)
def read_unique_names(self, job, project, application, gran, args): def read_unique_names(self, job, project, application, gran, args):
""" """
reads the entity-names from file-storage reads the entity-names from file-storage
@ -174,14 +169,14 @@ class Project(model.entity.Entity):
:return: :return:
""" """
config = {} config = {}
config[model.user.TABLE_NAME] = {} config[model.project.TABLE_NAME] = {}
pathname = os.path.join(job.conf[B.TOPIC_PATH][P.ATTR_PATH_HOME], P.VAL_CONFIG, pathname = os.path.join(job.conf[B.TOPIC_PATH][P.ATTR_PATH_HOME], P.VAL_CONFIG,
P.VAL_USER, name + ".yml") P.VAL_USER, name + ".yml")
for k in LIST_FIELDS: for k in LIST_FIELDS:
if getattr(self, k, "") == "" \ if getattr(self, k, "") == "" \
or k == FIELD_ID: or k == FIELD_ID:
continue continue
config[model.user.TABLE_NAME][k] = getattr(self, k, "") config[model.project.TABLE_NAME][k] = getattr(self, k, "")
tools.file_tool.write_file_dict(job.m, job, pathname, config) tools.file_tool.write_file_dict(job.m, job, pathname, config)
return self return self

8
model/release.py

@ -41,14 +41,6 @@ class Release(model.entity.Entity):
attributes = "" attributes = ""
reference = "" reference = ""
def __init__(self, job, project, name=""):
"""
to be initialized by readSpec
:param job:
"""
self.job = job
self.project = project
def read_unique_names(self, job, project, application, gran, args): def read_unique_names(self, job, project, application, gran, args):
""" """
reads the entity-names from file-storage reads the entity-names from file-storage

8
model/story.py

@ -36,14 +36,6 @@ class Story(model.entity.Entity):
description = "" description = ""
reference = "" reference = ""
def __init__(self, job, project, name=""):
"""
to be initialized by readSpec
:param job:
"""
self.job = job
self.project = project
def read_unique_names(self, job, project, application, gran, args): def read_unique_names(self, job, project, application, gran, args):
""" """
reads the entity-names from file-storage reads the entity-names from file-storage

2
model/table.py

@ -75,7 +75,7 @@ class Table(model.entity.Entity):
fieldnames = [] fieldnames = []
fielddef = {} fielddef = {}
def __init__(self, job, project="", name=""): def __init__(self, job, project="", application="", component=None, name=""):
""" """
to be initialized to be initialized
:param job: :param job:

8
model/user.py

@ -44,7 +44,7 @@ class User(model.entity.Entity):
project = "" project = ""
role = "" role = ""
def __int__(self, job, name=""): def xx__init__(self, job, name=""):
self.job = job self.job = job
if len(name) > 1: if len(name) > 1:
self.getEntity(job, name) self.getEntity(job, name)
@ -258,9 +258,13 @@ class User(model.entity.Entity):
self.setDbAttributes(job, [TABLE_NAME]) self.setDbAttributes(job, [TABLE_NAME])
dbi = basic.toolHandling.getDbTool(job, self, job.conf[B.TOPIC_NODE_DB]["type"]) dbi = basic.toolHandling.getDbTool(job, self, job.conf[B.TOPIC_NODE_DB]["type"])
condition = "where" condition = "where"
if B.DATA_NODE_KEYS in self.conf[B.DATA_NODE_DDL][table]:
keys = self.conf[B.DATA_NODE_DDL][table][B.DATA_NODE_KEYS]
else:
keys = self.conf[B.DATA_NODE_DDL][table]
for f in IDENTIFYER_FIELDS: for f in IDENTIFYER_FIELDS:
# TODO other db-formats than string has to be implemented # TODO other db-formats than string has to be implemented
val = dbi.getDbValue(self.conf[B.DATA_NODE_DDL][table][f], getattr(self, f, "")) val = dbi.getDbValue(keys[f], getattr(self, f, ""))
condition += " and " + f + " = " + val + "" condition += " and " + f + " = " + val + ""
condition = condition.replace("where and", "where ") condition = condition.replace("where and", "where ")
dbi.deleteRows(job, table, condition) dbi.deleteRows(job, table, condition)

4
test/test_14table.py

@ -15,9 +15,9 @@ import model.entity
HOME_PATH = test.constants.HOME_PATH HOME_PATH = test.constants.HOME_PATH
PYTHON_CMD = "python" PYTHON_CMD = "python"
TEST_FUNCTIONS = ["test_10getEntityNames", "test_11getEntities", "test_12getEntity", TEST_FUNCTIONS = ["test_10getEntityNames", "test_11getEntities", "test_12getEntity",
"test_13writeEntity", "test_14insertEntity", # "test_14insertEntity", # "test_13writeEntity",
"test_20getSchema"] "test_20getSchema"]
TEST_FUNCTIONS = ["test_20getSchema"] #TEST_FUNCTIONS = ["test_11getEntities"]
PROGRAM_NAME = "clean_workspace" PROGRAM_NAME = "clean_workspace"
class MyTestCase(unittest.TestCase): class MyTestCase(unittest.TestCase):

12
test/test_15user.py

@ -16,7 +16,7 @@ HOME_PATH = test.constants.HOME_PATH
PYTHON_CMD = "python" PYTHON_CMD = "python"
TEST_FUNCTIONS = ["test_10getEntityNames", "test_11getEntities", "test_12getEntity", TEST_FUNCTIONS = ["test_10getEntityNames", "test_11getEntities", "test_12getEntity",
"test_13writeEntity", "test_14insertEntity"] "test_13writeEntity", "test_14insertEntity"]
TEST_FUNCTIONS = ["test_14insertEntity"] # TEST_FUNCTIONS = ["test_14insertEntity"]
PROGRAM_NAME = "clean_workspace" PROGRAM_NAME = "clean_workspace"
class MyTestCase(unittest.TestCase): class MyTestCase(unittest.TestCase):
@ -31,7 +31,7 @@ class MyTestCase(unittest.TestCase):
if actfunction not in TEST_FUNCTIONS: if actfunction not in TEST_FUNCTIONS:
return return
job = test.testtools.getJob() job = test.testtools.getJob()
user = model.user.User() user = model.user.User(job)
entityNames = [] entityNames = []
entityNames = user.read_unique_names(job, "", "", "", {}) entityNames = user.read_unique_names(job, "", "", "", {})
self.assertEquals(type(entityNames), list) self.assertEquals(type(entityNames), list)
@ -46,7 +46,7 @@ class MyTestCase(unittest.TestCase):
if actfunction not in TEST_FUNCTIONS: if actfunction not in TEST_FUNCTIONS:
return return
job = test.testtools.getJob() job = test.testtools.getJob()
user = model.user.User() user = model.user.User(job)
entityNames = [] entityNames = []
entityNames = user.get_entities(job, storage=model.entity.STORAGE_FILE) entityNames = user.get_entities(job, storage=model.entity.STORAGE_FILE)
self.assertEqual(type(entityNames), list) self.assertEqual(type(entityNames), list)
@ -61,7 +61,7 @@ class MyTestCase(unittest.TestCase):
if actfunction not in TEST_FUNCTIONS: if actfunction not in TEST_FUNCTIONS:
return return
job = test.testtools.getJob() job = test.testtools.getJob()
user = model.user.User() user = model.user.User(job)
name = "ulrich" name = "ulrich"
actUser = user.read_entity(job, name) actUser = user.read_entity(job, name)
self.assertEqual(getattr(actUser, model.user.FIELD_USERNAME), name) self.assertEqual(getattr(actUser, model.user.FIELD_USERNAME), name)
@ -80,7 +80,7 @@ class MyTestCase(unittest.TestCase):
return return
job = test.testtools.getJob() job = test.testtools.getJob()
username = "hans_xyz" username = "hans_xyz"
user = model.user.User() user = model.user.User(job)
entityNames = user.get_unique_names(job, storage=model.entity.STORAGE_FILE) entityNames = user.get_unique_names(job, storage=model.entity.STORAGE_FILE)
self.assertNotIn(username, entityNames) self.assertNotIn(username, entityNames)
user.username = username user.username = username
@ -105,7 +105,7 @@ class MyTestCase(unittest.TestCase):
return return
job = test.testtools.getJob() job = test.testtools.getJob()
username = "hans_xyz" username = "hans_xyz"
user = model.user.User() user = model.user.User(job)
entityNames = collectInnerList(user.get_unique_names(job, storage=model.entity.STORAGE_DB)) entityNames = collectInnerList(user.get_unique_names(job, storage=model.entity.STORAGE_DB))
#self.assertNotIn(username, entityNames) #self.assertNotIn(username, entityNames)
user.username = username user.username = username

33
test/test_16project.py

@ -13,8 +13,9 @@ import model.entity
HOME_PATH = test.constants.HOME_PATH HOME_PATH = test.constants.HOME_PATH
PYTHON_CMD = "python" PYTHON_CMD = "python"
TEST_FUNCTIONS = ["test_10getEntityNames", "test_11getEntities", "test_12getEntity", TEST_FUNCTIONS = ["test_10getEntityNames", "test_11getEntities", "test_12getEntity",
"test_13writeEntity", "test_14insertEntity"] "test_13writeEntity" #, "test_14insertEntity"
TEST_FUNCTIONS = ["test_10getEntityNames", "test_12getEntity"] ]
#TEST_FUNCTIONS = ["test_10getEntityNames", "test_12getEntity"]
PROGRAM_NAME = "clean_workspace" PROGRAM_NAME = "clean_workspace"
class MyTestCase(unittest.TestCase): class MyTestCase(unittest.TestCase):
@ -29,7 +30,7 @@ class MyTestCase(unittest.TestCase):
if actfunction not in TEST_FUNCTIONS: if actfunction not in TEST_FUNCTIONS:
return return
job = test.testtools.getJob() job = test.testtools.getJob()
project = model.project.Project() project = model.project.Project(job)
entityNames = [] entityNames = []
entityNames = project.read_unique_names(job, "", "", "", {}) entityNames = project.read_unique_names(job, "", "", "", {})
self.assertEquals(type(entityNames), list) self.assertEquals(type(entityNames), list)
@ -44,12 +45,12 @@ class MyTestCase(unittest.TestCase):
if actfunction not in TEST_FUNCTIONS: if actfunction not in TEST_FUNCTIONS:
return return
job = test.testtools.getJob() job = test.testtools.getJob()
project = model.project.Project() project = model.project.Project(job)
entityNames = [] entityNames = []
entityNames = project.get_entities(job, storage=model.entity.STORAGE_FILE) entityNames = project.get_entities(job, storage=model.entity.STORAGE_FILE)
self.assertEqual(type(entityNames), list) self.assertEqual(type(entityNames), list)
entityNames = project.get_entities(job, storage=model.entity.STORAGE_DB) #entityNames = project.get_entities(job, storage=model.entity.STORAGE_DB)
self.assertEqual(type(entityNames), list) #self.assertEqual(type(entityNames), list)
def test_12getEntity(self): def test_12getEntity(self):
global mymsg global mymsg
@ -59,7 +60,7 @@ class MyTestCase(unittest.TestCase):
if actfunction not in TEST_FUNCTIONS: if actfunction not in TEST_FUNCTIONS:
return return
job = test.testtools.getJob() job = test.testtools.getJob()
project = model.project.Project() project = model.project.Project(job)
name = "TESTPROJ" name = "TESTPROJ"
actproject = project.read_entity(job, name) actproject = project.read_entity(job, name)
self.assertEqual(getattr(actproject, model.project.FIELD_NAME), name) self.assertEqual(getattr(actproject, model.project.FIELD_NAME), name)
@ -77,22 +78,6 @@ class MyTestCase(unittest.TestCase):
if actfunction not in TEST_FUNCTIONS: if actfunction not in TEST_FUNCTIONS:
return return
job = test.testtools.getJob() job = test.testtools.getJob()
username = "hans_xyz"
project = model.project.Project()
entityNames = project.get_unique_names(job, storage=model.entity.STORAGE_FILE)
self.assertNotIn(username, entityNames)
project.username = username
project.name = "Hans"
project.famname = "im Glueck"
project.project = "TESTPROJ"
project.write_entity(job, username)
entityNames = project.get_unique_names(job, storage=model.entity.STORAGE_FILE)
self.assertIn(username, entityNames)
actUser = project.read_entity(job, username)
self.assertEquals(getattr(actUser, model.project.FIELD_USERNAME), username)
actUser.remove_entity(job, username)
entityNames = project.get_unique_names(job, storage=model.entity.STORAGE_FILE)
self.assertNotIn(username, entityNames)
def test_14insertEntity(self): def test_14insertEntity(self):
global mymsg global mymsg
@ -103,7 +88,7 @@ class MyTestCase(unittest.TestCase):
return return
job = test.testtools.getJob() job = test.testtools.getJob()
username = "hans_xyz" username = "hans_xyz"
project = model.project.Project() project = model.project.Project(job)
entityNames = collectInnerList(project.get_unique_names(job, storage=model.entity.STORAGE_DB)) entityNames = collectInnerList(project.get_unique_names(job, storage=model.entity.STORAGE_DB))
#self.assertNotIn(username, entityNames) #self.assertNotIn(username, entityNames)
project.username = username project.username = username

27
test/test_17release.py

@ -15,8 +15,9 @@ import model.entity
HOME_PATH = test.constants.HOME_PATH HOME_PATH = test.constants.HOME_PATH
PYTHON_CMD = "python" PYTHON_CMD = "python"
TEST_FUNCTIONS = ["test_10getEntityNames", "test_11getEntities", "test_12getEntity", TEST_FUNCTIONS = ["test_10getEntityNames", "test_11getEntities", "test_12getEntity",
"test_13writeEntity", "test_14insertEntity"] "test_13writeEntity" #, "test_14insertEntity"
TEST_FUNCTIONS = ["test_10getEntityNames", "test_12getEntity"] ]
# TEST_FUNCTIONS = ["test_10getEntityNames", "test_12getEntity"]
PROGRAM_NAME = "clean_workspace" PROGRAM_NAME = "clean_workspace"
class MyTestCase(unittest.TestCase): class MyTestCase(unittest.TestCase):
@ -31,7 +32,7 @@ class MyTestCase(unittest.TestCase):
if actfunction not in TEST_FUNCTIONS: if actfunction not in TEST_FUNCTIONS:
return return
job = test.testtools.getJob() job = test.testtools.getJob()
release = model.release.Release(job, "TESTPROJ") release = model.release.Release(job)
entityNames = [] entityNames = []
entityNames = release.read_unique_names(job, "", "", "", {}) entityNames = release.read_unique_names(job, "", "", "", {})
self.assertEquals(type(entityNames), list) self.assertEquals(type(entityNames), list)
@ -46,7 +47,7 @@ class MyTestCase(unittest.TestCase):
if actfunction not in TEST_FUNCTIONS: if actfunction not in TEST_FUNCTIONS:
return return
job = test.testtools.getJob() job = test.testtools.getJob()
release = model.release.Release(job, "TESTPROJ") release = model.release.Release(job)
entityNames = [] entityNames = []
entityNames = release.get_entities(job, storage=model.entity.STORAGE_FILE) entityNames = release.get_entities(job, storage=model.entity.STORAGE_FILE)
self.assertEqual(type(entityNames), list) self.assertEqual(type(entityNames), list)
@ -61,7 +62,7 @@ class MyTestCase(unittest.TestCase):
if actfunction not in TEST_FUNCTIONS: if actfunction not in TEST_FUNCTIONS:
return return
job = test.testtools.getJob() job = test.testtools.getJob()
release = model.release.Release(job, "TESTPROJ") release = model.release.Release(job)
name = "V-1.1.0" name = "V-1.1.0"
actrelease = release.read_entity(job, name) actrelease = release.read_entity(job, name)
self.assertEqual(getattr(actrelease, model.release.FIELD_NAME), name) self.assertEqual(getattr(actrelease, model.release.FIELD_NAME), name)
@ -79,22 +80,6 @@ class MyTestCase(unittest.TestCase):
if actfunction not in TEST_FUNCTIONS: if actfunction not in TEST_FUNCTIONS:
return return
job = test.testtools.getJob() job = test.testtools.getJob()
username = "hans_xyz"
release = model.release.Release()
entityNames = release.get_unique_names(job, storage=model.entity.STORAGE_FILE)
self.assertNotIn(username, entityNames)
release.username = username
release.name = "Hans"
release.famname = "im Glueck"
release.project = "TESTPROJ"
release.write_entity(job, username)
entityNames = release.get_unique_names(job, storage=model.entity.STORAGE_FILE)
self.assertIn(username, entityNames)
actUser = release.read_entity(job, username)
self.assertEquals(getattr(actUser, model.release.FIELD_NAME), username)
actUser.remove_entity(job, username)
entityNames = release.get_unique_names(job, storage=model.entity.STORAGE_FILE)
self.assertNotIn(username, entityNames)
def test_14insertEntity(self): def test_14insertEntity(self):
global mymsg global mymsg

15
test/test_17story.py

@ -14,9 +14,10 @@ import model.entity
HOME_PATH = test.constants.HOME_PATH HOME_PATH = test.constants.HOME_PATH
PYTHON_CMD = "python" PYTHON_CMD = "python"
TEST_FUNCTIONS = ["test_10getEntityNames", "test_11getEntities", "test_12getEntity", TEST_FUNCTIONS = ["test_10getEntityNames", "test_11getEntities", "test_12getEntity"
"test_13writeEntity", "test_14insertEntity"] # , "test_13writeEntity" #, "test_14insertEntity"
TEST_FUNCTIONS = ["test_10getEntityNames", "test_12getEntity"] ]
# TEST_FUNCTIONS = ["test_10getEntityNames", "test_12getEntity"]
PROGRAM_NAME = "clean_workspace" PROGRAM_NAME = "clean_workspace"
class MyTestCase(unittest.TestCase): class MyTestCase(unittest.TestCase):
@ -31,7 +32,7 @@ class MyTestCase(unittest.TestCase):
if actfunction not in TEST_FUNCTIONS: if actfunction not in TEST_FUNCTIONS:
return return
job = test.testtools.getJob() job = test.testtools.getJob()
story = model.story.Story(job, "TESTPROJ") story = model.story.Story(job)
entityNames = story.read_unique_names(job, "", "", "", {}) entityNames = story.read_unique_names(job, "", "", "", {})
self.assertEquals(type(entityNames), list) self.assertEquals(type(entityNames), list)
#entityNames = project.select_unique_names(job, "", "", "", {}) #entityNames = project.select_unique_names(job, "", "", "", {})
@ -45,7 +46,7 @@ class MyTestCase(unittest.TestCase):
if actfunction not in TEST_FUNCTIONS: if actfunction not in TEST_FUNCTIONS:
return return
job = test.testtools.getJob() job = test.testtools.getJob()
story = model.story.Story(job, "TESTPROJ") story = model.story.Story(job)
entityNames = [] entityNames = []
entityNames = story.get_entities(job, storage=model.entity.STORAGE_FILE) entityNames = story.get_entities(job, storage=model.entity.STORAGE_FILE)
self.assertEqual(type(entityNames), list) self.assertEqual(type(entityNames), list)
@ -60,7 +61,7 @@ class MyTestCase(unittest.TestCase):
if actfunction not in TEST_FUNCTIONS: if actfunction not in TEST_FUNCTIONS:
return return
job = test.testtools.getJob() job = test.testtools.getJob()
story = model.story.Story(job, "TESTPROJ") story = model.story.Story(job)
name = "S-1" name = "S-1"
actstory = story.read_entity(job, name) actstory = story.read_entity(job, name)
self.assertEqual(getattr(actstory, model.story.FIELD_NAME), name) self.assertEqual(getattr(actstory, model.story.FIELD_NAME), name)
@ -79,7 +80,7 @@ class MyTestCase(unittest.TestCase):
return return
job = test.testtools.getJob() job = test.testtools.getJob()
username = "hans_xyz" username = "hans_xyz"
story = model.story.Project() story = model.story.Story(job)
entityNames = story.get_unique_names(job, storage=model.entity.STORAGE_FILE) entityNames = story.get_unique_names(job, storage=model.entity.STORAGE_FILE)
self.assertNotIn(username, entityNames) self.assertNotIn(username, entityNames)
story.username = username story.username = username

13
test/test_20application.py

@ -13,8 +13,9 @@ import model.application
HOME_PATH = test.constants.HOME_PATH HOME_PATH = test.constants.HOME_PATH
PYTHON_CMD = "python" PYTHON_CMD = "python"
TEST_FUNCTIONS = ["test_10getEntityNames", "test_12getEntity", "test_11getEntities", "test_10getApplications"] TEST_FUNCTIONS = ["test_10getEntityNames", "test_12getEntity", "test_11getEntities" # , "test_10getApplications"
TEST_FUNCTIONS = ["test_11getEntities"] ]
#TEST_FUNCTIONS = ["test_11getEntities"]
PROGRAM_NAME = "clean_workspace" PROGRAM_NAME = "clean_workspace"
@ -29,7 +30,9 @@ class MyTestCase(unittest.TestCase):
if actfunction not in TEST_FUNCTIONS: if actfunction not in TEST_FUNCTIONS:
return return
job = test.testtools.getJob() job = test.testtools.getJob()
application = model.application.Application() assert isinstance(job, object)
print(str(model.application.Application))
application = model.application.Application(job)
entityNames = [] entityNames = []
entityNames = application.read_unique_names(job, "", "", "", {}) entityNames = application.read_unique_names(job, "", "", "", {})
self.assertEquals(type(entityNames), list) self.assertEquals(type(entityNames), list)
@ -45,7 +48,7 @@ class MyTestCase(unittest.TestCase):
if actfunction not in TEST_FUNCTIONS: if actfunction not in TEST_FUNCTIONS:
return return
job = test.testtools.getJob() job = test.testtools.getJob()
application = model.application.Application() application = model.application.Application(job) #.application.Application(job)
entityNames = application.get_entities(job, storage=model.entity.STORAGE_FILE) entityNames = application.get_entities(job, storage=model.entity.STORAGE_FILE)
self.assertEqual(type(entityNames), list) self.assertEqual(type(entityNames), list)
#entityNames = environment.get_entities(job, storage=model.entity.STORAGE_DB) #entityNames = environment.get_entities(job, storage=model.entity.STORAGE_DB)
@ -59,7 +62,7 @@ class MyTestCase(unittest.TestCase):
if actfunction not in TEST_FUNCTIONS: if actfunction not in TEST_FUNCTIONS:
return return
job = test.testtools.getJob() job = test.testtools.getJob()
application = model.application.Application() application = model.application.Application(job)
name = "TESTAPP" name = "TESTAPP"
actproject = application.read_entity(job, name) actproject = application.read_entity(job, name)
self.assertEqual(getattr(actproject, model.application.FIELD_NAME), name) self.assertEqual(getattr(actproject, model.application.FIELD_NAME), name)

2
test/test_90testserver.py

@ -11,7 +11,7 @@ import basic.constants as B
# the list of TEST_FUNCTIONS defines which function will be really tested. # the list of TEST_FUNCTIONS defines which function will be really tested.
# if you minimize the list you can check the specific test-function # if you minimize the list you can check the specific test-function
#TEST_FUNCTIONS = ["test_01createTestserver", "test_02getDBSchema", "test_11createDBTables", "test_11syncApplication"] TEST_FUNCTIONS = ["test_01createTestserver", "test_02getDBSchema", "test_11createDBTables", "test_11syncApplication"]
TEST_FUNCTIONS = ["test_02getDBSchema"] TEST_FUNCTIONS = ["test_02getDBSchema"]
# with this variable you can switch prints on and off # with this variable you can switch prints on and off
verbose = False verbose = False

17
tools/db_abstract.py

@ -473,9 +473,16 @@ class DbFcts():
return "idx_"+table+"_"+attr return "idx_"+table+"_"+attr
def getInsertFields(self, ddl): def getInsertFields(self, ddl):
header = [] outheader = []
for f in ddl[B.DATA_NODE_HEADER]: if B.DATA_NODE_KEYS in ddl:
if D.DDL_TYPE in ddl[f] and ddl[f][D.DDL_TYPE] == D.TYPE_PK: header = ddl[B.DATA_NODE_KEYS].keys()
keys = ddl[B.DATA_NODE_KEYS]
else:
header = ddl[B.DATA_NODE_HEADER]
keys = ddl
for f in header:
#for f in ddl[B.DATA_NODE_HEADER]:
if D.DDL_TYPE in keys[f] and keys[f][D.DDL_TYPE] == D.TYPE_PK:
continue continue
header.append(f) outheader.append(f)
return header return outheader

27
tools/dbmysql_tool.py

@ -4,6 +4,8 @@
# Author : Ulrich Carmesin # Author : Ulrich Carmesin
# Source : gitea.ucarmesin.de # Source : gitea.ucarmesin.de
# --------------------------------------------------------------------------------------------------------- # ---------------------------------------------------------------------------------------------------------
import traceback
import tools.config_tool import tools.config_tool
import tools.dbrel_tool import tools.dbrel_tool
import mysql.connector import mysql.connector
@ -32,8 +34,12 @@ class DbFcts(tools.dbrel_tool.DbFcts):
sql += ";" sql += ";"
self.comp.m.logInfo(sql) self.comp.m.logInfo(sql)
connector = self.getConnector() connector = self.getConnector()
try:
mycursor = connector.cursor() mycursor = connector.cursor()
mycursor.execute(sql) mycursor.execute(sql)
except Exception as e:
print("except "+str(e))
print("except " + traceback.format_exc())
myresult = mycursor.fetchall() myresult = mycursor.fetchall()
tdata[B.DATA_NODE_HEADER] = [] tdata[B.DATA_NODE_HEADER] = []
for f in self.comp.conf[B.DATA_NODE_DDL][table][B.DATA_NODE_HEADER]: for f in self.comp.conf[B.DATA_NODE_DDL][table][B.DATA_NODE_HEADER]:
@ -42,14 +48,17 @@ class DbFcts(tools.dbrel_tool.DbFcts):
for x in myresult: for x in myresult:
r = {} r = {}
i = 0 i = 0
for f in self.comp.conf[B.DATA_NODE_DDL][table][B.DATA_NODE_HEADER]: if B.DATA_NODE_KEYS in self.comp.conf[B.DATA_NODE_DDL][table]:
try: header = self.comp.conf[B.DATA_NODE_DDL][table][B.DATA_NODE_KEYS].keys()
if self.comp.conf[B.DATA_NODE_DDL][table][f][D.DDL_TYPE] in [D.TYPE_TIME, D.TYPE_DATE]: keys = self.comp.conf[B.DATA_NODE_DDL][table][B.DATA_NODE_KEYS]
else:
header = self.comp.conf[B.DATA_NODE_DDL][table][B.DATA_NODE_HEADER]
keys = self.comp.conf[B.DATA_NODE_DDL][table]
for f in header:
if (keys[f][D.DDL_TYPE] in [D.TYPE_TIME, D.TYPE_DATE]):
r[f] = tools.date_tool.getFormatdate(x[i], tools.date_tool.F_DIR) r[f] = tools.date_tool.getFormatdate(x[i], tools.date_tool.F_DIR)
else: else:
r[f] = str(x[i]) r[f] = str(x[i])
except:
pass
i += 1 i += 1
tdata[B.DATA_NODE_DATA].append(r) tdata[B.DATA_NODE_DATA].append(r)
self.comp.m.logInfo(str(tdata)) self.comp.m.logInfo(str(tdata))
@ -88,14 +97,18 @@ class DbFcts(tools.dbrel_tool.DbFcts):
sql += " VALUES " sql += " VALUES "
self.comp.m.logInfo(sql) self.comp.m.logInfo(sql)
values = [] values = []
if B.DATA_NODE_KEYS in self.comp.conf[B.DATA_NODE_DDL][table]:
keys = self.comp.conf[B.DATA_NODE_DDL][table][B.DATA_NODE_KEYS]
else:
keys = self.comp.conf[B.DATA_NODE_DDL][table]
for r in rows: for r in rows:
rowvalues = [] rowvalues = []
for h in insheader: for h in insheader:
if (h in r): if (h in r):
#rowvalues.append("\'"+self.getDbValue(self.comp.conf[B.DATA_NODE_DDL][table][h], r[h])+"\'") #rowvalues.append("\'"+self.getDbValue(self.comp.conf[B.DATA_NODE_DDL][table][h], r[h])+"\'")
rowvalues.append(self.getDbValue(self.comp.conf[B.DATA_NODE_DDL][table][h], r[h])) rowvalues.append(self.getDbValue(keys[h], r[h]))
else: else:
rowvalues.append(self.getDbValue(self.comp.conf[B.DATA_NODE_DDL][table][h], "")) rowvalues.append(self.getDbValue(keys[h], ""))
sql += "("+",".join(rowvalues)+"), " sql += "("+",".join(rowvalues)+"), "
values.append(tuple(rowvalues)) values.append(tuple(rowvalues))
sql = sql[0:-2] sql = sql[0:-2]

3
tools/job_tool.py

@ -177,6 +177,9 @@ def start_child_process(job, args):
elif args[B.PAR_PROGRAM] == "clean_workspace": elif args[B.PAR_PROGRAM] == "clean_workspace":
import clean_workspace import clean_workspace
clean_workspace.startPyJob(childJob) clean_workspace.startPyJob(childJob)
elif args[B.PAR_PROGRAM] == "unit_tester":
import unit_tester
unit_tester.startPyJob(childJob)
else: else:
raise Exception("unkown program {}".format(args[B.PAR_PROGRAM])) raise Exception("unkown program {}".format(args[B.PAR_PROGRAM]))
childJob.stopJob(1) childJob.stopJob(1)

3
unit_tester.py

@ -42,7 +42,8 @@ def create_test_suite(job):
testnum = t[len(testdir)+11:len(testdir)+13] testnum = t[len(testdir)+11:len(testdir)+13]
if not testnum.isnumeric(): if not testnum.isnumeric():
continue continue
if testnum not in ["01", "03", "07", "08", "10", "11", "20", "21"]: if testnum not in ["01", "03", "07", "08", "10", "11", "14", "15", "16", "17", "19",
"20", "21", "22", "26", "27", "28", "29" ]:
continue continue
if testdir == T.COMP_PATH: if testdir == T.COMP_PATH:
v = "components.test." + t[len(testdir) + 6:-3] v = "components.test." + t[len(testdir) + 6:-3]

Loading…
Cancel
Save