Exemplo n.º 1
0
    def get_drf_yasg_compatible_route(self, route: str) -> str:
        """
        Returns a url that matches the urls found in a drf_yasg-generated schema.

        :param route: Django resolved route
        """
        resolved_route = resolve_path(route)
        path_prefix = self.get_path_prefix(
        )  # typically might be 'api/' or 'api/v1/'
        logger.debug('Path prefix: %s', path_prefix)
        if path_prefix != '/':
            return resolved_route[len(path_prefix):]
        else:
            return resolved_route
Exemplo n.º 2
0
    def __init__(self,
                 route: str,
                 method: str,
                 status_code: Optional[int] = None,
                 **kwargs) -> None:
        """
        Loads OpenAPI schema from a static file.

        :param route: a django-resolved endpoint path
        :param status_code: the relevant HTTP response status code to check in the OpenAPI schema
        :param method: the relevant HTTP method to check in the OpenAPI schema
        """
        validate_inputs(route=route, status_code=status_code, method=method)
        package_settings = settings.SWAGGER_TESTER
        self.validation(package_settings)
        self.path = package_settings['PATH']

        self.route = resolve_path(route)
        self.status_code = status_code
        self.method = method
Exemplo n.º 3
0
def test_successful_resolve() -> None:
    """
    This should run without errors.
    """
    for path in paths:
        resolve_path(path)
Exemplo n.º 4
0
def test_no_path_suggestions():
    """
    Make sure the appropriate error is raised.
    """
    with pytest.raises(ValueError, match='Could not resolve path'):
        resolve_path('this is not a path')
Exemplo n.º 5
0
def test_path_suggestions():
    """
    When a resolve fails, we want to output useful output.
    """
    with pytest.raises(ValueError, match='Did you mean one of these?'):
        resolve_path('trucks/correct')
Exemplo n.º 6
0
def test_successful_resolve_despite_missing_trailing_slash():
    """
    A trailing slash isn't always necessary, but when it is, a path missing its trailing slash should still resolve successfully.
    """
    for path in paths:
        resolve_path(path[:-1])
Exemplo n.º 7
0
def test_successful_resolve_despite_missing_leading_slash():
    """
    A path should resolve despite missing a leading slash.
    """
    for path in paths:
        resolve_path(path[1:])