Browse Source

unittests

refactor
Ulrich 1 year ago
parent
commit
ae216c08d4
  1. 19
      basic/Testserver.py
  2. 2
      basic/message.py
  3. 69
      basic/testkonzept.txt
  4. 7
      init_testsuite.py
  5. 2
      model/entity.py
  6. 6
      model/factory.py
  7. 11
      model/step.py
  8. 2
      test/test_03path.py
  9. 8
      test/test_11message.py
  10. 3
      test/test_14entity.py
  11. 2
      test/test_15user.py
  12. 2
      test/test_20application.py
  13. 27
      test/test_28step.py
  14. 10
      test/test_90testserver.py

19
basic/Testserver.py

@ -9,14 +9,24 @@ import tools.data_const as D
import tools.file_tool import tools.file_tool
import tools.filecsv_fcts import tools.filecsv_fcts
import model.table import model.table
import tools.value_tool
import tools.data_tool
COMP_NAME = B.ATTR_INST_TESTSERVER COMP_NAME = B.ATTR_INST_TESTSERVER
COMP_TABLES = ["application", "ap_component", "ap_project", "ap_application", COMP_TABLES = ["application", "ap_component", "ap_project", "ap_application",
"environment", "en_component", "en_project"] "environment", "en_component", "en_project"]
class Testserver(basic.component.Component): # class Testserver(basic.component.Component):
class Testserver():
"""
the Testserver represents the workspace with all resources for the automation
"""
tables = {} tables = {}
def __init__(self, job): def __init__(self, job):
"""
collect all resources into this object
:param job:
"""
print('init '+COMP_NAME) print('init '+COMP_NAME)
self.m = job.m self.m = job.m
self.conf = {} self.conf = {}
@ -26,6 +36,12 @@ class Testserver(basic.component.Component):
for attr in B.LIST_DB_ATTR: for attr in B.LIST_DB_ATTR:
if attr in job.conf[B.TOPIC_NODE_DB]: if attr in job.conf[B.TOPIC_NODE_DB]:
self.conf[B.TOPIC_CONN][B.TOPIC_NODE_DB][attr] = job.conf[B.TOPIC_NODE_DB][attr] self.conf[B.TOPIC_CONN][B.TOPIC_NODE_DB][attr] = job.conf[B.TOPIC_NODE_DB][attr]
# TODO was muss auf dem Testserver initial geladen werden?
self.model = {}
for s in B.LIST_SUBJECTS:
self.model[tools.data_tool.getSingularKeyword(s)] = {}
def restInit(self):
if not B.DATA_NODE_DDL in self.conf: if not B.DATA_NODE_DDL in self.conf:
self.conf[B.DATA_NODE_DDL] = {} self.conf[B.DATA_NODE_DDL] = {}
for table in COMP_TABLES: for table in COMP_TABLES:
@ -55,6 +71,7 @@ class Testserver(basic.component.Component):
else: else:
self.conf[B.DATA_NODE_DDL][table] = ddl self.conf[B.DATA_NODE_DDL][table] = ddl
def createDBTables(self, job): def createDBTables(self, job):
tables = {} tables = {}
if B.TOPIC_NODE_DB in job.conf: if B.TOPIC_NODE_DB in job.conf:

2
basic/message.py

@ -377,7 +377,7 @@ class Message:
def getLoggingArgs(self, mlevel, prio, text): def getLoggingArgs(self, mlevel, prio, text):
verify = self.getLogLevel("msg_tool") verify = self.getLogLevel("msg_tool")
if verify: if verify:
self.debugfile.write(verify, "getLoggingArgs: " + str(mlevel)+ ", "+self.format2Str(prio)+", "+self.format2Str(text)) self.debugfile.write("getLoggingArgs: " + str(mlevel)+ ", "+self.format2Str(prio)+", "+self.format2Str(text))
out = {} out = {}
prefix = "" prefix = ""
if isinstance(mlevel, int): if isinstance(mlevel, int):

69
basic/testkonzept.txt

