File size: 5,548 Bytes
bff9db3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
"""
単体テスト: models/schedule.py (ShiftRequest, SchedulePeriod)
品質特性: 機能適合性(ISO/IEC 25010 §4.2.1)
テストレベル: 単体テスト
"""
import pytest
from datetime import date
from models.schedule import ShiftRequest, ShiftAssignment, SchedulePeriod
from utils.constants import TimeSlot, Position


class TestShiftRequestSlotCoverage:
    """breakfast / dinner プロパティ(スロットカバー判定)"""

    def test_b_std_covers_breakfast_only(self):
        req = ShiftRequest(employee_id=1, date="2025-01-01", pattern_id="b_std")
        assert req.breakfast is True
        assert req.dinner is False

    def test_d_std1_covers_dinner_only(self):
        req = ShiftRequest(employee_id=1, date="2025-01-01", pattern_id="d_std1")
        assert req.breakfast is False
        assert req.dinner is True

    def test_double_covers_both(self):
        req = ShiftRequest(employee_id=1, date="2025-01-01", pattern_id="double")
        assert req.breakfast is True
        assert req.dinner is True

    def test_no_pattern_covers_none(self):
        req = ShiftRequest(employee_id=1, date="2025-01-01", pattern_id=None)
        assert req.breakfast is False
        assert req.dinner is False

    def test_am_only_covers_breakfast(self):
        req = ShiftRequest(employee_id=1, date="2025-01-01", pattern_id="am_only")
        assert req.breakfast is True
        assert req.dinner is False

    def test_pm_only_covers_dinner(self):
        req = ShiftRequest(employee_id=1, date="2025-01-01", pattern_id="pm_only")
        assert req.breakfast is False
        assert req.dinner is True

    def test_custom_breakfast_hours(self):
        req = ShiftRequest(
            employee_id=1, date="2025-01-01",
            pattern_id="custom",
            custom_start="06:00", custom_end="11:00",
        )
        assert req.breakfast is True
        assert req.dinner is False

    def test_custom_dinner_hours(self):
        req = ShiftRequest(
            employee_id=1, date="2025-01-01",
            pattern_id="custom",
            custom_start="17:00", custom_end="23:00",
        )
        assert req.breakfast is False
        assert req.dinner is True

    def test_custom_missing_times_covers_none(self):
        req = ShiftRequest(
            employee_id=1, date="2025-01-01",
            pattern_id="custom",
        )
        assert req.breakfast is False
        assert req.dinner is False

    def test_unknown_pattern_id_covers_none(self):
        req = ShiftRequest(employee_id=1, date="2025-01-01", pattern_id="nonexistent")
        assert req.breakfast is False
        assert req.dinner is False


class TestShiftRequestHasShift:
    def test_with_pattern_has_shift(self):
        req = ShiftRequest(employee_id=1, date="2025-01-01", pattern_id="b_std")
        assert req.has_shift is True

    def test_without_pattern_no_shift(self):
        req = ShiftRequest(employee_id=1, date="2025-01-01", pattern_id=None)
        assert req.has_shift is False

    def test_empty_string_pattern_no_shift(self):
        req = ShiftRequest(employee_id=1, date="2025-01-01", pattern_id="")
        assert req.has_shift is False


class TestShiftRequestDisplayTime:
    def test_custom_displays_times(self):
        req = ShiftRequest(
            employee_id=1, date="2025-01-01",
            pattern_id="custom",
            custom_start="09:00", custom_end="15:00",
        )
        assert req.display_time() == "09:00〜15:00"

    def test_custom_missing_start(self):
        req = ShiftRequest(
            employee_id=1, date="2025-01-01",
            pattern_id="custom",
            custom_end="15:00",
        )
        assert "?" in req.display_time()

    def test_known_pattern_returns_range(self):
        req = ShiftRequest(employee_id=1, date="2025-01-01", pattern_id="b_std")
        assert req.display_time() == "06:30〜11:30"

    def test_no_pattern_returns_empty(self):
        req = ShiftRequest(employee_id=1, date="2025-01-01", pattern_id=None)
        assert req.display_time() == ""


class TestSchedulePeriodDateRange:
    """date_range() の日付リスト生成"""

    def test_single_day(self):
        period = SchedulePeriod(id=1, start_date="2025-01-01", end_date="2025-01-01")
        dates = period.date_range()
        assert len(dates) == 1
        assert dates[0] == date(2025, 1, 1)

    def test_three_days(self):
        period = SchedulePeriod(id=1, start_date="2025-01-01", end_date="2025-01-03")
        dates = period.date_range()
        assert len(dates) == 3
        assert dates[0] == date(2025, 1, 1)
        assert dates[-1] == date(2025, 1, 3)

    def test_cross_month(self):
        # 1/30〜2/3 → 5日間
        period = SchedulePeriod(id=1, start_date="2025-01-30", end_date="2025-02-03")
        dates = period.date_range()
        assert len(dates) == 5
        assert dates[0] == date(2025, 1, 30)
        assert dates[-1] == date(2025, 2, 3)

    def test_full_month_january(self):
        period = SchedulePeriod(id=1, start_date="2025-01-01", end_date="2025-01-31")
        assert len(period.date_range()) == 31

    def test_result_is_sorted_ascending(self):
        period = SchedulePeriod(id=1, start_date="2025-03-01", end_date="2025-03-07")
        dates = period.date_range()
        assert dates == sorted(dates)

    def test_returns_date_objects(self):
        period = SchedulePeriod(id=1, start_date="2025-06-01", end_date="2025-06-02")
        for d in period.date_range():
            assert isinstance(d, date)