|
0
|
1 |
TOKEN_GENERATOR_TESTS = """ |
|
|
2 |
>>> from django.contrib.auth.models import User, AnonymousUser |
|
|
3 |
>>> from django.contrib.auth.tokens import PasswordResetTokenGenerator |
|
|
4 |
>>> from django.conf import settings |
|
|
5 |
>>> u = User.objects.create_user('tokentestuser', 'test2@example.com', 'testpw') |
|
|
6 |
>>> p0 = PasswordResetTokenGenerator() |
|
|
7 |
>>> tk1 = p0.make_token(u) |
|
|
8 |
>>> p0.check_token(u, tk1) |
|
|
9 |
True |
|
|
10 |
|
|
|
11 |
>>> u = User.objects.create_user('comebackkid', 'test3@example.com', 'testpw') |
|
|
12 |
>>> p0 = PasswordResetTokenGenerator() |
|
|
13 |
>>> tk1 = p0.make_token(u) |
|
|
14 |
>>> reload = User.objects.get(username='comebackkid') |
|
|
15 |
>>> tk2 = p0.make_token(reload) |
|
|
16 |
>>> tk1 == tk2 |
|
|
17 |
True |
|
|
18 |
|
|
|
19 |
Tests to ensure we can use the token after n days, but no greater. |
|
|
20 |
Use a mocked version of PasswordResetTokenGenerator so we can change |
|
|
21 |
the value of 'today' |
|
|
22 |
|
|
|
23 |
>>> class Mocked(PasswordResetTokenGenerator): |
|
|
24 |
... def __init__(self, today): |
|
|
25 |
... self._today_val = today |
|
|
26 |
... def _today(self): |
|
|
27 |
... return self._today_val |
|
|
28 |
|
|
|
29 |
>>> from datetime import date, timedelta |
|
|
30 |
>>> p1 = Mocked(date.today() + timedelta(settings.PASSWORD_RESET_TIMEOUT_DAYS)) |
|
|
31 |
>>> p1.check_token(u, tk1) |
|
|
32 |
True |
|
|
33 |
>>> p2 = Mocked(date.today() + timedelta(settings.PASSWORD_RESET_TIMEOUT_DAYS + 1)) |
|
|
34 |
>>> p2.check_token(u, tk1) |
|
|
35 |
False |
|
|
36 |
|
|
|
37 |
""" |