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.

407 lines
15 KiB

# ---------------------------------------------------------------------------------------------------------
# Author : Ulrich Carmesin
# Source : gitea.ucarmesin.de
# ---------------------------------------------------------------------------------------------------------
print("is importing module.app")
import os
import basic.toolHandling
import basic.constants as B
import model.entity
import model.constants as M
import tools.data_const as D
import tools.path_const as P
import tools.config_tool
import tools.file_tool
import tools.git_tool
TABLE_NAMES = ["application", "ap_project", "ap_component"]
STORAGES = [ M.STORAGE_FILE, M.STORAGE_DB ]
""" used storage in priority sortage, so: if file then read_fcts / if db then select-fcts """
DEFAULT_SYNC = M.SYNC_FULL_GIT2DB
TABLE_NAME = B.SUBJECT_APP
""" system-name for this entity """
FIELD_ID = "apid"
FIELD_NAME = D.FIELD_NAME
FIELD_DESCRIPTION = B.SUBJECT_DESCRIPTION
FIELD_REFERENCE = B.SUBJECT_REFERENCE
FIELD_PROJECT = B.SUBJECT_PROJECT
LIST_FIELDS = [FIELD_ID, FIELD_NAME, FIELD_DESCRIPTION, FIELD_REFERENCE, FIELD_PROJECT]
""" list of object-attributes """
SUB_COMPS = B.SUBJECT_COMPS
SUB_APPS = B.SUBJECT_APPS
SUB_RELS = B.SUBJECT_RELS
SUB_USECASE = B.SUBJECT_USECASES
LIST_SUBTABLES = [SUB_APPS, SUB_COMPS, SUB_RELS, SUB_USECASE]
FILE_EXTENSION = D.DFILE_TYPE_YML
UNIQUE_FIELDS = [FIELD_NAME]
""" unique business field as human identifer """
IDENTIFYER_FIELDS = [FIELD_ID]
""" unique technical field as technical identifer """
print("has imported module.app")
def getProjects(job):
"""
get all project which are configured for the workspace
with all environments where the application of the project are installed
:param job:
:return:
"""
appl = tools.config_tool.getConfig(job, P.KEY_BASIC, B.SUBJECT_APPS)
return searchProjects(job, appl)
def searchProjects(job, appl):
"""
search all relevant projects from server-configuration
filtered by parameter --application , --project
:param job:
:return:
"""
projects = {}
2 years ago
if B.SUBJECT_PROJECTS in job.conf:
for k in job.conf[B.SUBJECT_PROJECTS]:
if k in B.LIST_SUBJECTS:
continue
if hasattr(job.par, B.PAR_PROJ) and k != getattr(job.par, B.PAR_PROJ):
continue
if hasattr(job.par, B.PAR_APP) \
and k not in appl[B.SUBJECT_APPS][getattr(job.par, B.PAR_APP)][B.SUBJECT_PROJECTS]:
continue
projects[k] = appl[B.SUBJECT_PROJECTS][k]
projects[k][B.SUBJECT_ENVIRONMENT] = []
else:
2 years ago
job.conf[B.SUBJECT_PROJECTS] = appl[B.SUBJECT_PROJECTS]
return projects
def getEnvironments(job, projectList):
"""
searches and gets environments in which the applications of the project are declared that these are installed
filtered by parameter --environment
:param job:
:return:
"""
projects = {}
path = job.conf[B.TOPIC_PATH][B.ATTR_PATH_ENV]
if os.path.exists(path):
raise Exception("Umgebungsverzeichnis existiert nicht "+path)
for envdir in os.listdir(path):
print ("-- "+envdir)
if not os.path.isdir(os.path.join(path, envdir)):
continue
if envdir[0:1] == "_":
continue
if hasattr(job.par, B.PAR_ENV) and envdir != getattr(job.par, B.PAR_ENV):
continue
for format in tools.config_tool.CONFIG_FORMAT:
pathname = os.path.join(job.conf.getPath(P.ATTR_PATH_ENV),
envdir, P.VAL_CONFIG, P.KEY_TOOL + "_conn." + format)
if os.path.exists(pathname):
break
if os.path.exists(pathname):
doc = tools.file_tool.readFileDict(job, pathname, job.m)
print(str(doc))
for proj in doc[B.SUBJECT_ENVIRONMENT][B.CONF_NODE_GENERAL][B.SUBJECT_PROJECTS]:
if proj in projectList:
projects[proj][B.SUBJECT_ENVIRONMENT].append(envdir)
return projects
def select_applications(job, projectList):
"""
get all project which are configured for the workspace
with all environments where the application of the project are installed
:param job:
:return:
"""
appl = tools.config_tool.getConfig(job, P.KEY_BASIC, B.SUBJECT_APPS)
return searchApplications(job, projectList, appl)
def searchApplications(job, projectList, appl):
appList = {}
for proj in projectList:
if hasattr(job, "par") and hasattr(job.par, B.PAR_PROJ) and proj != getattr(job.par, B.PAR_PROJ):
continue
for app in appl[B.SUBJECT_APPS]:
if B.SUBJECT_PROJECT in appl[B.SUBJECT_APPS][app] and proj != appl[B.SUBJECT_APPS][app][B.SUBJECT_PROJECT]:
continue
appList[app] = appl[B.SUBJECT_APPS][app]
return appList
def syncEnitity(job, elem):
return syncEnitities(job)
import model.entity
def syncEnitities(job):
"""
synchronize the configuration with the database
:param job:
:return:
"""
syncMethod = DEFAULT_SYNC
if syncMethod.count("-") < 2:
return
fileTime = model.entity.VAL_ZERO_TIME
dbTime = model.entity.VAL_ZERO_TIME
# get git-commit
if "git" in syncMethod:
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)
fileTime = gitresult[0]["date"]
print(str(gitresult))
if "db" in syncMethod:
2 years ago
if B.TOPIC_NODE_DB in job.conf:
dbi = basic.toolHandling.getDbTool(job, job.testserver, job.conf[B.TOPIC_NODE_DB][B.ATTR_TYPE])
else:
return "No DB in job-config"
data = dbi.selectRows(TABLE_NAMES[0], job)
print(str(data[B.DATA_NODE_DATA]))
if len(data[B.DATA_NODE_DATA]) > 0:
dbTime = data[B.DATA_NODE_DATA][0]["updtime"]
if fileTime == dbTime:
print("gleich")
elif fileTime < dbTime:
print("db vorne")
(appObjects, appDict) = selectEntities(job, dbi)
print(str(appDict))
applPath = tools.config_tool.select_config_path(job, P.KEY_BASIC, B.SUBJECT_APPS)
tools.file_tool.write_file_dict(job.m, job, applPath, appDict)
#
elif fileTime > dbTime:
print("git vorne")
applData = tools.config_tool.getConfig(job, P.KEY_BASIC, B.SUBJECT_APPS)
insertEntities(job, applData, dbTime, dbi)
def selectEntities(job, dbi):
appObjects = []
appDict = {}
appDict[B.SUBJECT_PROJECTS] = {}
appDict[B.SUBJECT_APPS] = {}
appData = dbi.selectRows(TABLE_NAMES[0], job)
projData = dbi.selectRows(TABLE_NAMES[1], job)
compData = dbi.selectRows(TABLE_NAMES[2], job)
for row in appData[B.DATA_NODE_DATA]:
ao = Application(job)
ao.setAppRow(row, "")
appDict[B.SUBJECT_APPS][ao.name] = {}
for f in job.testserver.conf[B.DATA_NODE_DDL][TABLE_NAMES[0]][B.DATA_NODE_HEADER]:
if f in model.entity.ENTITY_FIELDS:
continue
appDict[B.SUBJECT_APPS][ao.name][f] = getattr(ao, f)
apid = ao.apid
rows = [row for row in projData[B.DATA_NODE_DATA] if row["apid"] == apid]
ao.setProjRow(rows)
appDict[B.SUBJECT_APPS][ao.name][B.SUBJECT_PROJECTS] = []
for proj in getattr(ao, B.PAR_PROJ):
appDict[B.SUBJECT_APPS][ao.name][B.SUBJECT_PROJECTS].append(proj)
if proj in appDict[B.SUBJECT_PROJECTS]:
appDict[B.SUBJECT_PROJECTS][proj][B.SUBJECT_APPS].append(ao.name)
continue
appDict[B.SUBJECT_PROJECTS][proj] = {}
appDict[B.SUBJECT_PROJECTS][proj][B.SUBJECT_APPS] = []
appDict[B.SUBJECT_PROJECTS][proj][B.SUBJECT_APPS].append(ao.name)
aoproj = getattr(ao, "project")[proj]
for f in job.testserver.conf[B.DATA_NODE_DDL][TABLE_NAMES[1]][B.DATA_NODE_HEADER]:
if f in model.entity.ENTITY_FIELDS + ["approid", "apid"]:
continue
appDict[B.SUBJECT_PROJECTS][proj][f] = aoproj[f]
rows = [row for row in compData[B.DATA_NODE_DATA] if row["apid"] == apid]
ao.setCompRow(rows)
appDict[B.SUBJECT_APPS][ao.name][B.SUBJECT_COMPS] = []
for comp in getattr(ao, B.PAR_COMP):
appDict[B.SUBJECT_APPS][ao.name][B.SUBJECT_COMPS].append(comp)
appObjects.append(ao)
return appObjects, appDict
def insertEntities(job,applData, dbTime, dbi):
# insertRows
# get list of application
if dbTime != model.entity.VAL_ZERO_TIME:
for t in TABLE_NAMES:
dbi.deleteRows(job, t)
for app in applData[B.SUBJECT_APPS]:
ao = Application(job)
ao.read_entity(job, app)
ao.insertEntity(dbi)
class Application(model.entity.Entity):
table = "application"
name = ""
description = ""
reference = ""
components = {}
project = {}
1 year ago
def __int__(self, job, project=""):
self.job = job
def read_unique_names(self, job, project, application, gran, args):
"""
reads the entity-names from file-storage
:param job:
:param opt. project: select-criteria if used and defined
:param opt. application: select-criteria if used and defined
:param opt. gran: granularity values testcase / testsuite / testplan
:param opt. args additional args
:return: list of entity-names
"""
config = self.getConfig(job, P.KEY_BASIC, B.SUBJECT_APPS, tools.config_tool.get_plain_filename(job, ""))
outList = list(config[B.SUBJECT_APPS].keys())
return outList
def read_entity(self, job, name):
"""
reads the entity from the file-system
:param job:
:param name:
:return:
"""
config = self.getConfig(job, P.KEY_BASIC, B.SUBJECT_APPS, tools.config_tool.get_plain_filename(job, name))
return self.setAttributes(config, name, LIST_FIELDS, LIST_SUBTABLES)
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):
2 years ago
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):
2 years ago
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
def get_schema(self, tableName="", tableObject=None):
"""
ersetzt durch testserver.createDB
:return:
"""
return ""