Skip to content

Commit

Permalink
fix Django 3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
uraniumanchor committed Dec 4, 2023
1 parent 3371ed6 commit 7eca2f1
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 5 deletions.
14 changes: 11 additions & 3 deletions tests/test_auth.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import urllib.parse
from unittest import skipIf

import django
import post_office.models
from django.contrib.auth import get_user_model
from django.test import RequestFactory, TestCase, override_settings
Expand Down Expand Up @@ -70,6 +72,11 @@ def test_register_inactive_user(self):
)
self.assertContains(resp, 'An e-mail has been sent to your address.')

# TODO: remove skip when 3.2 no longer supported
@skipIf(
django.VERSION < (4, 1),
'assertFormError requires response object until Django 4.1',
)
def test_register_active_user(self):
AuthUser.objects.create(
username='existinguser', email='test@email.com', is_active=True
Expand All @@ -78,8 +85,9 @@ def test_register_active_user(self):
reverse('tracker:register'), data={'email': 'test@email.com'}
)
self.assertFormError(
resp,
'form',
resp.context['form'],
'email',
'This email is already registered. Please log in, (or reset your password if you forgot it).',
[
'This email is already registered. Please log in, (or reset your password if you forgot it).'
],
)
9 changes: 8 additions & 1 deletion tests/test_prize.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import datetime
import random
from decimal import Decimal
from unittest import skipIf
from unittest.mock import patch

import django
import post_office.models
import pytz
from dateutil.parser import parse as parse_date
Expand Down Expand Up @@ -1467,6 +1469,11 @@ def test_prize_key_import_action(self):
reverse('admin:tracker_prize_key_import', args=(self.prize_with_keys.id,)),
)

# TODO: remove skip when 3.2 no longer supported
@skipIf(
django.VERSION < (4, 1),
'assertFormError requires response object until Django 4.1',
)
def test_prize_key_import_form(self):
keys = ['dead-beef-dead-beef-123%d' % i for i in range(5)]
response = self.client.get(
Expand Down Expand Up @@ -1521,7 +1528,7 @@ def test_prize_key_import_form(self):
{'keys': keys[0]},
)
self.assertFormError(
response, 'form', 'keys', ['At least one key already exists.']
response.context['form'], 'keys', ['At least one key already exists.']
)

def test_prize_winner_admin(self):
Expand Down
10 changes: 10 additions & 0 deletions tests/test_speedrun.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import datetime
import random
from unittest import skipIf

import django
import pytz
from django.contrib.auth.models import User
from django.core.exceptions import ValidationError
Expand Down Expand Up @@ -313,6 +315,10 @@ def test_start_run(self):
self.assertEqual(self.run1.run_time, '0:41:20')
self.assertEqual(self.run1.setup_time, '0:09:40')

@skipIf(
django.VERSION < (4, 1),
'assertFormError requires response object until Django 4.1',
)
def test_invalid_time(self):
from tracker.admin.forms import StartRunForm

Expand All @@ -329,6 +335,10 @@ def test_invalid_time(self):
self.assertFalse(form.is_valid())
self.assertFormError(form, None, StartRunForm.Errors.invalid_start_time)

@skipIf(
django.VERSION < (4, 1),
'assertFormError requires response object until Django 4.1',
)
def test_anchor_drift(self):
from tracker.admin.forms import StartRunForm

Expand Down
15 changes: 14 additions & 1 deletion tracker/models/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@
from .fields import TimestampField
from .util import LatestEvent

# TODO: remove when 3.10 is oldest supported version

try:
from itertools import pairwise
except ImportError:

def pairwise(iterable):
# pairwise('ABCDEFG') --> AB BC CD DE EF FG
a, b = itertools.tee(iterable)
next(b, None)
return zip(a, b)


__all__ = [
'Event',
'PostbackURL',
Expand Down Expand Up @@ -547,7 +560,7 @@ def clean(self):
'order': 'Next anchor in the order would occur before this one'
}
)
for c, n in itertools.pairwise(
for c, n in pairwise(
itertools.chain(
[self],
SpeedRun.objects.filter(
Expand Down

0 comments on commit 7eca2f1

Please sign in to comment.