Пример #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
    def test_partial_required_in_env(self):
        os.environ.update({
            'DATABASE_HOST': 'env_localhost',
            'DATABASE_PASSWORD': '******',
        })

        instance = ConfigClient()

        self.assertEqual(instance.get_value('database.host'), 'env_localhost')
        self.assertEqual(instance.get_value('database.port'), 3306)
        self.assertEqual(instance.get_value('database.name'), 'orion')
        self.assertEqual(instance.get_value('database.user'), 'orion')
        self.assertEqual(instance.get_value('database.password'),
                         'env_password')
Пример #3
0
class Context(object):
    """
    Global application context containing all necessary clients.
    """

    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.stream = StreamClient(
            kafka_addr=self.config.get_value('kafka.addr'),
            kafka_topic=self.config.get_value('kafka.topic'),
        )
Пример #4
0
    def test_get_value_unrecognized_param(self):
        instance = ConfigClient()

        self.assertRaises(
            ValueError,
            instance.get_value,
            key='unknown',
        )
Пример #5
0
    def __init__(self, app):
        """
        Create an application context object,

        :param app: Flask application instance.
        """
        self.config = ConfigClient()
        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(
            google_api_key=self.config.get_value('google_api_key'), )
Пример #6
0
    def test_all_required_in_env(self, mock_open):
        os.environ.update({
            'DATABASE_HOST': 'env_localhost',
            'DATABASE_PORT': '3306',
            'DATABASE_NAME': 'env_orion',
            'DATABASE_USER': '******',
            'DATABASE_PASSWORD': '******',
        })

        instance = ConfigClient()

        self.assertFalse(mock_open.called)
        self.assertEqual(instance.get_value('database.host'), 'env_localhost')
        self.assertEqual(instance.get_value('database.port'), 3306)
        self.assertEqual(instance.get_value('database.name'), 'env_orion')
        self.assertEqual(instance.get_value('database.user'), 'env_orion')
        self.assertEqual(instance.get_value('database.password'),
                         'env_password')
        self.assertEqual(instance.get_value('frontend_url'), '*')
Пример #7
0
    def test_get_value_default(self):
        instance = ConfigClient()

        self.assertEqual(instance.get_value('frontend_url'), '*')
        self.assertIsNone(instance.get_value('sentry_dsn'))
Пример #8
0
    def test_get_value_optional_param(self):
        instance = ConfigClient()

        self.assertEqual(instance.get_value('frontend_url'), 'url')
        self.assertEqual(instance.get_value('kafka.addr'), 'localhost:9092')
        self.assertEqual(instance.get_value('kafka.topic'), 'topic')
Пример #9
0
    def test_get_value_optional_param(self):
        instance = ConfigClient()

        self.assertEqual(instance.get_value('frontend_url'), 'url')