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]:
continue
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]:
args[x] = config[rootname][key][o][x]
# args[k] = config[rootname][key][o]

31
model/factory.py

@ -2,9 +2,34 @@ import model.entity
import basic.constants as B
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={}):
if name == "" and len(args) == 0 and Magazin.hasEntity(entityname):
return Magazin.getEntity(entityname)
if entityname in [B.SUBJECT_STEPS, B.SUBJECT_STEP]:
entity = getStep(job, name, args)
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)
else:
return None
#entity.setAttributes(job, args, name, entity.getFieldList(), entity.getNodeList(), entity.getSubtableList())
#testserver = basic.Testserver.getInstance(job)
if name == "" and len(args) == 0 and not Magazin.hasEntity(entityname):
return Magazin.setEntity(entityname, entity)
return entity
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]
elif k in B.LIST_DATA_NODE and tools.data_tool.getPluralKeyword(k) in subtables:
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:
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)
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[B.NODE_ATTRIBUTES] = attributes
for k in xsubtable:

45
test/test_14entity.py

@ -12,6 +12,7 @@ import test.constants as T
import model.testcase
import model.entity
import tools.data_tool
import tools.data_const as D
HOME_PATH = test.constants.HOME_PATH
PYTHON_CMD = "python"
@ -33,30 +34,26 @@ class MyTestCase(unittest.TestCase):
job = test.testtools.getJob()
tcname = "TC0001"
tcproject = "TESTPROJ"
testcase = model.testcase.Testcase(job, tcproject)
testcase = model.testcase.Testcase(job, tcname)
# eigene Attribute vollstaendig
testcase = model.testcase.Testcase(job, tcproject)
testcase = model.testcase.Testcase(job, tcname)
args = {}
args[tcname] = {}
for k in model.testcase.LIST_FIELDS:
for k in model.testcase.Testcase.LIST_FIELDS:
args[tcname][k] = "ATTR_" + k
testcase = testcase.setAttributes(job, args, tcname,
model.testcase.LIST_FIELDS,
model.testcase.LIST_NODES,
model.testcase.LIST_SUBTABLES)
for k in model.testcase.LIST_FIELDS:
if k == model.testcase.FIELD_NAME:
model.testcase.Testcase.LIST_FIELDS,
model.testcase.Testcase.LIST_NODES,
model.testcase.Testcase.LIST_SUBTABLES)
for k in model.testcase.Testcase.LIST_FIELDS:
if k == D.FIELD_NAME:
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:
self.assertEqual(hasattr(testcase, k), False)
self.assertEqual(hasattr(testcase, tools.data_tool.getPluralKeyword(B.DATA_NODE_TOPICS)), False)
# andere Attribute vollstaendig
testcase = model.testcase.Testcase(job, tcproject)
testcase = model.testcase.Testcase(job, tcname)
args = {}
args[tcname] = {}
attr = {}
@ -70,19 +67,15 @@ class MyTestCase(unittest.TestCase):
topics[k]["type"] = "x-type"
args[tcname][tools.data_tool.getPluralKeyword(B.DATA_NODE_TOPICS)] = topics
testcase = testcase.setAttributes(job, args, tcname,
model.testcase.LIST_FIELDS,
model.testcase.LIST_NODES,
model.testcase.LIST_SUBTABLES)
for k in model.testcase.LIST_FIELDS:
if k == model.testcase.FIELD_NAME:
model.testcase.Testcase.LIST_FIELDS,
model.testcase.Testcase.LIST_NODES,
model.testcase.Testcase.LIST_SUBTABLES)
for k in model.testcase.Testcase.LIST_FIELDS:
if k == D.FIELD_NAME:
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:
self.assertEqual(hasattr(testcase, k), False)
for k in model.testcase.LIST_NODES:
for k in model.testcase.Testcase.LIST_NODES:
print(k)
self.assertEqual(hasattr(testcase, k), 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:
return
job = test.testtools.getJob()
testcase = model.testcase.Testcase(job, "TESTPROJ")
testcase = model.testcase.Testcase(job)
entityNames = []
entityNames = testcase.get_entities(job, storage=model.entity.STORAGE_FILE)
self.assertEqual(type(entityNames), list)
@ -113,10 +106,10 @@ class MyTestCase(unittest.TestCase):
if actfunction not in TEST_FUNCTIONS:
return
job = test.testtools.getJob()
testcase = model.testcase.Testcase(job, "TESTPROJ")
testcase = model.testcase.Testcase(job)
name = "TC0001"
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")
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
if hasattr(job, "m"): msg = job.m
pathname = select_config_path(job, modul, name, subname)
print("+++ " + pathname)
print("+++ " + str(pathname))
confs = {}
if pathname is None:
return None

20
tools/filecsv_fcts.py

@ -128,13 +128,13 @@ class FileFcts(tools.file_abstract.FileFcts):
# subtable-Block
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)
subtable = setSubTable(job, subtable, a[0], fields)
subtable = setSubTable(job, subtable, a[0], fields, ttype)
tdata[subtable["actTable"]] = subtable[subtable["actTable"]]
status = subtable["actTable"]
# attribute-Block
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)
tableAttr = setTableAttribute(job, tableAttr, a[0], fields)
tableAttr = setTableAttribute(job, tableAttr, a[0], fields, ttype)
if ttype == "" and D.DATA_ATTR_TYPE in tableAttr:
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])
return out
def setSubTable(job, subtable, key, val):
def setSubTable(job, subtable, key, val, ttype):
"""
:param job:
@ -370,11 +370,21 @@ def setSubTable(job, subtable, key, val):
# descriptiom => attribute of actual subtable
key = key.lower() # tools.data_tool.getPluralKeyword(key)
subkey = ""
multi = True
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 "actTable" in subtable and subtable["actTable"]+"-" in key:
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:
newSubtable = True
subtable[keyword] = {}
@ -420,7 +430,7 @@ def setStepAttribute(job, stepAttr, key, val):
stepAttr[key] = step
return stepAttr
def setTableAttribute(job, tableAttr, key, val):
def setTableAttribute(job, tableAttr, key, val, ttype):
key = key.lower()
if key in D.LIST_DATA_ATTR:
if key in D.LIST_ATTR_MULTI:

Loading…
Cancel
Save