Write and Run Integration Tests
The db_routes.py Blueprint from lesson 3.3 is integrated with the Music Analytics API. You can view it here: music-analytics-api-with-db-routed-validated/db_routes.py. It returns albums by artist with Pydantic validation:
class Album(BaseModel):
AlbumId: int
Title: str
class ArtistAlbumsResponse(BaseModel):
artist_id: int
artist_name: str
albums: list[Album]
@db_routes.route("/artists/<int:artist_id>/albums")
def get_artist_albums(artist_id):
# Queries chinook.db, returns 404 if artist not found
...
You're already in music-analytics-api-with-db-routed-validated/; MCP is configured there. Ask Claude to write a pytest integration test, review it, and then run it.
This exercise is part of the course
Software Development with Claude Code
Exercise instructions
- Start Claude Code with
claude. - Reference
@db_routes.pyand ask Claude to write a pytest integration test for the endpoint. - Once the test looks good, ask Claude to run it.
- When done, type
/exitto exit Claude Code.
Hands-on interactive exercise
Turn theory into action with one of our interactive exercises
Start Exercise