def test_docs():
    "Testing that docs are initializing csrf headers correctly"

    api = NinjaAPI(csrf=True)

    client = TestClient(api)
    resp = client.get("/docs")
    assert resp.status_code == 200
    csrf_token = re.findall(r'data-csrf-token="(.*?)"', resp.content.decode("utf8"))[0]
    assert len(csrf_token) > 0

    api.csrf = False
    resp = client.get("/docs")
    assert resp.status_code == 200
    csrf_token = re.findall(r'data-csrf-token="(.*?)"', resp.content.decode("utf8"))[0]
    assert len(csrf_token) == 0
Testing that docs are initializing csrf headers correctly
tests/test_csrf.py