Browse Source

refactoring: basic-model - app

refactor
Ulrich 1 year ago
parent
commit
4b1e9d0a79
  1. 2
      basic/constants.py
  2. 13
      model/entity.py
  3. 10
      model/factory.py
  4. 72
      model/project.py
  5. 61
      model/release.py
  6. 58
      model/story.py
  7. 18
      model/testcase.py
  8. 68
      model/usecase.py
  9. 84
      model/user.py
  10. 82
      model/variant.py
  11. 2
      test/test_16project.py
  12. 3
      test/test_17release.py
  13. 3
      test/test_17story.py
  14. 16
      test/test_19usecase.py
  15. 13
      test/test_19variant.py
  16. 3
      tools/file_tool.py
  17. 25
      tools/file_type.py
  18. 2
      tools/filecsv_fcts.py

2
basic/constants.py

@ -162,7 +162,7 @@ SUBJECT_COMPS = SUBJECT_COMP + "s"
SUBJECT_USECASE = "usecase"
SUBJECT_USECASES = SUBJECT_USECASE + "s"
SUBJECT_USER = "user"
SUBJECT_USECRS = SUBJECT_USER + "s"
SUBJECT_USERS = SUBJECT_USER + "s"
SUBJECT_REL = "release"
SUBJECT_RELS = SUBJECT_REL + "s"
SUBJECT_TESTCASE = "testcase"

13
model/entity.py

@ -57,7 +57,6 @@ def getEntityValue(job, field, gitcommit):
class Entity:
""" system-name for this entity """
FIELD_ID = ""
FIELD_NAME = D.FIELD_NAME
LIST_FIELDS = []
""" list of object-attributes """
LIST_NODES = []
@ -169,7 +168,17 @@ class Entity:
"""
raise Exception(B.EXCEPT_NOT_IMPLEMENT)
def check_tdata(self, job, tdata: dict) -> dict:
@staticmethod
def rebuild_data(job, tdata: dict) -> dict:
"""
gets the subtable-tag from filecsv and sets the subtables in order to workable entity-elements
:param job:
:param tdata:
:return:
"""
raise Exception(B.EXCEPT_NOT_IMPLEMENT)
def check_data(self, job, tdata: dict) -> dict:
"""
it checks the data for the specific form
:param job:

10
model/factory.py

@ -27,6 +27,8 @@ def get_entity_object(job, name, args):
entity = getTestsuite(job)
elif name in [B.SUBJECT_TESTPLANS, B.SUBJECT_TESTPLAN]:
entity = getTestplan(job)
elif name in [B.SUBJECT_USERS, B.SUBJECT_USER]:
entity = getUser(job)
else:
return None
entity.setAttributes(job, args, name, entity.getFieldList(), entity.getNodeList(), entity.getSubtableList())
@ -71,11 +73,15 @@ def getStory(job=None, project="", name=""):
def getUsecase(job=None, project="", name=""):
import model.usecase
return model.usecase.Usecase(job, project, name)
return model.usecase.Usecase(job, name)
def getUser(job=None, project="", name=""):
import model.user
return model.user.User(job, name)
def getVariant(job=None, project="", name=""):
import model.variant
return model.variant.Variant(job, project, name)
return model.variant.Variant(job, name)
def getDatatable(job=None, project="", name=""):
import model.datatable

72
model/project.py

@ -12,6 +12,7 @@ import tools.config_tool
import tools.file_tool
import tools.db_abstract
import tools.git_tool
import tools.file_type
TABLE_NAME = "project"
""" system-name for this entity """
@ -30,6 +31,11 @@ IDENTIFYER_FIELDS = [FIELD_ID]
""" unique technical field as technical identifer """
class Project(model.entity.Entity):
FIELD_ID = "prid"
LIST_FIELDS = [FIELD_ID, D.FIELD_NAME, B.SUBJECT_DESCRIPTION, B.SUBJECT_REFERENCE]
""" list of object-attributes """
LIST_NODES = []
LIST_SUBTABLES = []
prid = 0
name = ""
description = ""
@ -46,7 +52,14 @@ class Project(model.entity.Entity):
:return: list of entity-names
"""
config = self.getConfig(job, B.SUBJECT_PROJECTS, "")
outList = list(config[B.SUBJECT_PROJECTS].keys())
if B.SUBJECT_PROJECTS in config:
conf = list(config[B.SUBJECT_PROJECTS].keys())
else:
conf = config.keys()
outList = []
for k in conf:
if k[:1] != "_":
outList.append(k)
return outList
def select_unique_names(self, job, project, application, gran, args):
@ -93,40 +106,6 @@ class Project(model.entity.Entity):
setattr(self, k, config[k])
return self
def getFieldList(self):
"""
returns a list of scalar attributes
:return: LIST_FIELDS
"""
return LIST_FIELDS
def getNodeList(self):
"""
returns a list of sub-nodes - which can be persisted in a clob-field
:return: LIST_NODES
"""
return LIST_NODES
def getSubtableList(self):
"""
returns a list of sub-tables
:return: LIST_SUBTABLES
"""
return LIST_SUBTABLES
def getName(self):
"""
returns the name - maybe build from other attributes
:return:
"""
return self.name
def getIDName(self):
"""
it returns the name as unique-id - maybe build from few attributes
:return:
"""
return self.name
def select_entity(self, job, name, row={}):
"""
@ -259,11 +238,32 @@ class Project(model.entity.Entity):
if config is not None:
if len(name) == 0:
return config
elif name in config[subject]:
elif subject in config and name in config[subject]:
return config[subject][name]
elif name in config:
return config[name]
raise Exception("keine Config zu "+name)
@staticmethod
def getCurrentUser(job):
return os.environ.get("USERNAME")
@staticmethod
def rebuild_data(job, data: dict) -> dict:
"""
gets the subtable-tag from filecsv and sets the subtables in order to workable entity-elements
:param job:
:param data:
:return:
"""
data = tools.file_type.popSubjectsNode(job, data)
data = tools.file_type.popNameNode(job, data)
return data
@staticmethod
def check_data(job, data: dict) -> dict:
checkNodes = {}
checkNodes[tools.file_type.MUST_NODES] = []
checkNodes[tools.file_type.MUSTNT_NODES] = [B.DATA_NODE_OPTION, B.DATA_NODE_DATA, B.DATA_NODE_FIELDS, B.DATA_NODE_HEADER]
checkNodes[tools.file_type.OPT_NODES] = [B.SUBJECT_PROJECTS, B.NODE_ATTRIBUTES]
return tools.file_type.check_nodes(job, data, checkNodes)

