Browse Source

refactoring: basic-model - with objects + create once

refactor
Ulrich 1 year ago
parent
commit
a6dda95034
  1. 4
      model/entity.py
  2. 31
      model/factory.py
  3. 13
      model/testcase.py
  4. 45
      test/test_14entity.py
  5. 2
      tools/config_tool.py
  6. 20
      tools/filecsv_fcts.py

4
model/entity.py

@ -403,6 +403,10 @@ class Entity:
if o in [B.DATA_NODE_DATA, B.DATA_NODE_HEADER, B.DATA_NODE_FIELDS, B.DATA_NODE_ROW, B.DATA_NODE_PATH]: if o in [B.DATA_NODE_DATA, B.DATA_NODE_HEADER, B.DATA_NODE_FIELDS, B.DATA_NODE_ROW, B.DATA_NODE_PATH]:
continue continue
args = {} args = {}
print("### " + k + " " + o + " " + str(config[rootname][key][o]))
if not isinstance(config[rootname][key][o], dict):
objects[k] = o
continue
for x in config[rootname][key][o]: for x in config[rootname][key][o]:
args[x] = config[rootname][key][o][x] args[x] = config[rootname][key][o][x]
# args[k] = config[rootname][key][o] # args[k] = config[rootname][key][o]

31
model/factory.py

@ -2,9 +2,34 @@ import model.entity
import basic.constants as B import basic.constants as B
import basic.Testserver import basic.Testserver
class Magazin():
__instance = None
__entities = {}
@staticmethod
def getInstance():
if Magazin.__instance == None:
return Magazin()
@staticmethod
def setEntity(name, object):
if name not in Magazin.__entities:
Magazin.__entities[name] = object
return Magazin.__entities[name]
@staticmethod
def getEntity(name):
if name in Magazin.__entities:
return Magazin.__entities[name]
@staticmethod
def hasEntity(name):
if name in Magazin.__entities:
return True
return False
def get_entity_object(job, entityname: str, name: str="", args: dict={}): def get_entity_object(job, entityname: str, name: str="", args: dict={}):
if name == "" and len(args) == 0 and Magazin.hasEntity(entityname):
return Magazin.getEntity(entityname)
if entityname in [B.SUBJECT_STEPS, B.SUBJECT_STEP]: if entityname in [B.SUBJECT_STEPS, B.SUBJECT_STEP]:
entity = getStep(job, name, args) entity = getStep(job, name, args)
elif entityname in [B.SUBJECT_STORIES, B.SUBJECT_STORY, "storys"]: elif entityname in [B.SUBJECT_STORIES, B.SUBJECT_STORY, "storys"]:
@ -37,8 +62,8 @@ def get_entity_object(job, entityname: str, name: str="", args: dict={}):
entity = getEnvironment(job, name, args) entity = getEnvironment(job, name, args)
else: else:
return None return None
#entity.setAttributes(job, args, name, entity.getFieldList(), entity.getNodeList(), entity.getSubtableList()) if name == "" and len(args) == 0 and not Magazin.hasEntity(entityname):
#testserver = basic.Testserver.getInstance(job) return Magazin.setEntity(entityname, entity)
return entity return entity
def getRelease(job=None, name: str="", args: dict={}): def getRelease(job=None, name: str="", args: dict={}):

13
model/testcase.py

