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 response carries a well-formed ADR 0029 error envelope.

Checks that every required envelope field is present, that status inside the body matches the response’s status code, that type is an https://docs.openedx.org/errors/ URI, that instance is the request path (when the test client attached the request to the response), and that no legacy DeveloperErrorViewMixin fields leak through.

Parameters:
  • response – a DRF test-client response (response.data) or any response exposing json().

  • 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