def setUp(self):
     plpy_mock_config()
     cartodb_services.init(plpy_mock, _GD={})
     self.username = '******'
     self.orgname = 'test_org'
     self.redis_conn = MockRedis()
     build_redis_user_config(self.redis_conn, self.username, 'geocoding')
     build_redis_org_config(self.redis_conn,
                            self.orgname,
                            'geocoding',
                            provider='mapzen')
     self.environment = 'production'
     plpy_mock._define_result("CDB_Conf_GetConf\('server_conf'\)",
                              [{
                                  'conf': '{"environment": "production"}'
                              }])
     plpy_mock._define_result(
         "CDB_Conf_GetConf\('redis_metadata_config'\)",
         [{
             'conf': '{"redis_host":"localhost","redis_port":"6379"}'
         }])
     plpy_mock._define_result(
         "CDB_Conf_GetConf\('redis_metrics_config'\)",
         [{
             'conf': '{"redis_host":"localhost","redis_port":"6379"}'
         }])
     basic_server_conf = {
         "server_conf": {
             "environment": "testing"
         },
         "mapzen_conf": {
             "geocoder": {
                 "api_key": "search-xxxxxxx",
                 "monthly_quota": 1500000,
                 "service": {
                     "base_url": "http://base"
                 }
             }
         },
         "logger_conf": {}
     }
     self.empty_server_config = InMemoryConfigStorage(basic_server_conf)
     self.empty_redis_config = InMemoryConfigStorage({})
     self.user_config = RedisUserConfigStorageBuilder(
         self.redis_conn, self.username).get()
     self.org_config = RedisOrgConfigStorageBuilder(self.redis_conn,
                                                    self.orgname).get()
     self.server_config = ServerConfigBackendFactory().get()
 def test_returns_env_according_to_configuration(self):
     server_config_storage = InMemoryConfigStorage({
         'server_conf': {
             'environment': 'staging'
         }
     })
     server_env = ServerEnvironmentBuilder(server_config_storage).get()
     assert server_env.is_staging == True
Beispiel #3
0
 def test_it_sets_absent_values_to_none_or_defaults(self):
     server_config_storage = InMemoryConfigStorage({
         'redis_metrics_config': {
             'redis_host': 'myhost.com',
             'redis_port': 6379,
         }
     })
     config = RedisMetricsConnectionConfigBuilder(server_config_storage).get()
     assert config.host == 'myhost.com'
     assert config.port == 6379
     assert config.timeout == 1.5
     assert config.db == 5
     assert config.sentinel_id is None
Beispiel #4
0
 def test_it_gets_a_valid_config_from_the_server_storage(self):
     server_config_storage = InMemoryConfigStorage({
         'redis_metrics_config': {
             'redis_host': 'myhost.com',
             'redis_port': 6379,
             'timeout': 0.2,
             'redis_db': 3,
             'sentinel_master_id': 'some_master_id'
         }
     })
     config = RedisMetricsConnectionConfigBuilder(server_config_storage).get()
     assert config.host == 'myhost.com'
     assert config.port == 6379
     assert config.timeout == 0.2
     assert config.db == 3
     assert config.sentinel_id == 'some_master_id'
Beispiel #5
0
 def test_it_gets_a_default_db_if_none(self):
     server_config_storage = InMemoryConfigStorage({
         'redis_metadata_config': {
             'redis_host': 'myhost.com',
             'redis_port': 6379,
             'timeout': 0.2,
             'redis_db': None,
             'sentinel_master_id': None
         }
     })
     config = RedisMetadataConnectionConfigBuilder(server_config_storage).get()
     assert config.host == 'myhost.com'
     assert config.port == 6379
     assert config.timeout == 0.2
     assert config.db == RedisConnectionConfigBuilder.DEFAULT_USER_DB
     assert config.sentinel_id is None
 def setUp(self):
     self._redis_connection = MockRedis()
     self._server_config = InMemoryConfigStorage({
         "server_conf": {
             "environment": "testing"
         },
         "mapzen_conf": {
             "geocoder": {
                 "api_key": "search-xxxxxxx",
                 "monthly_quota": 1500000
             }
         },
         "logger_conf": {}
     })
     self._username = '******'
     self._user_key = "rails:users:{0}".format(self._username)
     self._user_config = RedisUserConfigStorageBuilder(
         self._redis_connection, self._username).get()
     self._org_config = RedisOrgConfigStorageBuilder(
         self._redis_connection, None).get()
     self._set_default_config_values()
Beispiel #7
0
 def test_gets_none_if_cannot_retrieve_key(self):
     server_config = InMemoryConfigStorage()
     assert server_config.get('any_non_existing_key') == None
Beispiel #8
0
 def test_can_provide_values_from_hash(self):
     server_config = InMemoryConfigStorage({'any_key': 'any_value'})
     assert server_config.get('any_key') == 'any_value'
Beispiel #9
0
 def test_it_raises_exception_if_config_is_missing(self):
     server_config_storage = InMemoryConfigStorage()
     config_builder = RedisMetadataConnectionConfigBuilder(server_config_storage)
     self.assertRaises(ConfigException, config_builder.get)
Beispiel #10
0
 def test_it_raises_exception_as_it_is_abstract(self):
     server_config_storage = InMemoryConfigStorage()
     self.assertRaises(TypeError, RedisConnectionConfigBuilder, server_config_storage, 'whatever_key')
 def test_gets_none_if_cannot_retrieve_key(self):
     server_config = InMemoryConfigStorage()
     assert server_config.get('any_non_existing_key') == None
 def test_can_provide_values_from_hash(self):
     server_config = InMemoryConfigStorage({'any_key': 'any_value'})
     assert server_config.get('any_key') == 'any_value'
    def test_returns_default_when_no_server_conf(self):
        server_config_storage = InMemoryConfigStorage({})
        server_env = ServerEnvironmentBuilder(server_config_storage).get()

        assert server_env.is_development == True
        assert str(server_env) == ServerEnvironmentBuilder.DEFAULT_ENVIRONMENT