Testing#
Test helpers for the REST API conventions, currently
assert_error_envelope() — a single assertion that a response carries a
well-formed ADR 0029 error envelope.
- LEGACY_ERROR_FIELDS = ('developer_message', 'error_code')#
Legacy edx-platform error keys (
DeveloperErrorViewMixin) that must not leak into a standardized envelope.
- REQUIRED_ERROR_ENVELOPE_FIELDS = ('type', 'title', 'status', 'detail', 'instance')#
The keys every ADR 0029 error envelope must carry.
- assert_error_envelope(response, expected_status=None, expected_type_slug=None)#
Assert that
responsecarries a well-formed ADR 0029 error envelope.Checks that every required envelope field is present, that
statusinside the body matches the response’s status code, thattypeis anhttps://docs.openedx.org/errors/URI, thatinstanceis the request path (when the test client attached the request to the response), and that no legacyDeveloperErrorViewMixinfields leak through.- Parameters:
response – a DRF test-client response (
response.data) or any response exposingjson().expected_status (int) – when given, also assert the HTTP status code.
expected_type_slug (str) – when given, also assert the exact error-type slug (e.g.
"authn","not-found").
- Returns:
the decoded envelope, for any follow-up assertions.
- Return type:
dict