Browse Source

additional arg subkey

refactor
Ulrich 2 years ago
parent
commit
a66f1b068a
  1. 13
      objects/catalog.py
  2. 9
      test/test_07catalog.py
  3. 0
      test/test_08value.py

13
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

9
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)

0
test/test_08value.py

Loading…
Cancel
Save