Пример #1
0
    def test_endpoints_and_forwarding_url_supplied(self):
        config = {'route': self.forwarding_pattern,
                  'forwarding_url': self.endpoint_1,
                  'endpoints': self.endpoints}

        with ExpectedException(ConfigError):
            route_factory.parse_dict(config)
Пример #2
0
    def test_endpoints_wildcard_missing(self):
        config = {
            'route': self.forwarding_pattern,
            'endpoints': self.endpoints
        }

        with ExpectedException(ConfigError):
            route_factory.parse_dict(config)
Пример #3
0
    def test_endpoints_ignore_errors_range_entry_missing_start_number(self):
        ignore_errors = ["-404"]
        route_dict = {'route': self.endpoints_pattern,
                      'endpoints': self.endpoints,
                      'ignore_errors': ignore_errors}

        with ExpectedException(ConfigError):
            route_factory.parse_dict(route_dict)
Пример #4
0
    def test_endpoints_ignore_errors_range_entry_invalid_stop_number(self):
        ignore_errors = ["401-404A"]
        route_dict = {'route': self.endpoints_pattern,
                      'endpoints': self.endpoints,
                      'ignore_errors': ignore_errors}

        with ExpectedException(ConfigError):
            route_factory.parse_dict(route_dict)
Пример #5
0
    def test_endpoints_ignore_errors_single_entry_invalid_range_max(self):
        ignore_errors = ["600"]
        route_dict = {'route': self.endpoints_pattern,
                      'endpoints': self.endpoints,
                      'ignore_errors': ignore_errors}

        with ExpectedException(ConfigError):
            route_factory.parse_dict(route_dict)
Пример #6
0
    def test_endpoints_and_forwarding_url_supplied(self):
        config = {
            'route': self.forwarding_pattern,
            'forwarding_url': self.endpoint_1,
            'endpoints': self.endpoints
        }

        with ExpectedException(ConfigError):
            route_factory.parse_dict(config)
Пример #7
0
    def test_match_first_route(self):
        route_config_1 = {'route': 'https://www.example.com',
                          'forwarding_url': 'https://1.new.example.com'}
        route_1 = route_factory.parse_dict(route_config_1)
        route_config_2 = {'route': 'https://www.example.com/path',
                          'forwarding_url': 'https://2.new.example.com'}
        route_2 = route_factory.parse_dict(route_config_2)

        self.curry._routes += [route_1, route_2]

        matched_route = self.curry._match_route('https://www.example.com/p')

        self.assertEqual(route_1, matched_route)
Пример #8
0
    def test_matched_route(self):
        # Setup route
        self.route_config = {
            'route': 'https://www.example.com',
            'forwarding_url': 'https://new.example.com'
        }
        self.route = route_factory.parse_dict(self.route_config)
        self.curry._routes.append(self.route)

        # Mocked response
        mock_response = Response()
        mock_response.status = 200
        mock_response.body = 'Response Body'

        # Create request
        environ = {
            'wsgi.url_scheme': 'https',
            'HTTP_HOST': 'www.example.com',
            'PATH_INFO': '/path',
            'QUERY_STRING': 'query=string'
        }
        start_response = StartResponseMock()

        # Issue request
        with patch.object(ForwardingRoute,
                          '__call__',
                          return_value=mock_response):
            response = self.curry.__call__(environ, start_response)

            # Assert
            self.assertEqual(mock_response.status, start_response.status)
            self.assertEqual(mock_response.headerlist, start_response.headers)
            self.assertEqual(mock_response.body, response)
Пример #9
0
    def test_matched_route(self):
        # Setup route
        self.route_config = {'route': 'https://www.example.com',
                             'forwarding_url': 'https://new.example.com'}
        self.route = route_factory.parse_dict(self.route_config)
        self.curry._routes.append(self.route)

        # Mocked response
        mock_response = Response()
        mock_response.status = 200
        mock_response.body = 'Response Body'

        # Create request
        environ = {'wsgi.url_scheme': 'https',
                   'HTTP_HOST': 'www.example.com',
                   'PATH_INFO': '/path',
                   'QUERY_STRING': 'query=string'}
        start_response = StartResponseMock()

        # Issue request
        with patch.object(ForwardingRoute,
                          '__call__',
                          return_value=mock_response):
            response = self.curry.__call__(environ, start_response)

            # Assert
            self.assertEqual(mock_response.status, start_response.status)
            self.assertEqual(mock_response.headerlist, start_response.headers)
            self.assertEqual(mock_response.body, response)
Пример #10
0
    def test_endpoints_ignore_errors_single_entry_valid_range_min(self):
        ignore_errors = ["0"]
        route_dict = {'route': self.endpoints_pattern,
                      'endpoints': self.endpoints,
                      'ignore_errors': ignore_errors}

        route = route_factory.parse_dict(route_dict)
        self.assertEqual([0], route._ignore_errors)
Пример #11
0
    def test_endpoints_priority_errors(self):
        priority_errors = [401, 404]
        route_dict = {'route': self.endpoints_pattern,
                      'endpoints': self.endpoints,
                      'priority_errors': priority_errors}

        route = route_factory.parse_dict(route_dict)

        self.assertEqual(priority_errors, route._priority_errors)
Пример #12
0
    def test_endpoints(self):
        route = route_factory.parse_dict(self.endpoints_config)

        self.assertTrue(self.endpoint_1['id'] in route._endpoints)
        self.assertEqual(self.endpoint_1['url'],
                         route._endpoints[self.endpoint_1['id']])
        self.assertTrue(self.endpoint_2['id'] in route._endpoints)
        self.assertEqual(self.endpoint_2['url'],
                         route._endpoints[self.endpoint_2['id']])
