~homeworkprod/byceps

ref: 1181a35dd06d48c779208a6d2a4b3672dd38d812 byceps/tests/services/user/test_models_birthday.py -rw-r--r-- 1.0 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
"""
:Copyright: 2006-2017 Jochen Kupperschmidt
:License: Modified BSD, see LICENSE for details.
"""

from datetime import date

from freezegun import freeze_time
import pytest

from testfixtures.user import create_user_with_detail


@pytest.mark.parametrize('today_text, expected', [
    ('2014-03-16',   2),
    ('2014-03-17',   1),
    ('2014-03-18',   0),
    ('2014-03-19', 364),
])
def test_days_until_next_birthday(today_text, expected):
    user = create_user_with_detail(date_of_birth=date(1994, 3, 18))

    with freeze_time(today_text):
        assert user.detail.days_until_next_birthday == expected


@pytest.mark.parametrize('today_text, expected', [
    ('1994-03-17', False),
    ('1994-03-18', True ),
    ('1994-03-19', False),
    ('2014-03-17', False),
    ('2014-03-18', True ),
    ('2014-03-19', False),
])
def test_is_birthday_today(today_text, expected):
    user = create_user_with_detail(date_of_birth=date(1994, 3, 18))

    with freeze_time(today_text):
        assert user.detail.is_birthday_today == expected