mirror of
https://github.com/projecthorus/sondehub-infra.git
synced 2024-12-18 20:57:56 +00:00
add LRU cache
This commit is contained in:
parent
ce95ff37ad
commit
86029b5347
@ -1,7 +1,9 @@
|
||||
import os
|
||||
import boto3
|
||||
import json
|
||||
import functools
|
||||
|
||||
@functools.lru_cache()
|
||||
def get(topic: str, parameter: str, default=None) -> str:
|
||||
"""
|
||||
Get's a configuration parameter.
|
||||
|
@ -19,6 +19,9 @@ secret_call = {
|
||||
}
|
||||
|
||||
class TestConfigHandler(unittest.TestCase):
|
||||
def setUp(self) -> None:
|
||||
config_handler.get.cache_clear()
|
||||
|
||||
def test_env(self):
|
||||
with patch.dict(config_handler.os.environ,{ "MQTT_PASSWORD": "test_password" }, clear=True):
|
||||
return_value = config_handler.get("MQTT", "PASSWORD")
|
||||
@ -30,6 +33,14 @@ class TestConfigHandler(unittest.TestCase):
|
||||
return_value = config_handler.get("MQTT", "PASSWORD")
|
||||
MockApiCall.assert_called()
|
||||
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)
|
||||
def test_not_found(self, MockApiCall):
|
||||
|
Loading…
Reference in New Issue
Block a user