61
model/release.py

@ -15,24 +15,20 @@ import tools.git_tool
TABLE_NAME = "release"
""" system-name for this entity """
FIELD_ID = "rlid"
FIELD_NAME = "name"
FIELD_DESCRIPTION = B.SUBJECT_DESCRIPTION
FIELD_REFERENCE = B.SUBJECT_REFERENCE
FIELD_PROJECT = B.SUBJECT_PROJECT
FIELD_APPLICATION = B.SUBJECT_APP
FIELD_ATTRIBUTES = B.NODE_ATTRIBUTES
LIST_FIELDS = [FIELD_ID, FIELD_NAME, FIELD_DESCRIPTION, FIELD_REFERENCE, FIELD_PROJECT, FIELD_APPLICATION, FIELD_ATTRIBUTES]
""" list of object-attributes """
LIST_NODES = [B.NODE_ATTRIBUTES]
LIST_SUBTABLES = []
FILE_EXTENSION = D.DFILE_TYPE_CSV
UNIQUE_FIELDS = [FIELD_NAME]
UNIQUE_FIELDS = [D.FIELD_NAME]
""" unique business field as human identifer """
IDENTIFYER_FIELDS = [FIELD_ID]
""" unique technical field as technical identifer """
class Release(model.entity.Entity):
FIELD_ID = "rlid"
LIST_FIELDS = [FIELD_ID, D.FIELD_NAME, B.SUBJECT_DESCRIPTION, B.SUBJECT_REFERENCE, B.SUBJECT_PROJECT, B.SUBJECT_APP,
B.NODE_ATTRIBUTES]
""" list of object-attributes """
LIST_NODES = [B.NODE_ATTRIBUTES]
LIST_SUBTABLES = []
rlid = 0
name = ""
project = ""
@ -51,7 +47,7 @@ class Release(model.entity.Entity):
:param opt. args additional args
:return: list of entity-names
"""
config = self.getConfig(job, P.KEY_CATALOG, B.SUBJECT_RELS, tools.config_tool.get_plain_filename(job, ""))
config = self.getConfig(job, P.KEY_CATALOG, B.SUBJECT_RELS, tools.config_tool.get_plain_filename(job, ""), D.CSV_SPECTYPE_CTLG)
outList = list(config[B.SUBJECT_RELS][B.DATA_NODE_KEYS].keys())
return outList
@ -62,40 +58,7 @@ class Release(model.entity.Entity):
:param name:
:return:
"""
config = self.getConfig(job, P.KEY_CATALOG, B.SUBJECT_RELS, tools.config_tool.get_plain_filename(job, name))
return self.setAttributes(job, config, name, LIST_FIELDS, LIST_NODES, LIST_SUBTABLES)
def getFieldList(self):
"""
returns a list of scalar attributes
:return: LIST_FIELDS
"""
return LIST_FIELDS
config = self.getConfig(job, P.KEY_CATALOG, B.SUBJECT_RELS,
tools.config_tool.get_plain_filename(job, name), ttype=D.CSV_SPECTYPE_CTLG)
return self.setAttributes(job, config, name, self.LIST_FIELDS, self.LIST_NODES, self.LIST_SUBTABLES)
def getNodeList(self):
"""
returns a list of sub-nodes - which can be persisted in a clob-field
:return: LIST_NODES
"""
return LIST_NODES
def getSubtableList(self):
"""
returns a list of sub-tables
:return: LIST_SUBTABLES
"""
return LIST_SUBTABLES
def getName(self):
"""
returns the name - maybe build from other attributes
:return:
"""
return self.name
def getIDName(self):
"""
it returns the name as unique-id - maybe build from few attributes
:return:
"""
return self.name

58
model/story.py

