File: test_tutorial002.py

package info (click to toggle)
fastapi 0.118.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 34,212 kB
  • sloc: python: 69,848; javascript: 369; sh: 18; makefile: 17
file content (15 lines) | stat: -rw-r--r-- 570 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
from fastapi.testclient import TestClient

from docs_src.advanced_middleware.tutorial002 import app


def test_middleware():
    client = TestClient(app, base_url="http://example.com")
    response = client.get("/")
    assert response.status_code == 200, response.text
    client = TestClient(app, base_url="http://subdomain.example.com")
    response = client.get("/")
    assert response.status_code == 200, response.text
    client = TestClient(app, base_url="http://invalidhost")
    response = client.get("/")
    assert response.status_code == 400, response.text