@ -148,11 +148,20 @@ class Testcase(model.entity.Entity):
outdata[k][l] = data[k][l] outdata[k][l] = data[k][l]
elif k in B.LIST_DATA_NODE and tools.data_tool.getPluralKeyword(k) in subtables: elif k in B.LIST_DATA_NODE and tools.data_tool.getPluralKeyword(k) in subtables:
outdata[tools.data_tool.getPluralKeyword(k)] = data[k] outdata[tools.data_tool.getPluralKeyword(k)] = data[k]
elif k[:1] == "_":
a = k.split("-")
val = data[k]
if tools.data_tool.getPluralKeyword(a[0]) in B.LIST_SUBJECTS \
and tools.data_tool.getSingularKeyword(a[0]) in fields:
outdata[tools.data_tool.getSingularKeyword(a[0])] = tools.data_tool.splitDelimitedValues(val)[0]
elif tools.data_tool.getPluralKeyword(a[0]) in B.LIST_SUBJECTS \
and tools.data_tool.getPluralKeyword(a[0]) in subtables:
xsubtable = Testcase.setSubtable(job, xsubtable, l, val, outdata)
else: else:
outdata[k] = data[k] outdata[k] = data[k]
if len(outdata[B.DATA_NODE_OPTION]) == 0: if B.DATA_NODE_OPTION in outdata and len(outdata[B.DATA_NODE_OPTION]) == 0:
outdata.pop(B.DATA_NODE_OPTION) outdata.pop(B.DATA_NODE_OPTION)
if len(outdata[B.DATA_NODE_HEAD]) == 0: if B.DATA_NODE_HEAD in outdata and len(outdata[B.DATA_NODE_HEAD]) == 0:
outdata.pop(B.DATA_NODE_HEAD) outdata.pop(B.DATA_NODE_HEAD)
outdata[B.NODE_ATTRIBUTES] = attributes outdata[B.NODE_ATTRIBUTES] = attributes
for k in xsubtable: for k in xsubtable:

45
test/test_14entity.py

