We provide our own fixtures that are subclasses of Django's builtin one.
Django has this code inside: https://github.com/django/django/blob/7dc826b9758d634623a6f5ca05d0ca2048a0ce48/django/test/client.py#L450-L458
def _encode_json(self, data, content_type):
"""
Return encoded JSON if data is a dict, list, or tuple and content_type
is application/json.
"""
should_encode = JSON_CONTENT_TYPE_RE.match(content_type) and isinstance(
data, (dict, list, tuple)
)
return json.dumps(data, cls=self.json_encoder) if should_encode else data
We need to optimize this method, because json.dumps is slow, but msgspec is fast.
It won't be noticable on 1 tests, but will be on 2k tests (which is the case for our own test base).
See how we conditionally dump our schema here: https://github.com/wemake-services/django-modern-rest/blob/master/dmr/openapi/dump.py
Maybe we should reuse the same for tests?
We provide our own fixtures that are subclasses of Django's builtin one.
Django has this code inside: https://github.com/django/django/blob/7dc826b9758d634623a6f5ca05d0ca2048a0ce48/django/test/client.py#L450-L458
We need to optimize this method, because
json.dumpsis slow, butmsgspecis fast.It won't be noticable on 1 tests, but will be on 2k tests (which is the case for our own test base).
See how we conditionally dump our schema here: https://github.com/wemake-services/django-modern-rest/blob/master/dmr/openapi/dump.py
Maybe we should reuse the same for tests?