Ejemplo n.º 1
0
def test_misconfigured_routes():
    def view():
        raise NotImplementedError

    with pytest.raises(exceptions.ConfigurationError):
        WSGIApp(
            routes=[Route('/', 'GET', view),
                    Route('/another', 'POST', view)])
Ejemplo n.º 2
0
    def __init__(self):
        routes = import_module(settings.APISTAR_ROUTE_CONF).routes

        if settings.DEBUG:
            routes.append(Include('/static', static_urls))
            routes.append(Include('/docs', docs_urls))

        self.django_wsgi_app = get_wsgi_application()
        self.apistar_wsgi_app = WSGIApp(routes=routes,
                                        settings=settings.APISTAR_SETTINGS)
Ejemplo n.º 3
0
def test_misconfigured_type_on_route():
    def set_type(var: set):
        raise NotImplementedError

    with pytest.raises(exceptions.ConfigurationError):
        WSGIApp(routes=[Route('/{var}/', 'GET', set_type)])
Ejemplo n.º 4
0
    Route('/path_params/{var}/', 'GET', path_params),
    Route('/path_param/{var}/', 'GET', path_param),
    Route('/int/{var}/', 'GET', path_param_with_int),
    Route('/full_path/{var}', 'GET', path_param_with_full_path),
    Route('/max_length/{var}/', 'GET', path_param_with_max_length),
    Route('/number/{var}/', 'GET', path_param_with_number),
    Route('/integer/{var}/', 'GET', path_param_with_integer),
    Route('/string/{var}/', 'GET', path_param_with_string),
    Include('/subpath', [
        Route('/{var}/', 'GET', subpath),
    ],
            namespace='included'),
    Route('/x', 'GET', lambda: 1, name='x'),
    Include('/another_subpath', [Route('/x', 'GET', lambda: 1, name='x2')]),
]
wsgi_app = WSGIApp(routes=routes)
async_app = ASyncIOApp(routes=routes)

wsgi_client = TestClient(wsgi_app)
async_client = TestClient(async_app)


@pytest.mark.parametrize('client', [wsgi_client, async_client])
def test_200(client):
    response = client.get('/found/')
    assert response.status_code == 200
    assert response.json() == {'message': 'Found'}


@pytest.mark.parametrize('client', [wsgi_client, async_client])
def test_404(client):
Ejemplo n.º 5
0
            return None

        scheme, token = authorization.split()
        if scheme.lower() != 'basic':
            return None

        username, password = base64.b64decode(token).decode('utf-8').split(':')
        return Authenticated(username)


routes = [
    Route('/auth/', 'GET', get_auth),
]
settings = {'AUTHENTICATION': [BasicAuthentication()]}

wsgi_app = WSGIApp(routes=routes, settings=settings)
wsgi_client = TestClient(wsgi_app)

async_app = ASyncIOApp(routes=routes, settings=settings)
async_client = TestClient(async_app)


@pytest.mark.parametrize('client', [wsgi_client, async_client])
def test_unauthenticated_request(client):
    response = client.get('http://example.com/auth/')
    assert response.json() == {
        'display_name': None,
        'user_id': None,
        'is_authenticated': False
    }