Пример #1
0
    def __init__(self, app):
        """
        Create an application context object,

        :param app: Flask application instance.
        """
        self.config = ConfigClient()
        self.cache = CacheClient(
            addr=self.config.get_value('redis.addr'),
            prefix='orion',
        )
        self.db = DbClient(
            app,
            user=self.config.get_value('database.user'),
            password=self.config.get_value('database.password'),
            host=self.config.get_value('database.host'),
            port=self.config.get_value('database.port'),
            name=self.config.get_value('database.name'),
        )
        self.geocode = ReverseGeocodingClient(
            mapbox_access_token=self.config.get_value('mapbox_access_token'),
        )
        self.metrics_event = EventMetricsClient(
            addr=self.config.get_value('statsd.addr'),
            prefix='orion',
        )
        self.metrics_latency = LatencyMetricsClient(
            addr=self.config.get_value('statsd.addr'),
            prefix='orion',
        )
        self.stream = StreamClient(
            kafka_addr=self.config.get_value('kafka.addr'),
            kafka_topic=self.config.get_value('kafka.topic'),
        )
Пример #2
0
class TestCacheClient(TestCase):
    @mock.patch.object(cache, 'MemoryTTLCache')
    @mock.patch.object(cache, 'RedisProxyClient')
    def setUp(self, *args):
        self.redis_client = CacheClient('localhost:6379', 'prefix')
        self.memory_client = CacheClient(None, 'prefix')

    def test_rw_client(self):
        rw_client = self.redis_client.rw_client('namespace', 'key')

        rw_client.get()
        self.redis_client.backend.get.assert_called_with(
            key='prefix:namespace:key:')

        rw_client.set('value', 1000)
        self.redis_client.backend.set.assert_called_with(
            key='prefix:namespace:key:',
            value='value',
            ttl=1000,
        )

        rw_client.delete()
        self.redis_client.backend.delete.assert_called_with(
            key='prefix:namespace:key:')

    def test_format_key_valid(self):
        self.assertEqual(
            self.redis_client._format_key('namespace', 'key', {
                'a': 'b',
                'c': 4
            }),
            'prefix:namespace:key:a=b&c=4',
        )

    def test_format_key_invalid(self):
        self.assertRaises(
            CacheException,
            self.redis_client._format_key,
            namespace='namespace',
            key='key',
            tags={'a': '='},
        )
Пример #3
0
 def setUp(self):
     self.mock_app = flask.Flask(__name__)
     self.mock_ctx = mock.MagicMock()
     self.mock_ctx.cache = CacheClient(addr=None, prefix='prefix')
Пример #4
0
 def setUp(self, *args):
     self.redis_client = CacheClient('localhost:6379', 'prefix')
     self.memory_client = CacheClient(None, 'prefix')