~homeworkprod/byceps

ref: 1181a35dd06d48c779208a6d2a4b3672dd38d812 byceps/tests/services/verification_token/test_models.py -rw-r--r-- 1.4 KiB
1181a35d — Jochen Kupperschmidt Ported tests from nose2 to pytest 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
import pytest

from byceps.services.verification_token.models import Purpose

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


@pytest.mark.parametrize('purpose, now, expected', [
    (
        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