Restful-Booker API Tests¶
An API test suite for Restful-Booker, a free RESTful API by Mark Winteringham for practicing API test automation. It is built with pytest and requests, and its 9 tests walk through the complete booking lifecycle, from creation to deletion, with every HTTP call logged.
What's Covered¶
- Health check — ping endpoint
- Authentication — token creation
- Create and get booking — create a new booking and retrieve it by ID
- Update booking — full and partial update
- Search bookings — search by name and dates
- Delete booking — delete, then a negative check for 404 after deletion
How It's Built¶
- Dependency-based orchestration —
pytest-dependencymarkers enforce the order: auth, create, get, update, partial update, search, delete, verify deletion. - API client pattern — all endpoints are wrapped in a
RestfulBookerAPIclass, with HTTP methods abstracted inHTTPMethods. - Response validation helpers — utilities for status codes, JSON structure and field values.
- Dual logging — requests and responses are logged at the HTTP client level to files and to the pytest-html report.
- Error handling — descriptive errors, a 30-second timeout for all requests and JSON parsing errors with a response preview.
- Dynamic test data — Faker generates names, prices, booking dates, additional needs and deposit status.
Tech Stack¶
pytest— testing frameworkrequests— HTTP client librarypytest-html— HTML reports with logspytest-dependency— test dependency managementfaker— test data generationpython-dotenv— environment configurationuv— Python package managerruff— linter and formatter
Running It¶
Install dependencies, then run the tests with or without an HTML report:
make install
make test
make test-html