api: test drf tz awareness errors in serializer datetimefield filters (#64305)

This commit is contained in:
Paul Marillonnet 2022-04-21 18:25:14 +02:00
parent 17eb53dc24
commit 503a983320
1 changed files with 22 additions and 7 deletions

View File

@ -2050,10 +2050,20 @@ def test_filter_users_by_last_modification(app, admin, simple_user, freezer):
simple_user.save()
# AmbiguousTimeError
resp = app.get('/api/users/', params={'modified__gt': '2019-10-27T02:58:07'})
assert len(resp.json['results']) == 2
resp = app.get('/api/users/', params={'modified__lt': '2019-10-27T02:58:07'})
if django.VERSION[0] <= 2:
resp = app.get('/api/users/', params={'modified__gt': '2019-10-27T02:58:07'})
assert len(resp.json['results']) == 2
resp = app.get('/api/users/', params={'modified__lt': '2019-10-27T02:58:07'})
assert len(resp.json['results']) == 0
else:
# django 3 (justifiably) fails on tz-naive datetimes
app.get('/api/users/', params={'modified__gt': '2019-10-27T02:58:07'}, status=400)
app.get('/api/users/', params={'modified__lt': '2019-10-27T02:58:07'}, status=400)
# of course, tz-aware datetimes work with all supported django versions
resp = app.get('/api/users/', params={'modified__gt': '2019-10-27T02:58:07+00:00'})
assert len(resp.json['results']) == 0
resp = app.get('/api/users/', params={'modified__lt': '2019-10-27T02:58:07+00:00'})
assert len(resp.json['results']) == 2
def test_filter_member_users_by_last_modification(app, admin, simple_user, simple_role, freezer):
@ -2068,10 +2078,15 @@ def test_filter_member_users_by_last_modification(app, admin, simple_user, simpl
simple_user.save()
# AmbiguousTimeError
resp = app.get(url, params={'modified__gt': '2019-10-27T02:58:07'})
assert len(resp.json['results']) == 2
resp = app.get(url, params={'modified__lt': '2019-10-27T02:58:07'})
assert len(resp.json['results']) == 0
if django.VERSION[0] <= 2:
resp = app.get(url, params={'modified__gt': '2019-10-27T02:58:07'})
assert len(resp.json['results']) == 2
resp = app.get(url, params={'modified__lt': '2019-10-27T02:58:07'})
assert len(resp.json['results']) == 0
else:
# XXX handle tz-aware requests
app.get(url, params={'modified__gt': '2019-10-27T02:58:07'}, status=400)
app.get(url, params={'modified__lt': '2019-10-27T02:58:07'}, status=400)
def test_free_text_search(app, admin, settings):