mirror of
https://github.com/projecthorus/sondehub-infra.git
synced 2024-12-20 05:37:56 +00:00
add LRU cache
This commit is contained in:
parent
ce95ff37ad
commit
86029b5347
@ -1,7 +1,9 @@
|
|||||||
import os
|
import os
|
||||||
import boto3
|
import boto3
|
||||||
import json
|
import json
|
||||||
|
import functools
|
||||||
|
|
||||||
|
@functools.lru_cache()
|
||||||
def get(topic: str, parameter: str, default=None) -> str:
|
def get(topic: str, parameter: str, default=None) -> str:
|
||||||
"""
|
"""
|
||||||
Get's a configuration parameter.
|
Get's a configuration parameter.
|
||||||
|
@ -19,6 +19,9 @@ secret_call = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class TestConfigHandler(unittest.TestCase):
|
class TestConfigHandler(unittest.TestCase):
|
||||||
|
def setUp(self) -> None:
|
||||||
|
config_handler.get.cache_clear()
|
||||||
|
|
||||||
def test_env(self):
|
def test_env(self):
|
||||||
with patch.dict(config_handler.os.environ,{ "MQTT_PASSWORD": "test_password" }, clear=True):
|
with patch.dict(config_handler.os.environ,{ "MQTT_PASSWORD": "test_password" }, clear=True):
|
||||||
return_value = config_handler.get("MQTT", "PASSWORD")
|
return_value = config_handler.get("MQTT", "PASSWORD")
|
||||||
@ -31,6 +34,14 @@ class TestConfigHandler(unittest.TestCase):
|
|||||||
MockApiCall.assert_called()
|
MockApiCall.assert_called()
|
||||||
self.assertEqual(return_value, "test_password")
|
self.assertEqual(return_value, "test_password")
|
||||||
|
|
||||||
|
@patch('botocore.client.BaseClient._make_api_call', return_value=secret_call)
|
||||||
|
def test_cache(self, MockApiCall):
|
||||||
|
with patch.dict(config_handler.os.environ,{}, clear=True): #ensure that local env variables don't influence the tests
|
||||||
|
return_value = config_handler.get("MQTT", "PASSWORD")
|
||||||
|
return_value = config_handler.get("MQTT", "PASSWORD")
|
||||||
|
MockApiCall.assert_called_once()
|
||||||
|
self.assertEqual(return_value, "test_password")
|
||||||
|
|
||||||
@patch('botocore.client.BaseClient._make_api_call', return_value=secret_call)
|
@patch('botocore.client.BaseClient._make_api_call', return_value=secret_call)
|
||||||
def test_not_found(self, MockApiCall):
|
def test_not_found(self, MockApiCall):
|
||||||
with patch.dict(config_handler.os.environ,{}, clear=True):
|
with patch.dict(config_handler.os.environ,{}, clear=True):
|
||||||
|
Loading…
Reference in New Issue
Block a user