@ -0,0 +1,69 @@
Durch den Test soll die Qualität der Anwendung systematisch (Testabdeckung) nachgewiesen
und (mittels Regressionen) langfristig sichergestellt werden.
Rollen - sind jetzt beschrieben, ok
Testobjekte
logischer Testfall
Testfall in Managementsicht, aus den User-Story-Akzeptanzkriterien abgeleitet
Diese werden auf allen Ebenen reportet, insb. deren Status.
physischer Testfall
Testfall in Spezifikations- und Ausführungssicht
konkreter auszuführender Testfall, die einzelnen Testschritte müssen spezifiziert/konfiguriert und protokolliert werden.
Arten physischer Testfälle:
* automatisierter Testfall
Alle Einzelschritte werden entsprechend des Automatisierungsframeworks im git-Repo spezifiziert. Entsprechend der Spezifikation wird der Testfall ausgeführt.
* manueller Testfall
Alle Einzelschritte werden detailliert (in Jira-..) spezifiziert. Entsprechend der Spezifikation wird der Testfall ausgeführt.
* explorativer Testfall
Die wesentlichen Schritt-Sequenzen werden detailliert (in Jira-..) spezifiziert. Von der Spezifikation kann und soll bei der Durchführung variiert werden. Die wesentlichen Schritte werden protokolliert.
Test im Software-Prozess
@pre: Komponenten-/Unittests durch Entwickler:innen
Q1: Lieferung entgegennehmen
* Entschlüsseln
* Programm: Artefakte verifizieren mittels md5-Hash
* Lieferung in git-Repo pushen
<< Exit wenn Lieferung nicht gelesen werden kann
Q2: Statischer Test
--> NFA Wartbarkeit
* Vollständigkeit prüfen >>> gitVerteiler
* Code-Analyse >>> SonarQube
<< Exit bei Fehlen wesentlicher Programme (auch Fehlbennung gelten als Fehlen!)
<< Warnung bei Unvollständigkeit
Q3: Installierbarkeit
--> NFA Installierbarkeit, Portierbarkeit
* Kubernetes-Container >>> JEE-Plattform?
* DB-Scripte auf Hive ausfuehren ?
* Cloudera-1-Rechner-Maschine >>> Linux-Maschine
* DevOps-Installation ** Testfälle hierzu beschreiben!
<< Exit bei Nicht-Installierbarkeit
Q4: System-/Smoketest
* Bedienelemente
* dynamischer Smoketest (minimale Testfälle, v.a. Gutfälle)
* minimaler GUI-Test >>>
<< Exit bei technischen Blockern
Q5: Regressions-/Progressionstest
--> Funktionaler Test, Sicherheitstest
* funktionale Regression (umfassende Testfälle, vollständige Äquivalenzklassen)
* erweiterte Testfälle zu neuen Funktionen
* Sichtbarkeit, Sperrkonstellationen >>>
<< Exit bei groben Fehlfunktionen
Q6: Nutzbarkeit
--> NFA Usability, Performance, Last
* manuelle Benutzbarkeit, edu@ETU
<< Exit wenn die Nutzung unbrauchbar ist
<< Warnungen

7
init_testsuite.py

@ -9,9 +9,10 @@ import basic.message
PROGRAM_NAME = "init_testset" PROGRAM_NAME = "init_testset"
def startPyJob(job): def startPyJob(job):
cm = basic.componentHandling.ComponentManager.getInstance(job) #cm = basic.componentHandling.ComponentManager.getInstance(job)
cm.initComponents() #cm.initComponents()
comps = cm.getComponents(PROGRAM_NAME) #comps = cm.getComponents(PROGRAM_NAME)
comps = []
job.m.setMsg("# Components initialized with these relevant components " + str(comps)) job.m.setMsg("# Components initialized with these relevant components " + str(comps))
#testdata = tdata_tool.getTestdata(job) #testdata = tdata_tool.getTestdata(job)

2
model/entity.py

@ -312,6 +312,8 @@ class Entity:
""" """
""" 2023-05 """ """ 2023-05 """
verify = False verify = False
if not job is None:
self.job = job
for k in fields + nodes: for k in fields + nodes:
key = tools.data_tool.getExistKeyword(k, config[rootname]) key = tools.data_tool.getExistKeyword(k, config[rootname])
if verify: print("setFields " + k + " / " + key) if verify: print("setFields " + k + " / " + key)

6
model/factory.py

@ -12,6 +12,8 @@ def get_entity_object(job, name, args):
entity = getDatatable(job) entity = getDatatable(job)
elif name in B.SUBJECT_USECASES: elif name in B.SUBJECT_USECASES:
entity = getUsecase(job) entity = getUsecase(job)
elif name in B.SUBJECT_PROJECTS:
entity = getApplication(job)
elif name in B.SUBJECT_APPS: elif name in B.SUBJECT_APPS:
entity = getApplication(job) entity = getApplication(job)
elif name in B.SUBJECT_COMPS: elif name in B.SUBJECT_COMPS:
@ -35,6 +37,10 @@ def getApplication(job=None, name=""):
import model.application import model.application
return model.application.Application() return model.application.Application()
def getProject(job=None, name=""):
import model.project
return model.project.Project(job)
def getComponent(job=None, name=""): def getComponent(job=None, name=""):
import model.component import model.component
return model.component.Component(job) return model.component.Component(job)

