diff --git a/model/testcase.py b/model/testcase.py index 0c51e6d..7a0d851 100644 --- a/model/testcase.py +++ b/model/testcase.py @@ -121,6 +121,7 @@ class Testcase(model.entity.Entity): # r = tools.config_tool.select_config_path(job, P.KEY_TESTCASE, "TC0001") config = self.getConfig(job, P.KEY_TESTCASE, name, tools.config_tool.get_plain_filename(job, name)) self.setAttributes(config, name, LIST_FIELDS, LIST_SUBTABLES) + """ for k in LIST_SUBTABLES.keys(): if not hasattr(self, k): continue @@ -137,6 +138,7 @@ class Testcase(model.entity.Entity): for l in config[name]["_"+k]: values[config[name]["_" + k][l]] = "" setattr(self, k, values) + """ return self def xxread_entity(self, job, name): diff --git a/test/test_10job.py b/test/test_10job.py index 9156c0b..87b5b67 100644 --- a/test/test_10job.py +++ b/test/test_10job.py @@ -2,15 +2,10 @@ import unittest import os import inspect import shutil -print("start import 1") #import model.entity -print("start import 2") #import model.environment -print("start import 3") #import model.application -print("start import 4") #import model.component -print("start import 5") import model.testcase import model.testsuite import model.factory @@ -28,9 +23,9 @@ HOME_PATH = test.constants.HOME_PATH PYTHON_CMD = "python" TEST_FUNCTIONS = ["test_00init", "test_11selectApplication", "test_12selectComponent", "test_13selectEnvironment", - "test_16selectTestcase", + "test_14selectVariant", "test_16selectTestcase", "test_30startActJob"] -TEST_FUNCTIONS = ["test_16selectTestcase"] +TEST_FUNCTIONS = ["test_14selectVariant"] PROGRAM_NAME = "clean_workspace" @@ -110,6 +105,29 @@ class MyTestCase(unittest.TestCase): self.assertIsInstance(res, list) print(str(res)) + def test_14selectVariant(self): + global mymsg + 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 = basic.program.Job(PROGRAM_NAME) + args = {'proc': 'Testfall ausfuehren', 'gran': 'Testfall', 'user': 'ulrich', + 'project': 'TESTPROJ', 'step': '1', 'program': 'test_executer', + 'application': 'TESTAPP', 'environment': 'ENV01', 'testcase': 'TC0002'} + res = tools.job_tool.select_variant(job, "", "Testfall", args) + print(str(res)) + self.assertEqual(len(res), 1) + self.assertEqual("defaultVariant", res[0]) + args = {'proc': 'Testfall ausfuehren', 'gran': 'Testfall', 'user': 'ulrich', + 'project': 'TESTPROJ', 'step': '1', 'program': 'test_executer', + 'application': 'TESTAPP', 'environment': 'ENV01', 'testcase': 'TC0001'} + res = tools.job_tool.select_variant(job, "", "Testfall", args) + print(str(res)) + self.assertEqual(len(res), 2) + self.assertEqual("xml-rest", res[0]) + def test_14selectTestplan(self): global mymsg actfunction = str(inspect.currentframe().f_code.co_name) diff --git a/tools/filecsv_fcts.py b/tools/filecsv_fcts.py index 598a430..eac8139 100644 --- a/tools/filecsv_fcts.py +++ b/tools/filecsv_fcts.py @@ -53,15 +53,16 @@ class FileFcts(tools.file_abstract.FileFcts): :param status: :return: """ + verify = False try: - print("isBlock "+field + " , " + block + " , " + status) + if verify: print("isBlock "+field + " , " + block + " , " + status) blockPur = tools.data_tool.getPurKeyword(block) a = field.split(":") keyPur = tools.data_tool.getPurKeyword(a[0]) statusPur = tools.data_tool.getPurKeyword(status) if statusPur+"s-" in keyPur: keyPur = keyPur[keyPur.find("-")+1:] - print("isBlock "+a[0] + "=" + keyPur +" , " + blockPur + " , " + status) + if verify: print("isBlock "+a[0] + "=" + keyPur +" , " + blockPur + " , " + status) if (keyPur+"s" in D.LIST_SUBTABLES or keyPur in D.LIST_SUBTABLES) \ and block == D.CSV_BLOCK_SUBTABLES: return True @@ -386,21 +387,28 @@ def setSubTable(job, subtable, key, val): # descriptiom => attribute of actual subtable key = key.lower() subkey = "" + newSubtable = False print("setSubtable "+key+", "+str(val)) if "actTable" in subtable and subtable["actTable"]+"-" in key: subkey = key[key.find("-")+1:] if subkey == "" and key not in subtable: + newSubtable = True subtable[key] = {} subtable["actTable"] = key actTable = subtable["actTable"] + purKey = tools.data_tool.getPurKeyword(key) + print("setSubtable "+key+" =? "+actTable+ " + "+ purKey +" , "+str(val)) + actKeys = list(subtable[actTable].keys()) for i in range(1, len(val)): - if val[i] not in subtable[key]: + if newSubtable and val[i] not in subtable[key]: if val[i] == "": break - subtable[key][val[i]] = {} - subtable[key][val[i]]["name"] = val[i] + subtable[actTable][val[i]] = {} + subtable[actTable][val[i]]["name"] = val[i] else: - subtable[key][val[i]][key] = val[i] + if i >= len(actKeys): + break + subtable[actTable][actKeys[i]][purKey] = val[i] return subtable def setTableAttribute(job, tableAttr, key, val): diff --git a/tools/job_tool.py b/tools/job_tool.py index fed570e..def9500 100644 --- a/tools/job_tool.py +++ b/tools/job_tool.py @@ -264,26 +264,35 @@ def select_variant(job, programDef, gran, args): read the testobjects of the granularity,project and select one of them with the time :return: """ + outVariants = [] print("select spec "+gran) if gran == J.GRAN_TP.lower(): + setParameterArgs(job, args, [B.PAR_PROJ]) print("select tp spec " + gran) return [""] elif gran in [B.PAR_TESTSUITE, J.GRAN_TS]: + setParameterArgs(job, args, [B.PAR_PROJ]) print("select ts spec " + gran) out = model.testsuite.select_testsuite(job, args[B.PAR_PROJ], args[B.PAR_TESTSUITE]) if "variant" not in out: return [""] return list(out["variant"].keys()) elif gran in [B.PAR_TESTCASE, J.GRAN_TC]: + setParameterArgs(job, args, [B.PAR_PROJ]) print("select tc spec " + gran + " " + str(args)) - out = model.factory.getTestcase(job, args[B.PAR_PROJ]).read_entity(job, args[B.PAR_TESTCASE]) - print(str(out)) - if "variant" not in out: - return [""] - return list(out["variant"].keys()) + testcase = model.factory.getTestcase(job, args[B.PAR_PROJ]).read_entity(job, args[B.PAR_TESTCASE]) + print(str(testcase)) + #if "variant" not in testcase: + # return [""] + if hasattr(testcase, B.SUBJECT_VARIANTS): + outVariants = list(getattr(testcase, B.SUBJECT_VARIANTS).keys()) + #return list(testcase[B.SUBJECT_VARIANTS].keys()) else: raise Exception("for gran "+gran+" variant can not be selected") + if len(outVariants) == 0: + outVariants.append("defaultVariant") print("select no spec "+gran) + return outVariants def select_testplan(job, programDef, args): outList = [] @@ -298,4 +307,14 @@ def select_testcase(job, programDef, args): print("testcase args "+str(args)) # outList = model.testcase.select_testcases(job, [args[B.PAR_PROJ]], [args[B.PAR_APP]]) outList = model.factory.getTestcase(job, args[B.PAR_PROJ]).get_unique_names(job, project=args[B.PAR_PROJ], application=args[B.PAR_APP]) - return outList \ No newline at end of file + return outList + +def setParameterArgs(job, args, parameter): + if not hasattr(job, "par"): + job.setParameter({}) + # setattr(job, "par", object) + for p in parameter: + if hasattr(job.par, p): + continue + if p in args: + setattr(job.par, p, args[p]) \ No newline at end of file