Browse Source

some model for check_spec

refactor
Ulrich 1 year ago
parent
commit
8152541577
  1. 2
      basic/connection.py
  2. 15
      basic/constants.py
  3. 10
      check_specification.py
  4. 20
      model/document.py
  5. 20
      model/release.py
  6. 43
      model/step.py
  7. 26
      model/story.py
  8. 4
      model/table.py
  9. 90
      model/testcase.py
  10. 21
      model/usecase.py
  11. 39
      test/test_28step.py
  12. 14
      test/testtools.py

2
basic/connection.py

@ -26,7 +26,7 @@ class Connection(model.entity.Entity):
self.job = job self.job = job
def get_schema(self): def get_schema(self, table=""):
dbtype = self.job.conf[B.TOPIC_NODE_DB][B.ATTR_TYPE] dbtype = self.job.conf[B.TOPIC_NODE_DB][B.ATTR_TYPE]
dbi = basic.toolHandling.getDbTool(self.job, None, dbtype) dbi = basic.toolHandling.getDbTool(self.job, None, dbtype)
print(str(dbi)) print(str(dbi))

15
basic/constants.py

@ -93,18 +93,19 @@ LIST_MAIN_PAR = [PAR_APP, PAR_ENV, PAR_VAR, PAR_REL, PAR_TCDIR, PAR_TSDIR]
# + substructure { : variable maybe scheme, table of a database-component # + substructure { : variable maybe scheme, table of a database-component
# + + _header [ : constant # + + _header [ : constant
# - fields : variable field-name # - fields : variable field-name
CONF_NODE_GENERAL = "_general"
""" This constant defines a subnode of a table for the column-names """ """ This constant defines a subnode of a table for the column-names """
DATA_NODE_HEADER = "_header" CONF_NODE_GENERAL = "_general"
""" it defines a subnode of a table for the column-names """ """ it defines a subnode of a table for the column-names """
DATA_NODE_FIELDS = "_fields" DATA_NODE_HEADER = "_header"
""" it defines a subnode of a table for the field-list, used for ddl """ """ it defines a subnode of a table for the field-list, used for ddl """
DATA_NODE_DATA = "_data" DATA_NODE_FIELDS = "_fields"
""" it defines a subnode of a table for the data as key-value-pair, keys from header """ """ it defines a subnode of a table for the data as key-value-pair, keys from header """
DATA_NODE_STEPS = "_step" DATA_NODE_DATA = "_data"
""" it defines the main node in the testdata for the steps to execute """ """ it defines the main node in the testdata for the steps to execute """
DATA_NODE_OPTION = "_option" DATA_NODE_STEPS = "_step"
""" it defines main node in the testdata for testcase specific parameters """ """ it defines main node in the testdata for testcase specific parameters """
DATA_NODE_OPTION = "_option"
DATA_NODE_HEAD = "_head"
DATA_NODE_ARGS = "_arguments" DATA_NODE_ARGS = "_arguments"
""" it defines arguments as internal key-value-pairs by delimted with :, used in steps """ """ it defines arguments as internal key-value-pairs by delimted with :, used in steps """
""" This constant defines the main node in the testdata for the steps to execute """ """ This constant defines the main node in the testdata for the steps to execute """
@ -214,7 +215,7 @@ ATTR_PATH_TDATA = "testdata"
""" This constant defines the folder in testing-filesystem with the testcase-specifications """ """ This constant defines the folder in testing-filesystem with the testcase-specifications """
ATTR_PATH_PATTN = "pattern" ATTR_PATH_PATTN = "pattern"
""" This constant defines the debug-folder in testing-filesystem """ """ This constant defines the debug-folder in testing-filesystem """
SUBJECT_APP = "application"
SUBJECT_APPS = "applications" # | x | | | | CompHandling SUBJECT_APPS = "applications" # | x | | | | CompHandling
ATTR_APPS_PROJECT = "project" # | | | | x | CompHanlding ATTR_APPS_PROJECT = "project" # | | | | x | CompHanlding
SUBJECT_ENTITY = "entity" SUBJECT_ENTITY = "entity"

10
check_specification.py