11
model/step.py

@ -17,12 +17,13 @@ TABLE_NAME = "step"
""" system-name for this entity """ """ system-name for this entity """
FIELD_ID = "spid" FIELD_ID = "spid"
FIELD_NAME = "name" FIELD_NAME = "name"
FIELD_VARIANT = B.SUBJECT_VARIANT FIELD_VARIANT = B.SUBJECT_VARIANT # variant
FIELD_SORTNR = "sortnr" FIELD_COMPONENT = B.SUBJECT_COMP # variant
FIELD_STEPNR = "stepnr" FIELD_SORTNR = "sortnr" # testcase
FIELD_DATAREF = "dataref" FIELD_STEPNR = "stepnr" # testcase
FIELD_DATAREF = "dataref" # testcase
FIELD_ATTRIBUTES = B.NODE_ATTRIBUTES FIELD_ATTRIBUTES = B.NODE_ATTRIBUTES
LIST_FIELDS = [FIELD_ID, FIELD_NAME, FIELD_VARIANT, FIELD_SORTNR, FIELD_STEPNR, FIELD_DATAREF] LIST_FIELDS = [FIELD_ID, FIELD_NAME, FIELD_VARIANT, FIELD_COMPONENT, FIELD_SORTNR, FIELD_STEPNR, FIELD_DATAREF]
""" list of object-attributes """ """ list of object-attributes """
LIST_NODES = [B.NODE_ATTRIBUTES, B.DATA_NODE_TOPICS] LIST_NODES = [B.NODE_ATTRIBUTES, B.DATA_NODE_TOPICS]
LIST_SUBTABLES = [] LIST_SUBTABLES = []

2
test/test_03path.py

@ -13,7 +13,7 @@ DATA_PATH = test.constants.DATA_PATH
OS_SYSTEM = test.constants.OS_SYSTEM OS_SYSTEM = test.constants.OS_SYSTEM
# here you can select single testfunction for developping the tests # here you can select single testfunction for developping the tests
TEST_FUNCTIONS = ["test_rejoinPath", "test_rejoinPath", "test_extractPattern"] TEST_FUNCTIONS = ["test_rejoinPath", "test_extractPattern"]
#TEST_FUNCTIONS = ["test_key", "test_extractPath", "test_composePath"] #TEST_FUNCTIONS = ["test_key", "test_extractPath", "test_composePath"]
verbose = True verbose = True

8
test/test_11message.py

@ -12,7 +12,7 @@ import basic.message
HOME_PATH = test.constants.HOME_PATH HOME_PATH = test.constants.HOME_PATH
PYTHON_CMD = "python" PYTHON_CMD = "python"
TEST_FUNCTIONS = ["test_00init", "test_04logLevel", "test_05loginigArgs", "test_10set", "test_11log", "test_20close"] TEST_FUNCTIONS = ["test_00init", "test_04logLevel", "test_05loginigArgs", "test_10set", "test_11log", "test_20close"]
TEST_FUNCTIONS = ["test_00init", "test_05loginigArgs"] #TEST_FUNCTIONS = ["test_00init", "test_05loginigArgs"]
PROGRAM_NAME = "clean_workspace" PROGRAM_NAME = "clean_workspace"
NOT_TO_LOG = ["xx1xx", "xx4xx"] NOT_TO_LOG = ["xx1xx", "xx4xx"]
@ -146,12 +146,12 @@ class MyTestCase(unittest.TestCase):
self.assertEqual(True, msgObject.isRc(basic.message.RC_MSG)) self.assertEqual(True, msgObject.isRc(basic.message.RC_MSG))
self.assertEqual(True, msgObject.isRc(basic.message.MTEXT_MSG)) self.assertEqual(True, msgObject.isRc(basic.message.MTEXT_MSG))
self.assertEqual(True, msgObject.isRc(basic.message.MTEXT_INFO)) self.assertEqual(True, msgObject.isRc(basic.message.MTEXT_INFO))
self.assertEqual(True, msgObject.isRc(basic.message.RC_WARN)) self.assertEqual(False, msgObject.isRc(basic.message.RC_WARN))
self.assertEqual(True, msgObject.isRc(basic.message.MTEXT_WARN)) self.assertEqual(False, msgObject.isRc(basic.message.MTEXT_WARN))
msgObject.setWarn("yy2yy warn-msg") msgObject.setWarn("yy2yy warn-msg")
self.assertEqual(basic.message.RC_WARN, msgObject.getFinalRc()) self.assertEqual(basic.message.RC_WARN, msgObject.getFinalRc())
self.assertEqual("WARN: yy2yy warn-msg", msgObject.topmessage) self.assertEqual("WARN: yy2yy warn-msg", msgObject.topmessage)
self.assertEqual(False, msgObject.isRc(basic.message.RC_MSG)) self.assertEqual(True, msgObject.isRc(basic.message.RC_MSG))
msgObject.setError("yy3yy error-msg") msgObject.setError("yy3yy error-msg")
self.assertEqual(basic.message.RC_ERROR, msgObject.getFinalRc()) self.assertEqual(basic.message.RC_ERROR, msgObject.getFinalRc())
self.assertEqual("ERROR: yy3yy error-msg", msgObject.topmessage) self.assertEqual("ERROR: yy3yy error-msg", msgObject.topmessage)

