Writing a manual functional test

Introduction to FastAPI

Matt Eckerle

Software and Data Engineering Leader

What Are Functional Tests?

System Tests

  • Focus: Isolated system operations
  • Purpose: Validate system function
  • Scope: Endpoint
  • Environment: Python env with app running
def test_read():
    response = client.get("/items/1")
    assert response.status_code == 200

Functional Tests

  • Focus: Integrated system
  • Purpose: Validate system overall
  • Scope: Application
  • Environment: Python env with app running
def test_delete_then_read():
    response = client.delete("/items/1")
    assert response.status_code == 200
    response = client.get("/items/1")
    assert response.status_code == 404
Introduction to FastAPI

Test Workflows

Diagrams showing examples of success and failure test workflows

Introduction to FastAPI

Functional Test Workflow Examples

Successful workflows

  • Create, then read
  • Create, then update
  • Create, then delete
  • ...

Failing workflows

  • Read without create
  • Update after delete
  • Delete without create
  • ...
Introduction to FastAPI

Functional Test Scripts

  • Outside test framework - "Manual tests"
  • Use requests
import requests
ENDPOINT = "http://localhost:8000/items"
# Create item "rock"
r = requests.post(ENDPOINT, json={"name": "rock"})
assert r.status_code == 200
# Get item rock
r = requests.get(ENDPOINT, json={"name": "rock"})
assert r.status_code == 200
  • Workflows built against known application state
Introduction to FastAPI

Let's practice!

Introduction to FastAPI

Preparing Video For Download...