File: test_using_jwt_auth.py

package info (click to toggle)
litestar 2.21.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 12,568 kB
  • sloc: python: 70,588; makefile: 254; javascript: 104; sh: 60
file content (18 lines) | stat: -rw-r--r-- 769 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
from uuid import uuid4

from docs.examples.security.jwt.using_jwt_auth import app

from litestar.status_codes import HTTP_200_OK, HTTP_201_CREATED, HTTP_401_UNAUTHORIZED
from litestar.testing import TestClient


def test_using_jwt_auth() -> None:
    with TestClient(app) as client:
        response = client.get("/some-path")
        assert response.status_code == HTTP_401_UNAUTHORIZED
        response = client.post(
            "/login", json={"name": "Moishe Zuchmir", "email": "moishe@zuchmir.com", "id": str(uuid4())}
        )
        assert response.status_code == HTTP_201_CREATED, response.json()
        response = client.get("/some-path", headers={"Authorization": response.headers.get("authorization")})
        assert response.status_code == HTTP_200_OK