@ -13,23 +13,21 @@ import tools.git_tool
TABLE_NAME = "story"
""" system-name for this entity """
FIELD_ID = "stid"
FIELD_NAME = "name"
FIELD_DESCRIPTION = B.SUBJECT_DESCRIPTION
FIELD_REFERENCE = B.SUBJECT_REFERENCE
FIELD_PROJECT = B.SUBJECT_PROJECT
FIELD_ATTRIBUTES = B.NODE_ATTRIBUTES
LIST_FIELDS = [FIELD_ID, FIELD_NAME, FIELD_DESCRIPTION, FIELD_REFERENCE, FIELD_PROJECT, FIELD_ATTRIBUTES]
""" list of object-attributes """
LIST_NODES = [B.NODE_ATTRIBUTES]
LIST_SUBTABLES = {}
FILE_EXTENSION = D.DFILE_TYPE_CSV
UNIQUE_FIELDS = [FIELD_NAME]
UNIQUE_FIELDS = [D.FIELD_NAME]
""" unique business field as human identifer """
IDENTIFYER_FIELDS = [FIELD_ID]
""" unique technical field as technical identifer """
class Story(model.entity.Entity):
FIELD_ID = "stid"
LIST_FIELDS = [FIELD_ID, D.FIELD_NAME, B.SUBJECT_DESCRIPTION, B.SUBJECT_REFERENCE, B.SUBJECT_PROJECT]
""" list of object-attributes """
LIST_NODES = []
LIST_SUBTABLES = [B.SUBJECT_RELS]
stid = 0
story = ""
project = ""
@ -46,7 +44,8 @@ class Story(model.entity.Entity):
:param opt. args additional args
:return: list of entity-names
"""
config = self.getConfig(job, P.KEY_CATALOG, B.SUBJECT_STORIES, tools.config_tool.get_plain_filename(job, ""))
config = self.getConfig(job, P.KEY_CATALOG, B.SUBJECT_STORIES,
tools.config_tool.get_plain_filename(job, ""), ttype=D.CSV_SPECTYPE_CTLG)
outList = list(config[B.SUBJECT_STORIES][B.DATA_NODE_KEYS].keys())
return outList
@ -57,40 +56,7 @@ class Story(model.entity.Entity):
:param name:
:return:
"""
config = self.getConfig(job, P.KEY_CATALOG, B.SUBJECT_STORIES, tools.config_tool.get_plain_filename(job, name))
return self.setAttributes(job, config, name, LIST_FIELDS, LIST_NODES, LIST_SUBTABLES)
def getFieldList(self):
"""
returns a list of scalar attributes
:return: LIST_FIELDS
"""
return LIST_FIELDS
config = self.getConfig(job, P.KEY_CATALOG, B.SUBJECT_STORIES,
tools.config_tool.get_plain_filename(job, name), ttype=D.CSV_SPECTYPE_CTLG)
return self.setAttributes(job, config, name, self.LIST_FIELDS, self.LIST_NODES, self.LIST_SUBTABLES)
def getNodeList(self):
"""
returns a list of sub-nodes - which can be persisted in a clob-field
:return: LIST_NODES
"""
return LIST_NODES
def getSubtableList(self):
"""
returns a list of sub-tables
:return: LIST_SUBTABLES
"""
return LIST_SUBTABLES
def getName(self):
"""
returns the name - maybe build from other attributes
:return:
"""
return self.name
def getIDName(self):
"""
it returns the name as unique-id - maybe build from few attributes
:return:
"""
return self.name

18
model/testcase.py

