~homeworkprod/byceps

ref: 9f63b62a2b4647a97ebd3b6356d937ffa1d88876 byceps/tests/services/verification_token/test_models.py -rw-r--r-- 1.3 KiB
9f63b62a — Jochen Kupperschmidt Note that Python 3.6 is a supported Python version 4 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
"""
:Copyright: 2006-2017 Jochen Kupperschmidt
:License: Modified BSD, see LICENSE for details.
"""

from datetime import datetime

from freezegun import freeze_time
from nose2.tools import params

from byceps.services.verification_token.models import Purpose

from testfixtures.user import create_user
from testfixtures.verification_token import create_verification_token


@params(
    (
        Purpose.email_address_confirmation,
        datetime(2014, 11, 26, 19, 54, 38),
        False,
    ),
    (
        Purpose.email_address_confirmation,
        datetime(2014, 11, 27, 19, 54, 38),
        False,  # Never expires.
    ),
    (
        Purpose.password_reset,
        datetime(2014, 11, 26, 19, 54, 38),
        False,
    ),
    (
        Purpose.password_reset,
        datetime(2014, 11, 27, 17, 44, 52),
        False,  # Almost, but not yet.
    ),
    (
        Purpose.password_reset,
        datetime(2014, 11, 27, 17, 44, 53),
        True,  # Just now.
    ),
    (
        Purpose.password_reset,
        datetime(2014, 11, 27, 19, 54, 38),
        True,
    ),
)
def test_is_expired(purpose, now, expected):
    user = create_user()
    created_at = datetime(2014, 11, 26, 17, 44, 53)

    token = create_verification_token(user.id, purpose, created_at=created_at)

    with freeze_time(now):
        assert token.is_expired == expected