3
test/test_14entity.py

@ -79,10 +79,11 @@ class MyTestCase(unittest.TestCase):
elif k == model.testcase.FIELD_PROJECT: elif k == model.testcase.FIELD_PROJECT:
self.assertEqual(tcproject, getattr(testcase, k)) self.assertEqual(tcproject, getattr(testcase, k))
else: else:
self.assertEqual("", getattr(testcase, k)) 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.LIST_NODES:
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)
for k in B.LIST_TOPIC_NODES: for k in B.LIST_TOPIC_NODES:

2
test/test_15user.py

@ -112,7 +112,7 @@ class MyTestCase(unittest.TestCase):
user.name = "Hans" user.name = "Hans"
user.famname = "im Glueck" user.famname = "im Glueck"
user.project = "TESTPROJ" user.project = "TESTPROJ"
#user.insert_entity(job, username, table="user") user.insert_entity(job, username, table="user")
entityNames = collectInnerList(user.get_unique_names(job, storage=model.entity.STORAGE_DB)) entityNames = collectInnerList(user.get_unique_names(job, storage=model.entity.STORAGE_DB))
self.assertIn(username, entityNames) self.assertIn(username, entityNames)
actUser = user.select_entity(job, username) actUser = user.select_entity(job, username)

2
test/test_20application.py

@ -47,7 +47,7 @@ class MyTestCase(unittest.TestCase):
job = test.testtools.getJob() job = test.testtools.getJob()
application = model.application.Application() application = model.application.Application()
entityNames = application.get_entities(job, storage=model.entity.STORAGE_FILE) entityNames = application.get_entities(job, storage=model.entity.STORAGE_FILE)
self.assertEqual(type(entityNames), dict) self.assertEqual(type(entityNames), list)
#entityNames = environment.get_entities(job, storage=model.entity.STORAGE_DB) #entityNames = environment.get_entities(job, storage=model.entity.STORAGE_DB)
#self.assertEqual(type(entityNames), list) #self.assertEqual(type(entityNames), list)

27
test/test_28step.py

@ -10,10 +10,11 @@ import basic.constants as B
import test.constants as T import test.constants as T
import tools.file_tool import tools.file_tool
import model.step import model.step
import model.testcase
HOME_PATH = test.constants.HOME_PATH HOME_PATH = test.constants.HOME_PATH
PYTHON_CMD = "python" PYTHON_CMD = "python"
TEST_FUNCTIONS = ["test_10getEntityNames", "test_12getEntity", "test_20getStep"] # TEST_FUNCTIONS = ["test_10getEntityNames", "test_12getEntity", "test_02setEntity", "test_20getStep"]
TEST_FUNCTIONS = ["test_12getEntity"] TEST_FUNCTIONS = ["test_12getEntity"]
PROGRAM_NAME = "clean_workspace" PROGRAM_NAME = "clean_workspace"
@ -22,6 +23,21 @@ PROJECT = "TESTPROJ"
class MyTestCase(unittest.TestCase): class MyTestCase(unittest.TestCase):
mymsg = "--------------------------------------------------------------" mymsg = "--------------------------------------------------------------"
def test_02setEntity(self):
global mymsg
global jobObject
actfunction = str(inspect.currentframe().f_code.co_name)
cnttest = 0
if actfunction not in TEST_FUNCTIONS:
return
job = test.testtools.getJob()
step = model.step.Step(job)
name = "xml-rest"
actproject = step.read_entity(job, name)
self.assertEqual(getattr(actproject, model.step.FIELD_NAME), name)
self.assertRaises(Exception, step.read_entity, job, "xyzxyz")
def test_10getEntityNames(self): def test_10getEntityNames(self):
global mymsg global mymsg
global jobObject global jobObject
@ -48,10 +64,15 @@ class MyTestCase(unittest.TestCase):
job = test.testtools.getJob() job = test.testtools.getJob()
step = model.step.Step(job) step = model.step.Step(job)
name = "xml-rest" name = "xml-rest"
actproject = step.read_entity(job, name) actstep = step.read_entity(job, name)
self.assertEqual(getattr(actproject, model.step.FIELD_NAME), name) self.assertEqual(getattr(actstep, model.step.FIELD_NAME), name)
self.assertRaises(Exception, step.read_entity, job, "xyzxyz") self.assertRaises(Exception, step.read_entity, job, "xyzxyz")
# #
testcase = model.testcase.Testcase(job, "TESTPROJ")
tcname = "TC0001"
acttestcase = testcase.read_entity(job, tcname)
print(str(acttestcase.steps))
#actproject = actproject.setAttributes(job, )
#actproject = component.select_entity(job, name) #actproject = component.select_entity(job, name)
#self.assertEqual(getattr(actproject, model.component.FIELD_USERNAME), name) #self.assertEqual(getattr(actproject, model.component.FIELD_USERNAME), name)
#self.assertRaises(Exception, component.select_entity, job, ["xyzxyz"]) #self.assertRaises(Exception, component.select_entity, job, ["xyzxyz"])