@ -19,6 +19,7 @@ import model.story
import model.datatable
import model.step
import model.factory
import tools.file_type
TABLE_NAMES = ["application", "ap_project", "ap_component"]
STORAGES = [model.entity.STORAGE_FILE, model.entity.STORAGE_DB]
@ -70,7 +71,7 @@ class Testcase(model.entity.Entity):
tables -> comp.table
"""
FIELD_ID = "tcid"
LIST_FIELDS = [FIELD_ID, D.FIELD_NAME, B.SUBJECT_APP,
LIST_FIELDS = [FIELD_ID, D.FIELD_NAME, B.SUBJECT_APPS,
B.SUBJECT_DESCRIPTION, B.SUBJECT_REFERENCE, B.SUBJECT_PROJECT]
LIST_NODES = [B.NODE_ATTRIBUTES]
tcid = ""
@ -126,7 +127,7 @@ class Testcase(model.entity.Entity):
return self
@staticmethod
def set_subtables(job, tdata: dict) -> dict:
def rebuild_data(job, tdata: dict) -> dict:
"""
gets the subtable-tag from filecsv and sets the subtables in order to workable entity-elements
:param job:
@ -181,6 +182,8 @@ class Testcase(model.entity.Entity):
subtables[ka[0]] = subject
else: # attributes
arguments[e] = tdata[k][e]
elif k in B.SUBJECT_STORY:
outData[B.SUBJECT_STORIES] = tdata[k]
elif k in B.LIST_SUBJECTS:
outData[k] = tdata[k]
elif k in B.LIST_DATA_NODE:
@ -191,9 +194,18 @@ class Testcase(model.entity.Entity):
raise Exception("unknown tag in csv-data: "+k)
for s in subtables:
outData[s] = subtables[s]
outData[B.DATA_NODE_ARGS] = arguments
outData[B.NODE_ATTRIBUTES] = arguments
return outData
@staticmethod
def check_data(job, data: dict) -> dict:
checkNodes = {}
checkNodes[tools.file_type.MUST_NODES] = [B.SUBJECT_APP, B.SUBJECT_DATATABLES, B.SUBJECT_STEPS,
B.NODE_ATTRIBUTES]
checkNodes[tools.file_type.MUSTNT_NODES] = [B.DATA_NODE_OPTION, B.DATA_NODE_DATA, B.DATA_NODE_FIELDS, B.DATA_NODE_HEADER]
checkNodes[tools.file_type.OPT_NODES] = [B.SUBJECT_USECASES, B.SUBJECT_STORIES]
return tools.file_type.check_nodes(job, data, checkNodes)
def getFieldList(self):
"""
returns a list of scalar attributes

68
model/usecase.py

@ -9,28 +9,24 @@ import tools.data_const as D
import tools.config_tool
import tools.file_tool
import tools.git_tool
import tools.file_type
TABLE_NAME = "uscase"
""" system-name for this entity """
FIELD_ID = "ucid"
FIELD_NAME = "name"
FIELD_DESCRIPTION = B.SUBJECT_DESCRIPTION
FIELD_REFERENCE = B.SUBJECT_REFERENCE
FIELD_PROJECT = B.SUBJECT_PROJECT
FIELD_APPLICATION = B.SUBJECT_APP
FIELD_ATTRIBUTES = B.NODE_ATTRIBUTES
LIST_FIELDS = [FIELD_ID, FIELD_NAME, FIELD_DESCRIPTION, FIELD_REFERENCE, FIELD_PROJECT, FIELD_APPLICATION, FIELD_ATTRIBUTES]
""" list of object-attributes """
LIST_NODES = [B.NODE_ATTRIBUTES]
LIST_SUBTABLES = []
FILE_EXTENSION = D.DFILE_TYPE_CSV
UNIQUE_FIELDS = [FIELD_NAME]
UNIQUE_FIELDS = [D.FIELD_NAME]
""" unique business field as human identifer """
IDENTIFYER_FIELDS = [FIELD_ID]
""" unique technical field as technical identifer """
class Usecase(model.entity.Entity):
FIELD_ID = "ucid"
LIST_FIELDS = [FIELD_ID, D.FIELD_NAME, B.SUBJECT_DESCRIPTION, B.SUBJECT_REFERENCE, B.SUBJECT_PROJECT, B.SUBJECT_APP]
""" list of object-attributes """
LIST_NODES = [B.NODE_ATTRIBUTES]
LIST_SUBTABLES = []
ucid = 0
usecase = ""
project = ""
@ -39,14 +35,6 @@ class Usecase(model.entity.Entity):
reference = ""
attributes = ""
def __init__(self, job, project, name=""):
"""
to be initialized by readSpec
:param job:
"""
self.job = job
self.project = project
def read_unique_names(self, job, project, application, gran, args):
"""
reads the entity-names from file-storage
@ -57,7 +45,8 @@ class Usecase(model.entity.Entity):
:param opt. args additional args
:return: list of entity-names
"""
config = self.getConfig(job, P.KEY_CATALOG, B.SUBJECT_USECASES, tools.config_tool.get_plain_filename(job, ""))
config = self.getConfig(job, P.KEY_CATALOG, B.SUBJECT_USECASES,
tools.config_tool.get_plain_filename(job, ""), ttype=D.CSV_SPECTYPE_CTLG)
outList = list(config[B.SUBJECT_USECASES][B.DATA_NODE_KEYS].keys())
return outList
@ -68,40 +57,7 @@ class Usecase(model.entity.Entity):
:param name:
:return:
"""
config = self.getConfig(job, P.KEY_CATALOG, B.SUBJECT_USECASES, tools.config_tool.get_plain_filename(job, name))
return self.setAttributes(job, config, name, LIST_FIELDS, LIST_NODES, LIST_SUBTABLES)
def getFieldList(self):
"""
returns a list of scalar attributes
:return: LIST_FIELDS
"""
return LIST_FIELDS
config = self.getConfig(job, P.KEY_CATALOG, B.SUBJECT_USECASES,
tools.config_tool.get_plain_filename(job, name), ttype=D.CSV_SPECTYPE_CTLG)
return self.setAttributes(job, config, name, self.LIST_FIELDS, self.LIST_NODES, self.LIST_SUBTABLES)
def getNodeList(self):
"""
returns a list of sub-nodes - which can be persisted in a clob-field
:return: LIST_NODES
"""
return LIST_NODES
def getSubtableList(self):
"""
returns a list of sub-tables
:return: LIST_SUBTABLES
"""
return LIST_SUBTABLES
def getName(self):
"""
returns the name - maybe build from other attributes
:return:
"""
return self.name
def getIDName(self):
"""
it returns the name as unique-id - maybe build from few attributes
:return:
"""
return self.name

84
model/user.py