@ -12,6 +12,7 @@ import test.constants as T
import model.testcase import model.testcase
import model.entity import model.entity
import tools.data_tool import tools.data_tool
import tools.data_const as D
HOME_PATH = test.constants.HOME_PATH HOME_PATH = test.constants.HOME_PATH
PYTHON_CMD = "python" PYTHON_CMD = "python"
@ -33,30 +34,26 @@ class MyTestCase(unittest.TestCase):
job = test.testtools.getJob() job = test.testtools.getJob()
tcname = "TC0001" tcname = "TC0001"
tcproject = "TESTPROJ" tcproject = "TESTPROJ"
testcase = model.testcase.Testcase(job, tcproject) testcase = model.testcase.Testcase(job, tcname)
# eigene Attribute vollstaendig # eigene Attribute vollstaendig
testcase = model.testcase.Testcase(job, tcproject) testcase = model.testcase.Testcase(job, tcname)
args = {} args = {}
args[tcname] = {} args[tcname] = {}
for k in model.testcase.LIST_FIELDS: for k in model.testcase.Testcase.LIST_FIELDS:
args[tcname][k] = "ATTR_" + k args[tcname][k] = "ATTR_" + k
testcase = testcase.setAttributes(job, args, tcname, testcase = testcase.setAttributes(job, args, tcname,
model.testcase.LIST_FIELDS, model.testcase.Testcase.LIST_FIELDS,
model.testcase.LIST_NODES, model.testcase.Testcase.LIST_NODES,
model.testcase.LIST_SUBTABLES) model.testcase.Testcase.LIST_SUBTABLES)
for k in model.testcase.LIST_FIELDS: for k in model.testcase.Testcase.LIST_FIELDS:
if k == model.testcase.FIELD_NAME: if k == D.FIELD_NAME:
self.assertEqual(tcname, getattr(testcase, k)) self.assertEqual(tcname, getattr(testcase, k))
elif k == model.testcase.FIELD_PROJECT:
self.assertEqual(tcproject, getattr(testcase, k))
else:
self.assertEqual(getattr(testcase, k), "ATTR_" + k)
for k in LIST_XARGS: for k in LIST_XARGS:
self.assertEqual(hasattr(testcase, k), False) self.assertEqual(hasattr(testcase, k), False)
self.assertEqual(hasattr(testcase, tools.data_tool.getPluralKeyword(B.DATA_NODE_TOPICS)), False) self.assertEqual(hasattr(testcase, tools.data_tool.getPluralKeyword(B.DATA_NODE_TOPICS)), False)
# andere Attribute vollstaendig # andere Attribute vollstaendig
testcase = model.testcase.Testcase(job, tcproject) testcase = model.testcase.Testcase(job, tcname)
args = {} args = {}
args[tcname] = {} args[tcname] = {}
attr = {} attr = {}
@ -70,19 +67,15 @@ class MyTestCase(unittest.TestCase):
topics[k]["type"] = "x-type" topics[k]["type"] = "x-type"
args[tcname][tools.data_tool.getPluralKeyword(B.DATA_NODE_TOPICS)] = topics args[tcname][tools.data_tool.getPluralKeyword(B.DATA_NODE_TOPICS)] = topics
testcase = testcase.setAttributes(job, args, tcname, testcase = testcase.setAttributes(job, args, tcname,
model.testcase.LIST_FIELDS, model.testcase.Testcase.LIST_FIELDS,
model.testcase.LIST_NODES, model.testcase.Testcase.LIST_NODES,
model.testcase.LIST_SUBTABLES) model.testcase.Testcase.LIST_SUBTABLES)
for k in model.testcase.LIST_FIELDS: for k in model.testcase.Testcase.LIST_FIELDS:
if k == model.testcase.FIELD_NAME: if k == D.FIELD_NAME:
self.assertEqual(tcname, getattr(testcase, k)) self.assertEqual(tcname, getattr(testcase, k))
elif k == model.testcase.FIELD_PROJECT:
self.assertEqual(tcproject, getattr(testcase, k))
else:
self.assertEqual("", getattr(testcase, k, ""))
for k in LIST_XARGS: for k in LIST_XARGS:
self.assertEqual(hasattr(testcase, k), False) self.assertEqual(hasattr(testcase, k), False)
for k in model.testcase.LIST_NODES: for k in model.testcase.Testcase.LIST_NODES:
print(k) print(k)
self.assertEqual(hasattr(testcase, k), True) self.assertEqual(hasattr(testcase, k), True)
self.assertEqual(hasattr(testcase, tools.data_tool.getPluralKeyword(B.DATA_NODE_TOPICS)), True) self.assertEqual(hasattr(testcase, tools.data_tool.getPluralKeyword(B.DATA_NODE_TOPICS)), True)
@ -98,7 +91,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()
testcase = model.testcase.Testcase(job, "TESTPROJ") testcase = model.testcase.Testcase(job)
entityNames = [] entityNames = []
entityNames = testcase.get_entities(job, storage=model.entity.STORAGE_FILE) entityNames = testcase.get_entities(job, storage=model.entity.STORAGE_FILE)
self.assertEqual(type(entityNames), list) self.assertEqual(type(entityNames), list)
@ -113,10 +106,10 @@ 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()
testcase = model.testcase.Testcase(job, "TESTPROJ") testcase = model.testcase.Testcase(job)
name = "TC0001" name = "TC0001"
acttestcase = testcase.read_entity(job, name) acttestcase = testcase.read_entity(job, name)
self.assertEqual(getattr(acttestcase, model.testcase.FIELD_NAME), name) self.assertEqual(getattr(acttestcase, D.FIELD_NAME), name)
self.assertRaises(Exception, testcase.read_entity, job, "xyzxyz") self.assertRaises(Exception, testcase.read_entity, job, "xyzxyz")
if __name__ == '__main__': if __name__ == '__main__':

2
tools/config_tool.py