10
test/test_90testserver.py

@ -56,7 +56,7 @@ class MyTestCase(unittest.TestCase):
dbi = basic.toolHandling.getDbTool(job, self, "rel") dbi = basic.toolHandling.getDbTool(job, self, "rel")
# return "No DB in job-config" # return "No DB in job-config"
t = "application" t = "application"
sql = testserver.tables[t].get_schema(tableName=t, tableObject=testserver.tables[t]) sql = testserver.model[t].get_schema(tableName=t, tableObject=testserver.model[t])
#sql = testserver.getDBSchema(job, dbi, "application") #sql = testserver.getDBSchema(job, dbi, "application")
print(sql+"##") print(sql+"##")
lines = sql.split("\n") lines = sql.split("\n")
@ -64,7 +64,7 @@ class MyTestCase(unittest.TestCase):
self.assertIn("CREATE TABLE", lines[0]) self.assertIn("CREATE TABLE", lines[0])
self.assertIn("CREATE INDEX", lines[1]) self.assertIn("CREATE INDEX", lines[1])
t = "ap_project" t = "ap_project"
sql = testserver.tables[t].get_schema(tableName=t, tableObject=testserver.tables[t]) sql = testserver.model[t].get_schema(tableName=t, tableObject=testserver.model[t])
# sql = testserver.getDBSchema(job, dbi, "ap_project") # sql = testserver.getDBSchema(job, dbi, "ap_project")
print(sql+"##") print(sql+"##")
lines = sql.split("\n") lines = sql.split("\n")
@ -72,7 +72,7 @@ class MyTestCase(unittest.TestCase):
self.assertIn("CREATE TABLE", lines[0]) self.assertIn("CREATE TABLE", lines[0])
self.assertIn("CREATE INDEX", lines[1]) self.assertIn("CREATE INDEX", lines[1])
t = "ap_component" t = "ap_component"
sql = testserver.tables[t].get_schema(tableName=t, tableObject=testserver.tables[t]) sql = testserver.model[t].get_schema(tableName=t, tableObject=testserver.model[t])
#sql = testserver.getDBSchema(job, dbi, "ap_component") #sql = testserver.getDBSchema(job, dbi, "ap_component")
print(sql+"##") print(sql+"##")
lines = sql.split("\n") lines = sql.split("\n")
@ -94,8 +94,8 @@ class MyTestCase(unittest.TestCase):
job.conf[B.TOPIC_NODE_DB][B.ATTR_DB_DATABASE] = B.ATTR_INST_TESTSERVER job.conf[B.TOPIC_NODE_DB][B.ATTR_DB_DATABASE] = B.ATTR_INST_TESTSERVER
self.job = job self.job = job
testserver = basic.Testserver.Testserver(job) testserver = basic.Testserver.Testserver(job)
for t in testserver.tables: for t in testserver.model:
sql = testserver.tables[t].get_schema(tableName=t, tableObject=testserver.tables[t]) sql = testserver.model[t].get_schema(tableName=t, tableObject=testserver.model[t])
print(sql) print(sql)
#testserver.createDBTables(job) #testserver.createDBTables(job)

Loading…
Cancel
Save