@ -15,19 +15,9 @@ import tools.git_tool
TABLE_NAME = "user"
""" system-name for this entity """
FIELD_ID = "id"
FIELD_USERNAME = "username"
FIELD_NAME = "name"
FIELD_FAMNAME = "famname"
FIELD_EMAIL = "email"
FIELD_PASSWORD = "password"
FIELD_PROJECT = B.SUBJECT_PROJECT
FIELD_ROLE = "role"
LIST_FIELDS = [FIELD_ID, FIELD_ROLE, FIELD_PROJECT, FIELD_PASSWORD, FIELD_EMAIL, FIELD_FAMNAME, FIELD_NAME, FIELD_USERNAME]
""" list of object-attributes """
LIST_NODES = [B.NODE_ATTRIBUTES]
LIST_SUBTABLES = {}
FILE_EXTENSION = D.DFILE_TYPE_YML
UNIQUE_FIELDS = [FIELD_USERNAME]
""" unique business field as human identifer """
@ -35,6 +25,14 @@ IDENTIFYER_FIELDS = [FIELD_ID]
""" unique technical field as technical identifer """
class User(model.entity.Entity):
FIELD_ID = "id"
FIELD_USERNAME = "username"
FIELD_NAME = "name"
FIELD_FAMNAME = "famname"
FIELD_EMAIL = "email"
FIELD_PASSWORD = "password"
FIELD_PROJECT = B.SUBJECT_PROJECT
FIELD_ROLE = "role"
LIST_FIELDS = [FIELD_ID, FIELD_ROLE, FIELD_PROJECT, FIELD_PASSWORD, FIELD_EMAIL, FIELD_FAMNAME, FIELD_NAME,
FIELD_USERNAME]
""" list of object-attributes """
@ -108,12 +106,32 @@ class User(model.entity.Entity):
"""
print("name "+name)
config = model.user.User.getUserConfig(job, tools.config_tool.get_plain_filename(job, name))
for k in LIST_FIELDS:
for k in self.LIST_FIELDS:
if k not in config:
continue
setattr(self, k, config[k])
return self
@staticmethod
def rebuild_data(job, data: dict) -> dict:
"""
gets the subtable-tag from filecsv and sets the subtables in order to workable entity-elements
:param job:
:param data:
:return:
"""
data = tools.file_type.popSubjectsNode(job, data)
data = tools.file_type.popNameNode(job, data)
outdata = {}
for k in data:
if k == "sysuser":
sysuser = User.getCurrentUser(job)
outdata[sysuser] = data[k]
outdata[sysuser][FIELD_USERNAME] = sysuser
else:
outdata[k] = data[k]
return outdata
def check_data(self, job, data: dict) -> dict:
"""
it checks the data for the specific form
@ -124,45 +142,11 @@ class User(model.entity.Entity):
"""
import tools.file_type
checkNodes = {}
checkNodes[tools.file_type.MUST_NODES] = [B.DATA_NODE_HEADER, B.DATA_NODE_FIELDS, B.DATA_NODE_KEYS]
checkNodes[tools.file_type.MUSTNT_NODES] = [B.DATA_NODE_DATA]
checkNodes[tools.file_type.MUST_NODES] = []
checkNodes[tools.file_type.MUSTNT_NODES] = [B.DATA_NODE_DATA, B.DATA_NODE_HEADER, B.DATA_NODE_FIELDS, B.DATA_NODE_KEYS] + B.LIST_SUBJECTS
checkNodes[tools.file_type.OPT_NODES] = []
return tools.file_type.check_nodes(job, data, checkNodes)
def getFieldList(self):
"""
returns a list of scalar attributes
:return: LIST_FIELDS
"""
return LIST_FIELDS
def getNodeList(self):
"""
returns a list of sub-nodes - which can be persisted in a clob-field
:return: LIST_NODES
"""
return LIST_NODES
def getSubtableList(self):
"""
returns a list of sub-tables
:return: LIST_SUBTABLES
"""
return LIST_SUBTABLES
def getName(self):
"""
returns the name - maybe build from other attributes
:return:
"""
return self.name
def getIDName(self):
"""
it returns the name as unique-id - maybe build from few attributes
:return:
"""
return self.name
def select_entity(self, job, name, row={}):
"""
@ -190,7 +174,7 @@ class User(model.entity.Entity):
row = data[B.DATA_NODE_DATA][0]
else:
raise Exception("no result for: "+names[0])
for k in LIST_FIELDS:
for k in self.LIST_FIELDS:
if k not in row:
continue
setattr(self, k, row[k])
@ -208,7 +192,7 @@ class User(model.entity.Entity):
config[model.user.TABLE_NAME] = {}
pathname = os.path.join(job.conf[B.TOPIC_PATH][P.ATTR_PATH_HOME], P.VAL_CONFIG,
P.VAL_USER, name + ".yml")
for k in LIST_FIELDS:
for k in self.LIST_FIELDS:
if getattr(self, k, "") == "" \
or k == FIELD_ID:
continue

82
model/variant.py

