Estimated time: ~14 hours for someone new to Python (an estimate, not yet measured with real learners). The starter file:
code-labs/l1-m03/exercises/test_summary_service.py.
Main practical exercise
Business context
ShopEasy's dev team (fictional) wrote SummaryService, a service that calls the Claude API to summarise customer-service
tickets. The service is about to go to production. You are asked to write an API test suite to verify that the service follows
its contract, before it calls the real API.
Problem to solve
Does the service follow its contract? If not, where are the violations, and how serious are they?
Input data
- Contract:
summarize(ticket)returns{"ok": bool, "summary": str | None, "error": str | None, "retryable": bool}.- Every call sends a
max_tokensof no more than 1024, and uses the model in theSUMMARY_MODELenvironment variable (defaultclaude-opus-5-5). - Errors 400, 401, 403, 404 and 413 are never retried. 429, 5xx and 529 are retried at most 2 times,
that is, at most 3 requests for one call to
summarize(). - A reply truncated because of
max_tokensis never returned withok=True. erroris a fixed sentence, safe for the user, that never contains the provider's error content or the key.retryableisTrueexactly for 429 (except the spend cap), 5xx and 529.
- Tools:
FakeClaudeAPI,Reply,error_body,messageinlab/fake_api.py; theapifixture intests/conftest.py. - Black-box rule: call the service through
SummaryService(base_url=api.base_url).summarize(...)and observe what it sends (api.requests) and returns. Do not read the code below the contract.
Tasks
- Analyse the contract. Make a table: clause, how to verify it (what the fake must return, what to measure), oracle.
- Write the test suite. Copy
exercises/test_summary_service.pyintotests/. Write at least one test for each of clauses 2-6. For clauses 3 and 6, test at least two different kinds of error. - Run and analyse. Record which tests fail. For each failing test, decide whether it is a defect in the service or a defect in the test.
- Defect report.
reports/summary-service-defects.md: one entry per defect, with the violated clause, how to reproduce it (the fake reply and the input), expected, actual (with the number of requests observed where relevant), severity, and the impact in production (cost, experience, security). - Reflection. 5-10 sentences: which of your tests can not be run reliably against the real API, and why? Which live test would you add, when would it run, and with what budget?
Deliverables
contract-analysis.md
tests/test_summary_service.py
reports/summary-service-defects.md
reports/reflection.md
Paste the output of python -m pytest tests/test_summary_service.py -v at the end of the defect report.
Acceptance criteria (mandatory)
| # | Criterion |
|---|---|
| AC1 | The tests run offline with the fake API; no real key needed; no network calls off the machine |
| AC2 | Each of clauses 2-6 has at least one test; clauses 3 and 6 have at least two kinds of error |
| AC3 | The retry tests assert the number of requests actually sent (len(api.requests)), not only the returned result |
| AC4 | Each failing test has a matching defect report, or is explained as a defect in the test |
| AC5 | At least 4 different defects are found |
| AC6 | No real key, real data or real API output in the submission |
Scoring rubric (100 points)
| Dimension | 0 | 1 | 2 | 3 | Weight |
|---|---|---|---|---|---|
| Test design | AC2/AC3 not met | AC2/AC3 met, but each clause has only one easy case | Each clause has an easy case and a boundary case | As level 2, plus errors that do not come through HTTP (lost connection, timeout), the spend cap, model_context_window_exceeded, and a test that proves the fixture does not use real credentials |
25 |
| Implementation | Does not run | Runs, but weak checks (only ok) |
Checks the request body, the number of requests, the whole result | As level 2, tests independent of each other, clear failure messages, sensible use of parametrize | 25 |
| Contract analysis | Missing | Lists the clauses | Has a verification method and an oracle for each clause | As level 2, plus points out ambiguous clauses and questions for the product owner | 10 |
| Defect analysis | AC5 not met | 4 defects, severity or impact missing | ≥ 4 defects, each with its clause and severity | As level 2, plus a reasoned impact (retry cost, security) and at least one defect outside the patterns learned in the lessons | 15 |
| Reporting | Missing | Vague | All fields present, reproducible | Concise, with the number of requests and the configuration, a clear fix priority | 15 |
| Reflection | Missing | Generic | Distinguishes fake, replay and live | As level 2, plus a live test plan with a specific frequency and budget | 10 |
Score per dimension = (level achieved / 3) × weight. Mapping to the module: practical = Test design + Implementation (50); applied QA analysis = Contract analysis + Defect analysis (25); review/reflection = Reporting + Reflection (25).
Hints
Hint 1
A service that calls the SDK may have retries at several layers. Count the requests.Hint 2
Queue more error replies than the number of attempts you predict, so that the default successful reply does not slip in; then count `len(api.requests)`.Hint 3
Clause 1 says `summarize()` always returns a dict. Is there a situation in which a service returns nothing at all?Independent challenge
No code to run. It assesses design skills.
Context: EduTalk (fictional) calls the Claude API in streaming mode to grade speaking exercises and show the feedback gradually. The product owner requires: "TTFT under 1.5 seconds for 95% of requests; if the stream fails midway, clear the part already shown and report the error; never spend more than $50 a day on testing."
Tasks:
- Break the requirement into verifiable criteria; for each criterion, choose a test with the fake, replay or live, and explain.
- Design a TTFT measurement plan: the number of measurements, the environment, how p95 is calculated, and how cost is controlled (use the prices in L01; state your assumptions about token counts).
- Write 5 test cases for a stream that fails midway (describe the fake reply and the expected result).
Separate rubric (100 points, pass at ≥ 70):
| Dimension | 0 | 1 | 2 | 3 | Weight |
|---|---|---|---|---|---|
| Requirement breakdown and choice of test layer | Missing | Choices not explained | Mostly correct choices, with reasons | As level 2, plus recognises which requirements need clarifying | 35 |
| Measurement plan | Missing | No figures | Has the number of measurements, p95, the environment | As level 2, plus a cost estimate with clear assumptions that stays within the budget | 35 |
| Stream-error test cases | Missing | Happy path only | 5 valid cases | As level 2, covering different error positions (before the first chunk, in the middle, before message_stop) |
30 |
Rules
- Do not use a real key, real data, or real API output in your submission.
- If you run a live test yourself (optional), use your own account, set a spending limit first, and use synthetic data.