@ -14,6 +14,15 @@ def startPyJob(job):
try: try:
job.m.logDebug("--- start " + PROGRAM_NAME + " ------>>>>") job.m.logDebug("--- start " + PROGRAM_NAME + " ------>>>>")
job.m.setMsg("Job " + PROGRAM_NAME + " fertig") job.m.setMsg("Job " + PROGRAM_NAME + " fertig")
if hasattr(job.par, "testcase"):
testcase = getattr(job.par, "testcase")
print("Check testcase "+testcase)
elif hasattr(job.par, "testsuite"):
testsuite = getattr(job.par, "testsuite")
print("Check testsuite "+testsuite)
elif hasattr(job.par, "testplan"):
testplan = getattr(job.par, "testplan")
print("Check testplan "+testplan)
job.m.logDebug("<<<<<<<<----- " + PROGRAM_NAME + " ------") job.m.logDebug("<<<<<<<<----- " + PROGRAM_NAME + " ------")
except Exception as e: except Exception as e:
job.m.logDebug("+++++++++++++++++++++++++++++++++++++++++++++") job.m.logDebug("+++++++++++++++++++++++++++++++++++++++++++++")
@ -24,6 +33,7 @@ def startPyJob(job):
def checkHead(job): def checkHead(job):
pass pass
if __name__ == '__main__': if __name__ == '__main__':
x = basic.program.Job(PROGRAM_NAME) x = basic.program.Job(PROGRAM_NAME)
print ("x "+str(x)) print ("x "+str(x))

20
model/document.py

@ -0,0 +1,20 @@
# ---------------------------------------------------------------------------------------------------------
# Author : Ulrich Carmesin
# Source : gitea.ucarmesin.de
# ---------------------------------------------------------------------------------------------------------
import basic.constants as B
import model.entity
class Document(model.entity.Entity):
dcid = 0
document = ""
description = ""
project = ""
reference = ""
def __init__(self, job, project="", name=""):
"""
to be initialized by readSpec
:param job:
"""
self.job = job

20
model/release.py

@ -0,0 +1,20 @@
# ---------------------------------------------------------------------------------------------------------
# Author : Ulrich Carmesin
# Source : gitea.ucarmesin.de
# ---------------------------------------------------------------------------------------------------------
import basic.constants as B
import model.entity
class Release(model.entity.Entity):
rlid = 0
release = ""
project = ""
description = ""
reference = ""
def __init__(self, job, project="", name=""):
"""
to be initialized by readSpec
:param job:
"""
self.job = job

43
model/step.py

@ -25,8 +25,51 @@ STEP_ATTR_TOOL_NAME = "type"
""" name of the tool, values cli, dbi """ """ name of the tool, values cli, dbi """
STEP_ATTR_ARGS = "args" STEP_ATTR_ARGS = "args"
LIST_STEP_ATTR = [STEP_ATTR_NR, STEP_ATTR_GROUP, STEP_ATTR_COMP, STEP_ATTR_FCT,
STEP_ATTR_TOOL_TYPE, STEP_ATTR_TOOL_NAME, STEP_ATTR_ARGS]
FIELDS = {
STEP_ATTR_NR : "nr",
STEP_ATTR_GROUP : "group",
STEP_ATTR_COMP : "comp",
STEP_ATTR_FCT : "fct",
STEP_ATTR_TOOL_TYPE : "tool",
STEP_ATTR_TOOL_NAME : "toolname",
STEP_ATTR_ARGS : "args"
}
# step # step
# testsuite | testcase | component # testsuite | testcase | component
#---------------------------------- # ---------------------------------- # ---------------------------------- #---------------------------------- # ---------------------------------- # ----------------------------------
# start programs # start function # # start programs # start function #
class Step(model.entity.Entity):
nr = 0
name = ""
description = ""
project = ""
group = 0
comp = ""
fct = ""
tool = ""
toolname = ""
args = {}
def __init__(self, job, project="", name="", obj=None):
"""
to be initialized by readSpec
:param job:
"""
self.job = job
if len(project) > 1:
self.project = project
if len(name) > 1:
self.name = name
if obj is not None:
self.setEntity(LIST_STEP_ATTR, obj)
else:
self.getEntity(job, name)
def setEntity(self, keys, obj):
for k in keys:
if k in obj:
setattr(self, k, obj[k])

26
model/story.py

@ -0,0 +1,26 @@
# ---------------------------------------------------------------------------------------------------------
# Author : Ulrich Carmesin
# Source : gitea.ucarmesin.de
# ---------------------------------------------------------------------------------------------------------
import basic.constants as B
import model.entity
import tools.data_const as D
FIELDS = {
D.OPT_ATTR_STORYID : "story",
D.OPT_ATTR_STORY : "description"
}
class Story(model.entity.Entity):
stid = 0
story = ""
project = ""
description = ""
reference = ""
def __init__(self, job, project="", name=""):
"""
to be initialized by readSpec
:param job:
"""
self.job = job

4
model/table.py

