def test_server_rate_limit(self):
     rate_limits = '{"geocoder":{"limit":"3","period":3600}}'
     plpy_mock._define_result("CDB_Conf_GetConf\('rate_limits'\)", [{'conf': rate_limits}])
     with patch.object(RedisConnectionBuilder,'get') as get_fn:
         get_fn.return_value = self.redis_conn
         service_manager = ServiceManager('geocoder', MapzenGeocoderConfigBuilder, self.username, self.orgname)
         self.check_rate_limit(service_manager, 3)
     plpy_mock._define_result("CDB_Conf_GetConf\('rate_limits'\)", [])
 def test_org_rate_limit(self):
     org_redis_name = "rails:orgs:{0}".format(self.orgname)
     rate_limits = '{"limit":"3","period":3600}'
     self.redis_conn.hset(org_redis_name, 'geocoder_rate_limit', rate_limits)
     with patch.object(RedisConnectionBuilder,'get') as get_fn:
         get_fn.return_value = self.redis_conn
         service_manager = ServiceManager('geocoder', MapzenGeocoderConfigBuilder, self.username, self.orgname)
         self.check_rate_limit(service_manager, 3)
     self.redis_conn.hdel(org_redis_name, 'geocoder_rate_limit')
 def test_org_rate_limit_precedence_over_server(self):
     server_rate_limits = '{"geocoder":{"limit":"1000","period":3600}}'
     plpy_mock._define_result("CDB_Conf_GetConf\('rate_limits'\)", [{'conf': server_rate_limits}])
     org_redis_name = "rails:orgs:{0}".format(self.orgname)
     org_rate_limits = '{"limit":"3","period":3600}'
     self.redis_conn.hset(org_redis_name, 'geocoder_rate_limit', org_rate_limits)
     with patch.object(RedisConnectionBuilder,'get') as get_fn:
         get_fn.return_value = self.redis_conn
         service_manager = ServiceManager('geocoder', MapzenGeocoderConfigBuilder, self.username, self.orgname)
         self.check_rate_limit(service_manager, 3)
     self.redis_conn.hdel(org_redis_name, 'geocoder_rate_limit')
     plpy_mock._define_result("CDB_Conf_GetConf\('rate_limits'\)", [])
 def test_no_rate_limit_by_default(self):
     with patch.object(RedisConnectionBuilder,'get') as get_fn:
         get_fn.return_value = self.redis_conn
         service_manager = ServiceManager('geocoder', MapzenGeocoderConfigBuilder, self.username, self.orgname)
         self.check_rate_limit(service_manager, 3, False)
 def test_service_manager(self):
     with patch.object(RedisConnectionBuilder,'get') as get_fn:
         get_fn.return_value = self.redis_conn
         service_manager = ServiceManager('geocoder', MapzenGeocoderConfigBuilder, self.username, self.orgname)
         service_manager.assert_within_limits()
         assert_equal(service_manager.config.service_type, 'geocoder_mapzen')