diff --git a/objects/catalog.py b/objects/catalog.py index ca69318..26cb62b 100644 --- a/objects/catalog.py +++ b/objects/catalog.py @@ -39,7 +39,7 @@ class Catalog: return Catalog.__instance - def getValue(self, domain, key, job): + def getValue(self, job, domain, key, subkey=""): """ this function gets the value of the domain an key :param domain: @@ -57,6 +57,11 @@ class Catalog: if key not in self.catalog[domain]: job.m.setError(EXP_KEY_DOESNT_EXIST+" ("+domain+", "+key+")") return "" + if len(subkey) > 0: + if subkey not in self.catalog[domain][key]: + job.m.setError(EXP_KEY_DOESNT_EXIST + " (" + domain + ", " + key + ", " + subkey + ")") + return "" + return self.catalog[domain][key][subkey] return self.catalog[domain][key] @@ -93,7 +98,11 @@ class Catalog: pathname = tools.config_tool.getConfigPath(job, P.KEY_CATALOG, domain) if pathname is None: raise Exception(EXP_KEY_MISSING, (domain)) - data = tools.file_tool.readFileDict(job, pathname, job.m) + if hasattr(job, "m"): + msg = job.m + else: + msg = None + data = tools.file_tool.readFileDict(job, pathname, msg) self.catalog[domain] = data[B.DATA_NODE_TABLES][domain][B.DATA_NODE_KEYS] return data diff --git a/test/test_07catalog.py b/test/test_07catalog.py index f082c77..ef7db71 100644 --- a/test/test_07catalog.py +++ b/test/test_07catalog.py @@ -68,16 +68,19 @@ class MyTestCase(unittest.TestCase): return job = test.testtools.getJob() catalog = objects.catalog.Catalog.getInstance() - res = catalog.getValue("countries", "key", job) + res = catalog.getValue(job, "countries", "key", "") self.assertEqual(res, "") self.assertEqual(job.m.rc, basic.message.RC_ERROR) cnttest += 1 - res = catalog.getValue("countries", "TD", job) + res = catalog.getValue(job, "countries", "TD", "") print(str(res)) self.assertEqual(res["Land"], "Tschad") + cnttest += 1 + res = catalog.getValue(job, "countries", "TD", "Land") print(str(res)) + self.assertEqual(res, "Tschad") cnttest += 1 - res = catalog.getValue("sender", "firma", job) + res = catalog.getValue(job, "sender", "firma", "") print(str(res)) MyTestCase.mymsg += "\n----- "+actfunction+" : "+str(cnttest) diff --git a/test/test_08value.py b/test/test_08value.py new file mode 100644 index 0000000..e69de29