From 815254157746a3f838e7e6d88bcadfe7e9c186f3 Mon Sep 17 00:00:00 2001 From: Ulrich Date: Thu, 4 May 2023 19:14:43 +0200 Subject: [PATCH] some model for check_spec --- basic/connection.py | 2 +- basic/constants.py | 15 +++---- check_specification.py | 10 +++++ model/document.py | 20 ++++++++++ model/release.py | 20 ++++++++++ model/step.py | 43 ++++++++++++++++++++ model/story.py | 26 ++++++++++++ model/table.py | 4 +- model/testcase.py | 90 ++++++++++++++++++++++++++++++++++++++++-- model/usecase.py | 21 ++++++++++ test/test_28step.py | 39 ++++++++++++++++++ test/testtools.py | 14 +++---- 12 files changed, 283 insertions(+), 21 deletions(-) create mode 100644 model/document.py create mode 100644 model/release.py create mode 100644 model/story.py create mode 100644 model/usecase.py diff --git a/basic/connection.py b/basic/connection.py index fd8f806..9086b80 100644 --- a/basic/connection.py +++ b/basic/connection.py @@ -26,7 +26,7 @@ class Connection(model.entity.Entity): self.job = job - def get_schema(self): + def get_schema(self, table=""): dbtype = self.job.conf[B.TOPIC_NODE_DB][B.ATTR_TYPE] dbi = basic.toolHandling.getDbTool(self.job, None, dbtype) print(str(dbi)) diff --git a/basic/constants.py b/basic/constants.py index 64877ea..c4a3a27 100644 --- a/basic/constants.py +++ b/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 # + + _header [ : constant # - fields : variable field-name -CONF_NODE_GENERAL = "_general" """ 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 """ -DATA_NODE_FIELDS = "_fields" +DATA_NODE_HEADER = "_header" """ 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 """ -DATA_NODE_STEPS = "_step" +DATA_NODE_DATA = "_data" """ 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 """ +DATA_NODE_OPTION = "_option" +DATA_NODE_HEAD = "_head" DATA_NODE_ARGS = "_arguments" """ 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 """ @@ -214,7 +215,7 @@ ATTR_PATH_TDATA = "testdata" """ This constant defines the folder in testing-filesystem with the testcase-specifications """ ATTR_PATH_PATTN = "pattern" """ This constant defines the debug-folder in testing-filesystem """ - +SUBJECT_APP = "application" SUBJECT_APPS = "applications" # | x | | | | CompHandling ATTR_APPS_PROJECT = "project" # | | | | x | CompHanlding SUBJECT_ENTITY = "entity" diff --git a/check_specification.py b/check_specification.py index fb4cfcc..bb380cf 100644 --- a/check_specification.py +++ b/check_specification.py @@ -14,6 +14,15 @@ def startPyJob(job): try: job.m.logDebug("--- start " + PROGRAM_NAME + " ------>>>>") 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 + " ------") except Exception as e: job.m.logDebug("+++++++++++++++++++++++++++++++++++++++++++++") @@ -24,6 +33,7 @@ def startPyJob(job): def checkHead(job): pass + if __name__ == '__main__': x = basic.program.Job(PROGRAM_NAME) print ("x "+str(x)) diff --git a/model/document.py b/model/document.py new file mode 100644 index 0000000..cc564b0 --- /dev/null +++ b/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 diff --git a/model/release.py b/model/release.py new file mode 100644 index 0000000..8e44645 --- /dev/null +++ b/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 diff --git a/model/step.py b/model/step.py index ee7098e..e85eee3 100644 --- a/model/step.py +++ b/model/step.py @@ -25,8 +25,51 @@ STEP_ATTR_TOOL_NAME = "type" """ name of the tool, values cli, dbi """ 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 # testsuite | testcase | component #---------------------------------- # ---------------------------------- # ---------------------------------- # 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]) + diff --git a/model/story.py b/model/story.py new file mode 100644 index 0000000..5a817ae --- /dev/null +++ b/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 diff --git a/model/table.py b/model/table.py index 217d6d8..ed0b5a8 100644 --- a/model/table.py +++ b/model/table.py @@ -39,13 +39,11 @@ DEFAULTS = { def select_tables(job, project="", application="", component=""): outList = [] 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): if p[-4:] not in [".csv", ".yml", ".xml", "json"]: continue table = p[:-4] - if not os.path.isdir(os.path.join(path, table)): - continue outList.append(table) return outList diff --git a/model/testcase.py b/model/testcase.py index f9144bd..49f6eef 100644 --- a/model/testcase.py +++ b/model/testcase.py @@ -15,7 +15,10 @@ import tools.job_tool import tools.path_tool import tools.path_const as P import model.entity - +import model.story +import model.document +import model.step +import model.table class Testcase(model.entity.Entity): """ @@ -28,20 +31,101 @@ class Testcase(model.entity.Entity): steps -> comp.step tables -> comp.table """ + tcid = "" name = "" description = "" + project = "" application = "" - usecase = [] + reference = "" + attributes = "" story = [] + docs = [] tables = {} steps = [] - def __init__(self, job): + def __init__(self, job, project="", name=""): """ to be initialized by readSpec :param 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): dbtype = self.job.conf[B.TOPIC_NODE_DB][B.ATTR_TYPE] diff --git a/model/usecase.py b/model/usecase.py new file mode 100644 index 0000000..00b8108 --- /dev/null +++ b/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 diff --git a/test/test_28step.py b/test/test_28step.py index e69de29..1f28c19 100644 --- a/test/test_28step.py +++ b/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() diff --git a/test/testtools.py b/test/testtools.py index 8b17a09..81ac65c 100644 --- a/test/testtools.py +++ b/test/testtools.py @@ -35,12 +35,12 @@ conf = { }, B.DATA_NODE_DDL: { "person": { - "id": { D.DDL_FNAME: "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" }, - "birth": { D.DDL_FNAME: "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" }, - "position": { D.DDL_FNAME: "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: "" }, + "id": {D.DDL_FIELD: "id", D.DDL_TYPE: "int", D.DDL_ACCEPTANCE: "ignore", D.DDL_KEY: "T:3"}, + "name": {D.DDL_FIELD: "name", D.DDL_TYPE: "string", D.DDL_ACCEPTANCE: "must", D.DDL_KEY: "F:1"}, + "birth": {D.DDL_FIELD: "id", D.DDL_TYPE: "date", D.DDL_ACCEPTANCE: "must", D.DDL_KEY: ""}, + "year": {D.DDL_FIELD: "year", D.DDL_TYPE: "int", D.DDL_ACCEPTANCE: "must", D.DDL_KEY: "F:2"}, + "position": {D.DDL_FIELD: "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"] } } @@ -93,7 +93,7 @@ def getTestJob(): args = {} args[B.PAR_PROGRAM] = "unit_tester" args[B.PAR_APP] = "service" - args[B.PAR_PROJ] = "TESTAPP" + args[B.PAR_PROJ] = "TESTPROJ" args[B.PAR_ENV] = "Testserver" job = basic.program.Job(args[B.PAR_PROGRAM], "", args) return job