From e61b732e4423c7f2ef4e266957541d5cfe37879d Mon Sep 17 00:00:00 2001 From: Tor-Einar Skog <tor-einar.skog@nibio.no> Date: Wed, 22 Feb 2023 16:36:42 +0100 Subject: [PATCH] added namespace to get/set value of Result class --- src/vipscore_common/entities.py | 8 ++++---- tests/test_entities.py | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/vipscore_common/entities.py b/src/vipscore_common/entities.py index 562d7de..70b14ed 100755 --- a/src/vipscore_common/entities.py +++ b/src/vipscore_common/entities.py @@ -73,14 +73,14 @@ class Result(BaseModel): if v is not None and not isinstance(v, Point) and not isinstance(v, Polygon): raise ValueError("%s is not a " % v) - def set_value(self, key, value): + def set_value(self, namespace, key, value): temp_all_values = json.loads(self.all_values) - temp_all_values[key] = value + temp_all_values["%s.%s" %(namespace, key)] = value self.all_values = json.dumps(temp_all_values) - def get_value(self, key): + def get_value(self, namespace, key): temp_all_values = json.loads(self.all_values) - return temp_all_values.get(key) + return temp_all_values.get("%s.%s" %(namespace, key)) def set_all_values(self, values_dict): self.all_values = json.dumps(values_dict) diff --git a/tests/test_entities.py b/tests/test_entities.py index 5975b42..8ad7a94 100644 --- a/tests/test_entities.py +++ b/tests/test_entities.py @@ -11,7 +11,7 @@ class TestEntities(unittest.TestCase): valid_time_start = datetime.fromisoformat("2015-03-01T00:00:00+01:00"), # valid_time_start valid_time_end = None, warning_status = 2, - all_values = json.dumps({"TM":2}) + all_values = json.dumps({"WEATHER.TM":2}) ) r = Result( @@ -20,7 +20,7 @@ class TestEntities(unittest.TestCase): warning_status = 2 ) - r.set_value("TM",2) + r.set_value("WEATHER","TM",2) def test_weather_elements(self): self.assertEquals("TM",WeatherElements.TEMPERATURE_MEAN) \ No newline at end of file -- GitLab