CS 220 — Web Applications, SQL and Software Engineering · Weeks 12–14
Version control, tests and delivery
Full teaching sequence and cumulative subject work
Study the complete on-site source sections below, then work the original example, changed-condition problem and transfer laboratory. Study CS50 Web Git and Testing, CI/CD. Build separate unit, integration and accessibility checks; rehearse a reversible deployment using fictional records.
Integration tests and reversible delivery
Unit tests can establish a function’s behavior while the deployed route never calls it. Integration tests cross the actual boundary: authentication, routing, validation, persistence and serialization. A useful negative test attempts an operation as the wrong user and verifies both the response and the absence of data changes.
Deployment includes schema evolution. An application rollback can fail if a migration removed a column the previous version still requires. Expand-and-contract changes keep old and new application versions compatible during transition. Backups and restoration tests answer a different question from whether a migration script exits successfully.
Worked problem
Version 2 renames customer_name to display_name by deleting the old column immediately. Version 1 remains on one running worker. Explain the failure and a safer sequence.
Trace the complete reasoning
The old worker can still query customer_name and fail after the migration. Rolling back application code alone does not restore the column.
First add display_name without removing customer_name. Backfill and use a documented compatibility period with synchronized writes or a clear authoritative field.
Deploy code that reads the new field with the required transition fallback. Verify old/new behavior and data reconciliation.
Remove the old field only after all consumers have migrated and rollback requirements are resolved. Test recovery on a disposable copy first.
Independent transfer problem
A unit authorization test passes, but the endpoint accepts role=admin from submitted JSON. Design the integration test that exposes it.
Compare the transfer solution
Authenticate as an ordinary customer, submit role=admin with a request targeting another customer’s order, and verify denial plus no database change. Then verify the permitted operation on the customer’s own order. The test must call the real route so a correct helper cannot conceal an untrusted role source.
Learning objectives
- Explain and trace the mechanisms in version control, tests and delivery.
- Apply the method to the worked example and changed-condition exercise.
- Identify assumptions, failure cases and the evidence needed to justify a result.
Study the mechanism
Version control records changes and their relationships. A commit should represent a coherent change that can be reviewed and explained. A branch provides an independent line of work; merging integrates histories and may require resolving semantic conflicts even when text merges automatically. Secrets do not belong in commits. Deleting a secret from the current file does not remove it from history or revoke it.
A delivery pipeline should test the exact revision it deploys. Unit tests isolate rules; integration tests exercise real boundaries; end-to-end tests exercise visitor behavior. A screenshot cannot show that server authorization works. Use fixtures with duplicate names, empty lists, large values and denied access. A migration should have a compatibility and recovery plan; rolling back application files may not reverse a destructive database change.
Operational readiness includes observability and recovery. Log enough to diagnose failures while minimizing sensitive content. Monitor errors and latency as well as uptime. Rehearse restoration rather than merely asserting that backups exist. A failed deployment should leave a clear route to a known working revision. Define acceptance through concrete user tasks: create an order, retrieve it as its owner, reject another account, recover from a failed request and continue using existing records.
Worked example
def can_edit(member, order):
return member["id"] == order["owner"] or member.get("role") == "admin"
assert can_edit({"id": "a"}, {"owner": "a"})
assert not can_edit({"id": "b"}, {"owner": "a"})
assert can_edit({"id": "b", "role": "admin"}, {"owner": "a"})These unit tests check a rule in isolation. They do not prove that the deployed endpoint actually calls this function or that roles come from a trusted source. An integration test must verify those connections. If the endpoint accepts role from submitted JSON, the rule can be correct while the system remains vulnerable.
Check your understanding
Why are unit authorization tests insufficient alone?
- The endpoint might bypass the tested rule or supply untrusted identity data
- Unit tests automatically exercise production routing
- Passing tests remove the need for integration
Answer and reasoning for every option
Correct: The endpoint might bypass the tested rule or supply untrusted identity data The complete boundary must also be exercised.
Reconsider: Unit tests automatically exercise production routing Isolated function tests do not invoke every route.
Reconsider: Passing tests remove the need for integration Each test level supplies different evidence.
Transfer laboratory: A migration and backward compatibility
A deployment introduces a mandatory new field while old application instances still create records without it. Propose a staged migration and rollback behavior.
Work through the full solution
Add the field compatibly, deploy code that can read both old and new records, backfill under an explicit rule, then enforce the constraint once all writers are compatible. Avoid inventing historical values during backfill. A rollback of code must remain able to read records created by the new release. Test mixed-version behavior and restoration before destructive changes.
Evidence of understanding
Separate expand, migrate and constrain stages and preserve existing records.
Complete on-site teaching readings
These are full attributed source sections, not previews. Read them alongside the original Academy explanation and code.
- Introduction to cross-browser testing · Mozilla Contributors
- Website security · Mozilla Contributors
- 5.7. Modifying Tables # · The PostgreSQL Global Development Group and The Regents of the University of California
- 25.1. SQL Dump # · The PostgreSQL Global Development Group and The Regents of the University of California
- Django Tutorial Part 10: Testing a Django web application · Mozilla Contributors
- Django Tutorial Part 11: Deploying Django to production · Mozilla Contributors
Open the complete practice sequence and cumulative assessment →