File: test_secrets.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 (21 lines) | stat: -rw-r--r-- 745 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
from docs.examples.datastructures.secrets.secret_body import post_handler
from docs.examples.datastructures.secrets.secret_header import get_handler

from litestar.status_codes import HTTP_200_OK, HTTP_201_CREATED
from litestar.testing import create_test_client


def test_secret_header() -> None:
    with create_test_client(get_handler) as client:
        r = client.get("/", headers={"x-secret": "super-secret"})

    assert r.status_code == HTTP_200_OK
    assert r.json() == {"value": "sensitive data"}


def test_secret_body() -> None:
    with create_test_client(post_handler) as client:
        r = client.post("/", json={"value": "super-secret"})

    assert r.status_code == HTTP_201_CREATED
    assert r.json() == {"value": "******"}