Пример #13
0
    def test_endpoint(self):
        config = {'route': self.endpoints_pattern,
                  'endpoints': [self.endpoint_1]}

        route = route_factory.parse_dict(config)

        self.assertTrue(self.endpoint_1['id'] in route._endpoints)
        self.assertEqual(self.endpoint_1['url'],
                         route._endpoints[self.endpoint_1['id']])
Пример #14
0
    def test_endpoints(self):
        route = route_factory.parse_dict(self.endpoints_config)

        self.assertTrue(self.endpoint_1['id'] in route._endpoints)
        self.assertEqual(self.endpoint_1['url'],
                         route._endpoints[self.endpoint_1['id']])
        self.assertTrue(self.endpoint_2['id'] in route._endpoints)
        self.assertEqual(self.endpoint_2['url'],
                         route._endpoints[self.endpoint_2['id']])
Пример #15
0
    def test_unmatched_no_matching_routes(self):
        route_config = {'route': 'https://www.example.com',
                        'forwarding_url': 'https://new.example.com'}
        route = route_factory.parse_dict(route_config)

        self.curry._routes.append(route)

        with ExpectedException(RequestError):
            self.curry._match_route('https://1.www.example.com/path')
Пример #16
0
    def test_endpoints_ignore_errors_range_entry_valid(self):
        ignore_errors = ["401-404"]
        route_dict = {'route': self.endpoints_pattern,
                      'endpoints': self.endpoints,
                      'ignore_errors': ignore_errors}

        route = route_factory.parse_dict(route_dict)

        self.assertEqual(range(401, 405), route._ignore_errors)
Пример #17
0
    def test_match(self):
        route_config = {'route': 'https://www.example.com',
                        'forwarding_url': 'https://new.example.com'}
        route = route_factory.parse_dict(route_config)

        self.curry._routes.append(route)

        matched_route = self.curry._match_route('https://www.example.com/path')

        self.assertEqual(route, matched_route)
Пример #18
0
    def test_endpoint(self):
        config = {
            'route': self.endpoints_pattern,
            'endpoints': [self.endpoint_1]
        }

        route = route_factory.parse_dict(config)

        self.assertTrue(self.endpoint_1['id'] in route._endpoints)
        self.assertEqual(self.endpoint_1['url'],
                         route._endpoints[self.endpoint_1['id']])
Пример #19
0
    def test_endpoints_priority_errors(self):
        priority_errors = [401, 404]
        route_dict = {
            'route': self.endpoints_pattern,
            'endpoints': self.endpoints,
            'priority_errors': priority_errors
        }

        route = route_factory.parse_dict(route_dict)

        self.assertEqual(priority_errors, route._priority_errors)
Пример #20
0
    def _process_routes(self, routes_file):
        """Read a configuration file and setup an instance of CurryProxy.

        Args:
            routes_file: Path to CurryProxy's main configuration file which
                details the routes to be served and the backend endpoints each
                route points to.

        """
        try:
            route_configs = json.load(open(routes_file))
        except ValueError:
            raise ConfigError('Configuration file contains invalid JSON.')

        for route_config in route_configs:
            self._routes.append(route_factory.parse_dict(route_config))
Пример #21
0
    def test_endpoints_wildcard_missing(self):
        config = {'route': self.forwarding_pattern,
                  'endpoints': self.endpoints}

        with ExpectedException(ConfigError):
            route_factory.parse_dict(config)
Пример #22
0
    def test_forwarding_url(self):
        route = route_factory.parse_dict(self.forwarding_config)

        self.assertEqual(self.endpoint_1, route._forwarding_url)
Пример #23
0
    def test_endpoints_ignore_errors_missing(self):
        route = route_factory.parse_dict(self.endpoints_config)

        self.assertEqual([], route._ignore_errors)
Пример #24
0
    def test_forwarding_url(self):
        route = route_factory.parse_dict(self.forwarding_config)

        self.assertEqual(self.endpoint_1, route._forwarding_url)
Пример #25
0
    def test_route(self):
        route = route_factory.parse_dict(self.endpoints_config)

        self.assertEqual([self.endpoints_pattern], route._url_patterns)
Пример #26
0
 def test_route_missing(self):
     with ExpectedException(ConfigError):
         route_factory.parse_dict({'endpoints': self.endpoints})
Пример #27
0
 def test_endpoints_and_forwarding_url_missing(self):
     with ExpectedException(ConfigError):
         route_factory.parse_dict({'route': self.forwarding_pattern})
Пример #28
0
    def test_status(self):
        route_dict = {'status': ['http://curryproxy.example.com/status']}

        route = route_factory.parse_dict(route_dict)

        self.assertEqual(route_dict['status'], route._url_patterns)
Пример #29
0
 def test_endpoints_and_forwarding_url_missing(self):
     with ExpectedException(ConfigError):
         route_factory.parse_dict({'route': self.forwarding_pattern})
Пример #30
0
    def test_route(self):
        route = route_factory.parse_dict(self.endpoints_config)

        self.assertEqual([self.endpoints_pattern], route._url_patterns)
Пример #31
0
 def test_route_missing(self):
     with ExpectedException(ConfigError):
         route_factory.parse_dict({'endpoints': self.endpoints})
Пример #32
0
    def test_status(self):
        route_dict = {'status': ['http://curryproxy.example.com/status']}

        route = route_factory.parse_dict(route_dict)

        self.assertEqual(route_dict['status'], route._url_patterns)