@ -39,13 +39,11 @@ DEFAULTS = {
def select_tables(job, project="", application="", component=""): def select_tables(job, project="", application="", component=""):
outList = [] outList = []
appl = tools.config_tool.getConfig(job, P.KEY_BASIC, B.SUBJECT_APPS) appl = tools.config_tool.getConfig(job, P.KEY_BASIC, B.SUBJECT_APPS)
path = job.conf[B.SUBJECT_PATH][B.ATTR_PATH_COMPS]["catalog"]["tables"] path = os.path.join(job.conf[B.SUBJECT_PATH][B.ATTR_PATH_COMPS], "catalog", "tables")
for p in os.listdir(path): for p in os.listdir(path):
if p[-4:] not in [".csv", ".yml", ".xml", "json"]: if p[-4:] not in [".csv", ".yml", ".xml", "json"]:
continue continue
table = p[:-4] table = p[:-4]
if not os.path.isdir(os.path.join(path, table)):
continue
outList.append(table) outList.append(table)
return outList return outList

90
model/testcase.py

@ -15,7 +15,10 @@ import tools.job_tool
import tools.path_tool import tools.path_tool
import tools.path_const as P import tools.path_const as P
import model.entity import model.entity
import model.story
import model.document
import model.step
import model.table
class Testcase(model.entity.Entity): class Testcase(model.entity.Entity):
""" """
@ -28,20 +31,101 @@ class Testcase(model.entity.Entity):
steps -> comp.step steps -> comp.step
tables -> comp.table tables -> comp.table
""" """
tcid = ""
name = "" name = ""
description = "" description = ""
project = ""
application = "" application = ""
usecase = [] reference = ""
attributes = ""
story = [] story = []
docs = []
tables = {} tables = {}
steps = [] steps = []
def __init__(self, job): def __init__(self, job, project="", name=""):
""" """
to be initialized by readSpec to be initialized by readSpec
:param job: :param job:
""" """
self.job = job self.job = job
if len(project) > 1:
self.project = project
if len(name) > 1:
self.name = name
self.getEntity(job, name)
def read_entity(self, job, name):
"""
reads the entity from the file-system
:param job:
:param name:
:return:
"""
pathname = tools.config_tool.select_config_path(job, P.KEY_TESTCASE, name, "")
print(pathname)
(fname, ext) = os.path.splitext(pathname)
fi = basic.toolHandling.getFileTool(job, None, ext[1:])
tdata = fi.load_file(pathname, ttype=D.CSV_SPECTYPE_DATA)
stories = []
docs = []
attributes = {}
pass
if B.DATA_NODE_HEAD in tdata:
for h in D.LIST_HEAD_ATTR:
if h in tdata[B.DATA_NODE_HEAD]:
setattr(self, h, tdata[B.DATA_NODE_HEAD][h])
else:
job.m.logWarn("Keine Head-Daten in Testcase "+name)
if B.DATA_NODE_OPTION in tdata:
for o in tdata[B.DATA_NODE_OPTION]:
if o in [D.OPT_ATTR_UCID, D.OPT_ATTR_USECASE]:
pass
elif o in [D.OPT_ATTR_STORYID, D.OPT_ATTR_STORY]:
if len(stories) < 1:
story = model.story.Story(job)
stories.append(story)
else:
story = stories[0]
setattr(story, model.story.FIELDS[o], tdata[B.DATA_NODE_OPTION][o])
elif o in D.LIST_OPT_ATTR:
setattr(self, o, tdata[B.DATA_NODE_OPTION][o])
else:
attributes[o] = tdata[B.DATA_NODE_OPTION][o]
else:
job.m.logWarn("Keine Option-Daten in Testcase "+name)
if len(attributes) > 0:
self.attributes = attributes
if len(stories) > 0:
self.story = stories
pass
if B.DATA_NODE_STEPS in tdata:
for s in tdata[B.DATA_NODE_STEPS]:
step = model.step.Step(job, project=job.par.project, name=s)
pass
if B.DATA_NODE_TABLES in tdata:
for t in tdata[B.DATA_NODE_TABLES]:
table = model.table.Table(job, project=job.par.project, name=t)
pass
# for o in tdata[B.option
# header = tdata[B.DATA_NODE_STEPS][] LIST
# reference
#
# for t in tdata[B.tables
#raise Exception(B.EXCEPT_NOT_IMPLEMENT)
def select_entity(self, job, name):
"""
reads the entity from the database
it should get the same result like read_entity
:param job:
:param name:
:return:
"""
raise Exception(B.EXCEPT_NOT_IMPLEMENT)
def get_schema(self, tableName="", tableObject=None): def get_schema(self, tableName="", tableObject=None):
dbtype = self.job.conf[B.TOPIC_NODE_DB][B.ATTR_TYPE] dbtype = self.job.conf[B.TOPIC_NODE_DB][B.ATTR_TYPE]

21
model/usecase.py

@ -0,0 +1,21 @@
# ---------------------------------------------------------------------------------------------------------
# Author : Ulrich Carmesin
# Source : gitea.ucarmesin.de
# ---------------------------------------------------------------------------------------------------------
import basic.constants as B
import model.entity
class Usecase(model.entity.Entity):
ucid = 0
usecase = ""
project = ""
application = ""
description = ""
reference = ""
def __init__(self, job, project="", name=""):
"""
to be initialized by readSpec
:param job:
"""
self.job = job

39
test/test_28step.py

@ -0,0 +1,39 @@
import unittest
import os
import inspect
import shutil
import tools.path_tool
import basic.program
import test.testtools
import basic.constants as B
import test.constants as T
import tools.file_tool
import model.step
HOME_PATH = test.constants.HOME_PATH
PYTHON_CMD = "python"
TEST_FUNCTIONS = ["test_10getEnvironments"]
PROGRAM_NAME = "clean_workspace"
class MyTestCase(unittest.TestCase):
mymsg = "--------------------------------------------------------------"
def test_10getEnvironments(self):
global mymsg
global jobObject
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
if actfunction not in TEST_FUNCTIONS:
return
# simple job instantiate - without parameter and only simple messaging
job = test.testtools.getJob()
print(str(job.__dict__))
jobObject = job
projList = ["TESTPROJ"]
appList = []
if __name__ == '__main__':
unittest.main()

14
test/testtools.py

@ -35,12 +35,12 @@ conf = {
}, },
B.DATA_NODE_DDL: { B.DATA_NODE_DDL: {
"person": { "person": {
"id": { D.DDL_FNAME: "id", D.DDL_TYPE: "int", D.DDL_ACCEPTANCE: "ignore", D.DDL_KEY: "T:3" }, "id": {D.DDL_FIELD: "id", D.DDL_TYPE: "int", D.DDL_ACCEPTANCE: "ignore", D.DDL_KEY: "T:3"},
"name": { D.DDL_FNAME: "name", D.DDL_TYPE: "string", D.DDL_ACCEPTANCE: "must", D.DDL_KEY: "F:1" }, "name": {D.DDL_FIELD: "name", D.DDL_TYPE: "string", D.DDL_ACCEPTANCE: "must", D.DDL_KEY: "F:1"},
"birth": { D.DDL_FNAME: "id", D.DDL_TYPE: "date", D.DDL_ACCEPTANCE: "must", D.DDL_KEY: "" }, "birth": {D.DDL_FIELD: "id", D.DDL_TYPE: "date", D.DDL_ACCEPTANCE: "must", D.DDL_KEY: ""},
"year": { D.DDL_FNAME: "year", D.DDL_TYPE: "int", D.DDL_ACCEPTANCE: "must", D.DDL_KEY: "F:2" }, "year": {D.DDL_FIELD: "year", D.DDL_TYPE: "int", D.DDL_ACCEPTANCE: "must", D.DDL_KEY: "F:2"},
"position": { D.DDL_FNAME: "id", D.DDL_TYPE: "string", D.DDL_ACCEPTANCE: "must", D.DDL_KEY: "" }, "position": {D.DDL_FIELD: "id", D.DDL_TYPE: "string", D.DDL_ACCEPTANCE: "must", D.DDL_KEY: ""},
"hobby": { D.DDL_FNAME: "id", D.DDL_TYPE: "string", D.DDL_ACCEPTANCE: "must", D.DDL_KEY: "" }, "hobby": {D.DDL_FIELD: "id", D.DDL_TYPE: "string", D.DDL_ACCEPTANCE: "must", D.DDL_KEY: ""},
"_header": ["id", "name", "birth", "year", "position", "hobby"] "_header": ["id", "name", "birth", "year", "position", "hobby"]
} }
} }
@ -93,7 +93,7 @@ def getTestJob():
args = {} args = {}
args[B.PAR_PROGRAM] = "unit_tester" args[B.PAR_PROGRAM] = "unit_tester"
args[B.PAR_APP] = "service" args[B.PAR_APP] = "service"
args[B.PAR_PROJ] = "TESTAPP" args[B.PAR_PROJ] = "TESTPROJ"
args[B.PAR_ENV] = "Testserver" args[B.PAR_ENV] = "Testserver"
job = basic.program.Job(args[B.PAR_PROGRAM], "", args) job = basic.program.Job(args[B.PAR_PROGRAM], "", args)
return job return job

Loading…
Cancel
Save