@ -335,7 +335,7 @@ def getConfig(job, modul: str, name: str, subname: str = "", ttype: str = D.CSV_
msg = None msg = None
if hasattr(job, "m"): msg = job.m if hasattr(job, "m"): msg = job.m
pathname = select_config_path(job, modul, name, subname) pathname = select_config_path(job, modul, name, subname)
print("+++ " + pathname) print("+++ " + str(pathname))
confs = {} confs = {}
if pathname is None: if pathname is None:
return None return None

20
tools/filecsv_fcts.py

@ -128,13 +128,13 @@ class FileFcts(tools.file_abstract.FileFcts):
# subtable-Block # subtable-Block
if self.isBlock(msg, job, fields[0], D.CSV_BLOCK_SUBTABLES, status): # a[0].lower() in D.LIST_DATA_ATTR: if self.isBlock(msg, job, fields[0], D.CSV_BLOCK_SUBTABLES, status): # a[0].lower() in D.LIST_DATA_ATTR:
if verify: print("block "+D.CSV_BLOCK_SUBTABLES+" :: "+l) if verify: print("block "+D.CSV_BLOCK_SUBTABLES+" :: "+l)
subtable = setSubTable(job, subtable, a[0], fields) subtable = setSubTable(job, subtable, a[0], fields, ttype)
tdata[subtable["actTable"]] = subtable[subtable["actTable"]] tdata[subtable["actTable"]] = subtable[subtable["actTable"]]
status = subtable["actTable"] status = subtable["actTable"]
# attribute-Block # attribute-Block
elif self.isBlock(msg, job, fields[0], D.CSV_BLOCK_ATTR, status): # a[0].lower() in D.LIST_DATA_ATTR: elif self.isBlock(msg, job, fields[0], D.CSV_BLOCK_ATTR, status): # a[0].lower() in D.LIST_DATA_ATTR:
if verify: print("block "+D.CSV_BLOCK_ATTR+" :: "+l) if verify: print("block "+D.CSV_BLOCK_ATTR+" :: "+l)
tableAttr = setTableAttribute(job, tableAttr, a[0], fields) tableAttr = setTableAttribute(job, tableAttr, a[0], fields, ttype)
if ttype == "" and D.DATA_ATTR_TYPE in tableAttr: if ttype == "" and D.DATA_ATTR_TYPE in tableAttr:
ttype = tableAttr[D.DATA_ATTR_TYPE] ttype = tableAttr[D.DATA_ATTR_TYPE]
elif (D.DATA_ATTR_TYPE in tableAttr and ttype != tableAttr[D.DATA_ATTR_TYPE] elif (D.DATA_ATTR_TYPE in tableAttr and ttype != tableAttr[D.DATA_ATTR_TYPE]
@ -355,7 +355,7 @@ def splitFields(line, delimiter, job):
out.append(fields[i]) out.append(fields[i])
return out return out
def setSubTable(job, subtable, key, val): def setSubTable(job, subtable, key, val, ttype):
""" """
:param job: :param job:
@ -370,11 +370,21 @@ def setSubTable(job, subtable, key, val):
# descriptiom => attribute of actual subtable # descriptiom => attribute of actual subtable
key = key.lower() # tools.data_tool.getPluralKeyword(key) key = key.lower() # tools.data_tool.getPluralKeyword(key)
subkey = "" subkey = ""
multi = True
newSubtable = False newSubtable = False
if tools.data_tool.getPluralKeyword(ttype) in B.LIST_SUBJECTS:
entity = model.factory.get_entity_object(job, ttype)
else:
entity = None
if verify: print("setSubtable "+key+", "+str(val)) if verify: print("setSubtable "+key+", "+str(val))
if "actTable" in subtable and subtable["actTable"]+"-" in key: if "actTable" in subtable and subtable["actTable"]+"-" in key:
subkey = key[key.find("-")+1:] subkey = key[key.find("-")+1:]
keyword = tools.data_tool.getPluralKeyword(key) if entity is not None and tools.data_tool.getSingularKeyword(key) in entity.LIST_FIELDS:
keyword = tools.data_tool.getSingularKeyword(key)
multi = False
else:
keyword = tools.data_tool.getPluralKeyword(key)
if subkey == "" and keyword not in subtable: if subkey == "" and keyword not in subtable:
newSubtable = True newSubtable = True
subtable[keyword] = {} subtable[keyword] = {}
@ -420,7 +430,7 @@ def setStepAttribute(job, stepAttr, key, val):
stepAttr[key] = step stepAttr[key] = step
return stepAttr return stepAttr
def setTableAttribute(job, tableAttr, key, val): def setTableAttribute(job, tableAttr, key, val, ttype):
key = key.lower() key = key.lower()
if key in D.LIST_DATA_ATTR: if key in D.LIST_DATA_ATTR:
if key in D.LIST_ATTR_MULTI: if key in D.LIST_ATTR_MULTI:

Loading…
Cancel
Save