~homeworkprod/byceps

ref: 9f63b62a2b4647a97ebd3b6356d937ffa1d88876 byceps/tests/services/shop/article/models/test_article_availability.py -rw-r--r-- 2.6 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
"""
: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 testfixtures.shop_article import create_article


@params(
    (datetime(2014,  4,  8, 12,  0,  0), False),
    (datetime(2014,  9, 15, 17, 59, 59), False),
    (datetime(2014,  9, 15, 18,  0,  0), True ),
    (datetime(2014,  9, 19, 15,  0,  0), True ),
    (datetime(2014,  9, 23, 17, 59, 59), True ),
    (datetime(2014,  9, 23, 18,  0,  0), False),
    (datetime(2014, 11,  4, 12,  0,  0), False),
)
def test_is_available_with_start_and_end(now, expected):
    article = create_article(
        available_from=datetime(2014, 9, 15, 18, 0, 0),
        available_until=datetime(2014, 9, 23, 18, 0, 0))

    with freeze_time(now):
        assert article.is_available == expected


@params(
    (datetime(2014,  4,  8, 12,  0,  0), False),
    (datetime(2014,  9, 15, 17, 59, 59), False),
    (datetime(2014,  9, 15, 18,  0,  0), True ),
    (datetime(2014,  9, 19, 15,  0,  0), True ),
    (datetime(2014,  9, 23, 17, 59, 59), True ),
    (datetime(2014,  9, 23, 18,  0,  0), True ),
    (datetime(2014, 11,  4, 12,  0,  0), True ),
)
def test_is_available_with_start_and_without_end(now, expected):
    article = create_article(
        available_from=datetime(2014, 9, 15, 18, 0, 0),
        available_until=None)

    with freeze_time(now):
        assert article.is_available == expected


@params(
    (datetime(2014,  4,  8, 12,  0,  0), True ),
    (datetime(2014,  9, 15, 17, 59, 59), True ),
    (datetime(2014,  9, 15, 18,  0,  0), True ),
    (datetime(2014,  9, 19, 15,  0,  0), True ),
    (datetime(2014,  9, 23, 17, 59, 59), True ),
    (datetime(2014,  9, 23, 18,  0,  0), False),
    (datetime(2014, 11,  4, 12,  0,  0), False),
)
def test_is_available_without_start_and_with_end(now, expected):
    article = create_article(
        available_from=None,
        available_until=datetime(2014, 9, 23, 18, 0, 0))

    with freeze_time(now):
        assert article.is_available == expected


@params(
    (datetime(2014,  4,  8, 12,  0,  0), True ),
    (datetime(2014,  9, 15, 17, 59, 59), True ),
    (datetime(2014,  9, 15, 18,  0,  0), True ),
    (datetime(2014,  9, 19, 15,  0,  0), True ),
    (datetime(2014,  9, 23, 17, 59, 59), True ),
    (datetime(2014,  9, 23, 18,  0,  0), True ),
    (datetime(2014, 11,  4, 12,  0,  0), True ),
)
def test_is_available_without_start_and_without_end(now, expected):
    article = create_article(
        available_from=None,
        available_until=None)

    with freeze_time(now):
        assert article.is_available == expected