revsys / django-test-plus

Useful additions to Django's default TestCase
https://django-test-plus.readthedocs.io
BSD 3-Clause "New" or "Revised" License
612 stars 62 forks source link

Version 2.2.2 has breaking behaviour #205

Closed frankvdp closed 3 months ago

frankvdp commented 1 year ago

When creating a unit test for a GET request, providing query parameters as data={"key": "value"}, the latest version introduced a json.dumps on the dictionary, resulting in an error like: `

def urlencode(query, doseq=False):
    """
    A version of Python's urllib.parse.urlencode() function that can operate on
    MultiValueDict and non-string values.
    """
    if isinstance(query, MultiValueDict):
        query = query.lists()
    elif hasattr(query, 'items'):
        query = query.items()
    query_params = []
  for key, value in query:

E ValueError: not enough values to unpack (expected 2, got 1)

venv/lib/python3.8/site-packages/django/utils/http.py:111: ValueError`

When pinning to version 2.2.1, this problem is no longer there.

It appears to be caused by the file test_plus/test.py:381 kwargs["data"] = json.dumps(data) if data is not None else None

dhararon commented 1 year ago

I have the same issue. Python 3.11. Django 4.2.2 The uuid type is not supported. if you pass

{
    "id": self.user.pk,
    "name": "Hello"
}

the json.dump return a UUID object is not a valid JSON. but into the version 2.2.1 everything works fine.

KaczuH commented 1 year ago

I've investigated the issue. I've created a pull request. Meanwhile downgrading to v2.2.1 also worked for me.

andres-holvi commented 4 months ago

Any chance of addressing this and doing a release? I see no way of making test-plus work with python 3.12 currently

frankwiles commented 3 months ago

Just released this fix. Good call on the test format @KaczuH, I know I didn't know that dark corner of DRF settings even existed. Thanks!

Apologies for the delay in getting this merged. @andres-holvi does this fix 3.12 for you? I don't directly see how this didn't work with 3.12.