@ -16,25 +16,21 @@ import tools.git_tool
TABLE_NAME = "variant"
""" system-name for this entity """
FIELD_ID = "vrid"
FIELD_NAME = "name"
FIELD_DESCRIPTION = B.SUBJECT_DESCRIPTION
FIELD_REFERENCE = B.SUBJECT_REFERENCE
FIELD_PROJECT = B.SUBJECT_PROJECT
FIELD_COMPONENT = B.SUBJECT_COMP
FIELD_ATTRIBUTES = B.NODE_ATTRIBUTES
LIST_FIELDS = [FIELD_ID, FIELD_NAME, FIELD_DESCRIPTION, FIELD_REFERENCE, FIELD_PROJECT, FIELD_COMPONENT, FIELD_ATTRIBUTES]
""" list of object-attributes """
LIST_NODES = [B.NODE_ATTRIBUTES]
LIST_SUBTABLES = []
FILE_EXTENSION = D.DFILE_TYPE_YML
UNIQUE_FIELDS = [FIELD_NAME]
UNIQUE_FIELDS = [D.FIELD_NAME]
""" unique business field as human identifer """
IDENTIFYER_FIELDS = [FIELD_ID]
""" unique technical field as technical identifer """
class Variant(model.entity.Entity):
FIELD_ID = "vrid"
LIST_FIELDS = [FIELD_ID, D.FIELD_NAME, B.SUBJECT_DESCRIPTION, B.SUBJECT_REFERENCE, B.SUBJECT_PROJECT]
""" list of object-attributes """
LIST_NODES = [B.NODE_ATTRIBUTES]
LIST_SUBTABLES = [B.SUBJECT_COMPS]
""" list of object-attributes """
name = ""
description = ""
reference = ""
@ -42,17 +38,6 @@ class Variant(model.entity.Entity):
project = ""
component = ""
def __init__(self, job, project, name=""):
"""
to be initialized by readSpec
project : optional
alternative parameter
name : name of variant or default - only from testspec
obj : object with main attributes
:param job:
"""
self.job = job
self.project = project
def read_unique_names(self, job, project, application, gran, args):
"""
@ -64,7 +49,8 @@ class Variant(model.entity.Entity):
:param opt. args additional args
:return: list of entity-names
"""
config = self.getConfig(job, P.KEY_BASIC, B.SUBJECT_VARIANTS, tools.config_tool.get_plain_filename(job, ""))
config = self.getConfig(job, P.KEY_BASIC, B.SUBJECT_VARIANTS,
tools.config_tool.get_plain_filename(job, ""), B.SUBJECT_VARIANT)
outList = list(config[B.SUBJECT_VARIANTS].keys())
return outList
@ -75,40 +61,28 @@ class Variant(model.entity.Entity):
:param name:
:return:
"""
config = self.getConfig(job, P.KEY_BASIC, B.SUBJECT_VARIANTS, tools.config_tool.get_plain_filename(job, name))
return self.setAttributes(job, config, name, LIST_FIELDS, LIST_NODES, LIST_SUBTABLES)
def getFieldList(self):
"""
returns a list of scalar attributes
:return: LIST_FIELDS
"""
return LIST_FIELDS
def getNodeList(self):
"""
returns a list of sub-nodes - which can be persisted in a clob-field
:return: LIST_NODES
"""
return LIST_NODES
config = self.getConfig(job, P.KEY_BASIC, B.SUBJECT_VARIANTS,
tools.config_tool.get_plain_filename(job, name), B.SUBJECT_VARIANT)
return self.setAttributes(job, config, name, self.LIST_FIELDS, self.LIST_NODES, self.LIST_SUBTABLES)
def getSubtableList(self):
"""
returns a list of sub-tables
:return: LIST_SUBTABLES
"""
return LIST_SUBTABLES
def getName(self):
@staticmethod
def rebuild_data(job, data: dict) -> dict:
"""
returns the name - maybe build from other attributes
gets the subtable-tag from filecsv and sets the subtables in order to workable entity-elements
:param job:
:param data:
:return:
"""
return self.name
data = tools.file_type.popSubjectsNode(job, data)
data = tools.file_type.popNameNode(job, data)
return data
@staticmethod
def check_data(job, data: dict) -> dict:
checkNodes = {}
checkNodes[tools.file_type.MUST_NODES] = []
checkNodes[tools.file_type.MUSTNT_NODES] = [B.DATA_NODE_OPTION, B.DATA_NODE_DATA, B.DATA_NODE_FIELDS, B.DATA_NODE_HEADER]
checkNodes[tools.file_type.OPT_NODES] = [B.SUBJECT_PROJECTS, B.NODE_ATTRIBUTES]
return tools.file_type.check_nodes(job, data, checkNodes)
def getIDName(self):
"""
it returns the name as unique-id - maybe build from few attributes
:return:
"""
return self.name

2
test/test_16project.py

@ -33,7 +33,7 @@ class MyTestCase(unittest.TestCase):
project = model.project.Project(job)
entityNames = []
entityNames = project.read_unique_names(job, "", "", "", {})
self.assertEquals(type(entityNames), list)
self.assertEqual(type(entityNames), list)
#entityNames = project.select_unique_names(job, "", "", "", {})
#self.assertEquals(type(entityNames), list)

3
test/test_17release.py

@ -11,6 +11,7 @@ import basic.constants as B
import test.constants as T
import model.release
import model.entity
import tools.data_const as D
HOME_PATH = test.constants.HOME_PATH
PYTHON_CMD = "python"
@ -65,7 +66,7 @@ class MyTestCase(unittest.TestCase):
release = model.release.Release(job)
name = "V-1.1.0"
actrelease = release.read_entity(job, name)
self.assertEqual(getattr(actrelease, model.release.FIELD_NAME), name)
self.assertEqual(getattr(actrelease, D.FIELD_NAME), name)
self.assertRaises(Exception, release.read_entity, job, "xyzxyz")
#
#actrelease = release.select_entity(job, name)

3
test/test_17story.py

@ -11,6 +11,7 @@ import basic.constants as B
import test.constants as T
import model.story
import model.entity
import tools.data_const as D
HOME_PATH = test.constants.HOME_PATH
PYTHON_CMD = "python"
@ -64,7 +65,7 @@ class MyTestCase(unittest.TestCase):
story = model.story.Story(job)
name = "S-1"
actstory = story.read_entity(job, name)
self.assertEqual(getattr(actstory, model.story.FIELD_NAME), name)
self.assertEqual(getattr(actstory, D.FIELD_NAME), name)
self.assertRaises(Exception, story.read_entity, job, "xyzxyz")
#
#actstory = story.select_entity(job, name)

16
test/test_19usecase.py

@ -11,11 +11,13 @@ import basic.constants as B
import test.constants as T
import model.usecase
import model.entity
import tools.data_const as D
HOME_PATH = test.constants.HOME_PATH
PYTHON_CMD = "python"
TEST_FUNCTIONS = ["test_10getEntityNames", "test_11getEntities", "test_12getEntity",
"test_13writeEntity", "test_14insertEntity"]
TEST_FUNCTIONS = ["test_10getEntityNames", "test_11getEntities", "test_12getEntity"
#"test_13writeEntity", "test_14insertEntity"
]
TEST_FUNCTIONS = ["test_10getEntityNames", "test_12getEntity"]
PROGRAM_NAME = "clean_workspace"
@ -31,10 +33,10 @@ class MyTestCase(unittest.TestCase):
if actfunction not in TEST_FUNCTIONS:
return
job = test.testtools.getJob()
usecase = model.usecase.Usecase(job, "TESTPROJ")
usecase = model.usecase.Usecase(job)
entityNames = []
entityNames = usecase.read_unique_names(job, "", "", "", {})
self.assertEquals(type(entityNames), list)
self.assertEqual(type(entityNames), list)
#entityNames = project.select_unique_names(job, "", "", "", {})
#self.assertEquals(type(entityNames), list)
@ -46,7 +48,7 @@ class MyTestCase(unittest.TestCase):
if actfunction not in TEST_FUNCTIONS:
return
job = test.testtools.getJob()
usecase = model.usecase.Usecase(job, "TESTPROJ")
usecase = model.usecase.Usecase(job)
entityNames = []
entityNames = usecase.get_entities(job, storage=model.entity.STORAGE_FILE)
self.assertEqual(type(entityNames), list)
@ -61,10 +63,10 @@ class MyTestCase(unittest.TestCase):
if actfunction not in TEST_FUNCTIONS:
return
job = test.testtools.getJob()
usecase = model.usecase.Usecase(job, "TESTPROJ")
usecase = model.usecase.Usecase(job)
name = "AWF-1"
actusecase = usecase.read_entity(job, name)
self.assertEqual(getattr(actusecase, model.usecase.FIELD_NAME), name)
self.assertEqual(getattr(actusecase, D.FIELD_NAME), name)
self.assertRaises(Exception, usecase.read_entity, job, "xyzxyz")
#
#actproject = project.select_entity(job, name)

13
test/test_19variant.py

@ -11,6 +11,7 @@ import basic.constants as B
import test.constants as T
import model.variant
import model.entity
import tools.data_const as D
HOME_PATH = test.constants.HOME_PATH
PYTHON_CMD = "python"
@ -31,7 +32,7 @@ class MyTestCase(unittest.TestCase):
if actfunction not in TEST_FUNCTIONS:
return
job = test.testtools.getJob()
variant = model.variant.Variant(job, "TESTPROJ")
variant = model.variant.Variant(job)
entityNames = []
entityNames = variant.read_unique_names(job, "", "", "", {})
self.assertEqual(type(entityNames), list)
@ -46,7 +47,7 @@ class MyTestCase(unittest.TestCase):
if actfunction not in TEST_FUNCTIONS:
return
job = test.testtools.getJob()
variant = model.variant.Variant(job, "TESTPROJ")
variant = model.variant.Variant(job)
entityNames = []
entityNames = variant.get_entities(job, storage=model.entity.STORAGE_FILE)
self.assertEqual(type(entityNames), list)
@ -61,10 +62,10 @@ class MyTestCase(unittest.TestCase):
if actfunction not in TEST_FUNCTIONS:
return
job = test.testtools.getJob()
variant = model.variant.Variant(job, "TESTPROJ")
variant = model.variant.Variant(job)
name = "xml-rest"
actrelease = variant.read_entity(job, name)
self.assertEqual(getattr(actrelease, model.variant.FIELD_NAME), name)
self.assertEqual(getattr(actrelease, D.FIELD_NAME), name)
self.assertRaises(Exception, variant.read_entity, job, "xyzxyz")
#
#actvariant = variant.select_entity(job, name)
@ -80,7 +81,7 @@ class MyTestCase(unittest.TestCase):
return
job = test.testtools.getJob()
username = "hans_xyz"
variant = model.variant.Variant(job, "TESTPROJ")
variant = model.variant.Variant(job)
entityNames = variant.get_unique_names(job, storage=model.entity.STORAGE_FILE)
self.assertNotIn(username, entityNames)
variant.username = username
@ -105,7 +106,7 @@ class MyTestCase(unittest.TestCase):
return
job = test.testtools.getJob()
username = "hans_xyz"
variant = model.variant.Variant(job, "TESTPROJ")
variant = model.variant.Variant(job)
entityNames = collectInnerList(variant.get_unique_names(job, storage=model.entity.STORAGE_DB))
#self.assertNotIn(username, entityNames)
variant.username = username

3
tools/file_tool.py

@ -225,16 +225,19 @@ def read_file_dict(job, path: str, msg, ttype: str = D.DFILE_TYPE_CSV) -> dict:
with open(path, 'r', encoding=enc) as file:
doc = yaml.full_load(file)
file.close()
doc = tools.file_type.rebuild_tdata(job, doc, {}, ttype)
elif D.DFILE_TYPE_JSON in path[-5:]:
with open(path, 'r', encoding=enc) as file:
doc = json.load(file)
file.close()
doc = tools.file_type.rebuild_tdata(job, doc, {}, ttype)
elif D.DFILE_TYPE_XML in path[-4:]:
with open(path, 'r', encoding=enc) as file:
res = xmltodict.parse(file.read())
# doc = dict(res)
doc = castOrderedDict(res)
file.close()
doc = tools.file_type.rebuild_tdata(job, doc, {}, ttype)
elif D.DFILE_TYPE_CSV in path[-5:]:
ffcts = basic.toolHandling.getFileTool(job, None, D.DFILE_TYPE_CSV)
#doc = tools.tdata_tool.getCsvSpec(msg, job, path, D.CSV_SPECTYPE_CONF)

25
tools/file_type.py

@ -1,6 +1,7 @@
import os
import basic.constants as B
import tools.data_const as D
import model.factory
MUST_NODES = "must"
MUSTNT_NODES = "mustnt"
@ -24,7 +25,10 @@ def rebuild_tdata(job, tdata: dict, tableAttr: dict, ttype:str) -> dict:
# return rebuildCatalog(job, tdata)
elif ttype == D.CSV_SPECTYPE_TREE:
return rebuildCatalog(job, tdata)
elif ttype in B.LIST_SUBJECTS:
elif ttype + "s" in B.LIST_SUBJECTS or ttype == B.SUBJECT_USER:
enty = model.factory.get_entity_object(job, ttype, {})
return enty.rebuild_data(job, tdata)
elif ttype in ["basic", "tool"]:
return tdata
else:
raise Exception("ttype is not defined " + ttype)
@ -105,8 +109,9 @@ def check_tdata(job, tdata: dict, ttype:str) -> dict:
return DatatypeCatalog.check_data(job, tdata)
elif ttype == D.CSV_SPECTYPE_TREE:
return checkCatalog(job, tdata)
elif ttype in B.LIST_SUBJECTS:
return tdata
elif ttype + "s" in B.LIST_SUBJECTS or ttype == B.SUBJECT_USER:
enty = model.factory.get_entity_object(job, ttype, {})
return enty.check_data(job, tdata)
elif ttype in ["basic"]:
return tdata
else:
@ -166,6 +171,13 @@ class DatatypeCatalog():
checkNodes[OPT_NODES] = [B.DATA_NODE_FIELDS]
return check_nodes(job, data, checkNodes)
def popSubjectsNode(job, data: dict) -> dict:
if len(data) == 1:
key = list(data.keys())[0]
if key in B.LIST_SUBJECTS:
data = data[key]
return data
def popTablesNode(job, data: dict) -> dict:
if B.DATA_NODE_TABLES not in data:
return data
@ -241,9 +253,9 @@ class DatatypeDDL():
@staticmethod
def check_data(job, data: dict) -> dict:
checkNodes = {}
checkNodes[MUST_NODES] = [B.DATA_NODE_HEADER, B.DATA_NODE_FIELDS, B.DATA_NODE_KEYS]
checkNodes[MUST_NODES] = [B.DATA_NODE_HEADER, B.DATA_NODE_KEYS]
checkNodes[MUSTNT_NODES] = [B.DATA_NODE_DATA]
checkNodes[OPT_NODES] = []
checkNodes[OPT_NODES] = [B.DATA_NODE_FIELDS]
return check_nodes(job, data, checkNodes)
@ -296,13 +308,16 @@ def check_nodes(job, config: dict, checkNodes: dict):
a = str(config["_path"]).split(os.path.sep)
b = a[-1].split(".")
path = config["_path"]
"""
if b[0] in config:
config = config[b[0]]
config["_path"] = path
if len(config) == 2:
for x in B.LIST_SUBJECTS:
if x[:-1] in config:
config = config[x[:-1]]
break
"""
for n in mustNodes:
if n not in config:
raise Exception("must-node doesnt exist "+n+" "+path)

2
tools/filecsv_fcts.py

@ -207,7 +207,7 @@ class FileFcts(tools.file_abstract.FileFcts):
print("csvfcts 198 "+ttype)
enty = model.factory.get_entity_object(job, ttype, {})
print(str(tdata))
tdata = enty.set_subtables(job, tdata)
tdata = enty.rebuild_data(job, tdata)
elif ttype in [D.CSV_SPECTYPE_DDL, D.CSV_SPECTYPE_CTLG, D.CSV_SPECTYPE_MDL]:
if len(tdata[B.DATA_NODE_TABLES]) > 1:
job.m.setError("Mehr als eine Tabelle in "+ttype)

Loading…
Cancel
Save