def test_forbidden_endpoint_id_asterisk(self): endpoints = { "one": "http://1.example.com/", "*": "http://2.example.com/" } with ExpectedException(ConfigError): EndpointsRoute(None, endpoints, None, None)
def test_duplicate_endpoint_ids(self): endpoints = { "one": "http://1.example.com/", "ONE": "http://1.example.com/", "two": "http://2.example.com/" } with ExpectedException(ConfigError): EndpointsRoute(None, endpoints, None, None)
def setUp(self): super(Test__call__Unmocked, self).setUp() url_patterns = ['http://example.com/{Endpoint_IDs}/'] endpoint = {'test': 'http://example.com/'} endpoints = {'1': 'http://1.example.com/', '2': 'http://2.example.com/'} endpoints_for_ignore = {'1': 'http://1.example.com/', '2': 'http://2.example.com/', '3': 'http://3.example.com/', '4': 'http://4.example.com/', '5': 'http://5.example.com/'} self.endpoint_route = EndpointsRoute(url_patterns, endpoint, [], []) self.endpoints_route = EndpointsRoute(url_patterns, endpoints, [], []) self.endpoints_route_with_ignore = EndpointsRoute(url_patterns, endpoints_for_ignore, [], [0, 400, 500, 501, 502, 503])
def test_endpoint_ids_lowered(self): endpoints = { "ONE": "http://1.example.com/", "two": "http://2.example.com/" } endpoints_route = EndpointsRoute(None, endpoints, None, None) self.assertTrue('one' in endpoints_route._endpoints) self.assertFalse('ONE' in endpoints_route._endpoints)
def parse_dict(route_config): """Produces a route based on an entry in CurryProxy's configuration file. Note that this function will be called multiple times, once for each route CurryProxy is configured to handle. Args: route_config: Dictionary representing one entry in CurryProxy's configuration file. Raises: ConfigError: An error was detected when parsing the data found in the configuration file. """ url_patterns = None if 'status' in route_config: return StatusRoute(route_config['status']) if 'route' not in route_config: raise ConfigError('Each route must contain "route"') # Convert to list for later support of multiple routes per endpoint url_patterns = [route_config['route']] if ('forwarding_url' in route_config and 'endpoints' in route_config): raise ConfigError( 'The route "{0}" cannot contain both ' '"forwarding_url" and "endpoints"'.format(url_patterns)) if 'forwarding_url' in route_config: return ForwardingRoute(url_patterns, route_config['forwarding_url']) if 'endpoints' in route_config: if any('{Endpoint_IDs' not in pattern for pattern in url_patterns): raise ConfigError( 'The route "{0}" must contain the ' 'placeholder "{{Endpoint_IDs}}"'.format(url_patterns)) endpoints = {} for endpoint in route_config['endpoints']: endpoints[endpoint['id']] = endpoint['url'] priority_errors = [] if 'priority_errors' in route_config: priority_errors = route_config['priority_errors'] ignore_errors = parse_ignore_rules(route_config) return EndpointsRoute(url_patterns, endpoints, priority_errors, list(ignore_errors)) raise ConfigError('The route "{0}" must contain either "forwarding_url" ' 'or "endpoints"'.format(url_patterns))
def setUp(self): super(Test_Create_Forwarded_Urls, self).setUp() url_patterns = [ 'https://example.com/{Endpoint_IDs}/', 'https://www.example.com/{Endpoint_IDs}/' ] self.endpoints = { "one": "https://1.example.com/", "two": "https://2.example.com/" } self.route = EndpointsRoute(url_patterns, self.endpoints, [], [])
def setUp(self): super(Test_Find_Pattern_For_Request, self).setUp() self.url_patterns = [ 'https://example.com/{Endpoint_IDs}/', 'https://www.example.com/{Endpoint_IDs}/' ] endpoints = { "one": "https://1.example.com/", "two": "https://2.example.com/" } self.route = EndpointsRoute(self.url_patterns, endpoints, [], [])
def setUp(self): super(Test__Call__, self).setUp() self.patcher = patch.object(grequests, 'map') self.grequests_map = self.patcher.start() url_patterns = ['http://example.com/{Endpoint_IDs}/'] endpoint = {'test': 'http://example.com/'} endpoints = {'1': 'http://1.example.com/', '2': 'http://2.example.com/'} endpoints_for_ignore = {'1': 'http://1.example.com/', '2': 'http://2.example.com/', '3': 'http://3.example.com/', '4': 'http://4.example.com/', '5': 'http://5.example.com/'} self.endpoint_route = EndpointsRoute(url_patterns, endpoint, [], []) self.endpoints_route = EndpointsRoute(url_patterns, endpoints, [], []) self.endpoints_route_with_ignore = EndpointsRoute(url_patterns, endpoints_for_ignore, [], [0, 400, 500, 501, 502, 503])
def setUp(self): super(Test__Log_Response, self).setUp() self.endpoints_route = EndpointsRoute( mock.MagicMock(), mock.MagicMock(), mock.MagicMock(), mock.MagicMock(), ) self.logger = logging.getLogger('curryproxy.routes.endpoints_route') patcher = patch.object(logging, 'debug') self.logging_debug = patcher.start() self.addCleanup(patcher.stop)
def setUp(self): super(Test_Resolve_Query_String, self).setUp() self.route = EndpointsRoute([], [], [], []) self.request_base_url = 'https://1.example.com/path'