This repository contains integration-style pytest tests that exercise the main endpoints (ping, auth, create/list/get/update/patch/delete bookings). Tests are intended to run against the public demo service but can be adapted to use mocks for offline testing or CI.
-
Clone the repository and change into the project root:
git clone <repo-url> cd restful_api_framework
-
Create a virtual environment and install dependencies:
python -m venv .venv source .venv/bin/activate # macOS / Linux .venv\Scripts\Activate.ps1 # Windows PowerShell pip install -r requirements.txt
If
requirements.txtis not present, install the minimal deps:pip install pytest requests
-
Run the full test suite (integration tests hit the live demo API):
pytest -q
-
BASE_URL
- Default (used in tests):
https://restful-booker.herokuapp.com - You can override this to point tests at another server:
export BASE_URL="http://localhost:3000" # macOS / Linux setx BASE_URL "http://localhost:3000" # Windows (new session required)
- Default (used in tests):
-
AUTH_USERNAME / AUTH_PASSWORD
- Default used by tests:
admin/password123 - You can override if your server uses different credentials:
export AUTH_USERNAME="admin" export AUTH_PASSWORD="password123"
- Default used by tests:
- Tests are written with
pytest. - They exercise the public API directly and therefore are integration tests that require network access.
- Fixtures include:
base_url— base endpointauth_token— obtains an auth token from/authand is used for update/delete operationscreate_booking— helper fixture to create bookings and perform best-effort cleanup
- Recommended marker:
- Mark integration tests with
@pytest.mark.integrationif you want to skip them during fast/local runs:pytest -m "not integration" pytest -m integration
- Mark integration tests with
Run a single test file:
pytest tests/test_restful_booker.py::test_create_and_get_booking -qRun tests matching a keyword:
pytest -k create -qIf you prefer not to hit the live service:
- Use libraries such as
responses,requests-mock, orvcrpyto stub HTTP interactions. - Example (install):
pip install responses
- Replace network calls in tests with mocked responses, or add a pytest fixture that toggles a
requestsadapter.
- api/ - optional in-repo application code
- tests/ - pytest test modules
- conftest.py - shared fixtures and sys.path adjustments
- requirements.txt - Python dependencies
- README.md
- Add a CI step to create a virtualenv, install
-r requirements.txt, and runpytest. - For public demo tests, consider isolating or gating integration tests so CI does not fail due to external service outages. Use
pytest -m "not integration"in fast CI pipelines, and run integration tests separately.