|
1 | | -from datetime import datetime, timedelta |
2 | | -from pycamp_bot.models import Pycamp |
| 1 | +from datetime import datetime |
| 2 | +from pycamp_bot.models import Pycamp, Pycampista, Slot |
3 | 3 | from pycamp_bot.commands import wizard |
4 | | -from test.conftest import use_test_database, test_db, MODELS |
| 4 | +from test.conftest import use_test_database, test_db, MODELS, TEST_END_DATE, TEST_INIT_DATE |
5 | 5 |
|
6 | 6 |
|
7 | 7 | # --------------------------- |
@@ -99,4 +99,71 @@ def test_no_slot_after_last_day_lunch(self): |
99 | 99 |
|
100 | 100 |
|
101 | 101 | class TestDefineWizardsSchedule: |
102 | | - pass |
| 102 | + |
| 103 | + def init_pycamp(self): |
| 104 | + self.pycamp = Pycamp.create( |
| 105 | + headquarters="Narnia", |
| 106 | + init=datetime(2024,6,20), |
| 107 | + end=datetime(2024,6,24), |
| 108 | + ) |
| 109 | + |
| 110 | + # If no wizards, returns {} |
| 111 | + @use_test_database |
| 112 | + def test_no_wizards_then_return_empty_dict(self): |
| 113 | + self.init_pycamp() |
| 114 | + sched = wizard.define_wizards_schedule(self.pycamp) |
| 115 | + assert sched == {} |
| 116 | + |
| 117 | + # all slots are asigned a wizard |
| 118 | + @use_test_database |
| 119 | + def test_all_slots_are_signed_a_wizard(self): |
| 120 | + self.init_pycamp() |
| 121 | + gandalf = Pycampista.create(username="gandalf", wizard=True) |
| 122 | + sched = wizard.define_wizards_schedule(self.pycamp) |
| 123 | + assert all( |
| 124 | + (isinstance(s, Pycampista) and s.wizard) for s in sched.values() |
| 125 | + ) |
| 126 | + |
| 127 | + # Wizards are not asigned to slots when they are busy |
| 128 | + @use_test_database |
| 129 | + def test_all_slots_are_signed_a_wizard(self): |
| 130 | + self.init_pycamp() |
| 131 | + gandalf = Pycampista.create(username="gandalf", wizard=True) |
| 132 | + merlin = Pycampista.create(username="merlin", wizard=True) |
| 133 | + for h in [9, 10, 11, 12]: |
| 134 | + # Create 3 slots where Gandalf is busy |
| 135 | + Slot.create( |
| 136 | + code = "A1", |
| 137 | + start=datetime(2024, 6, 21, h, 30, 0), |
| 138 | + current_wizard=gandalf |
| 139 | + ) |
| 140 | + sched = wizard.define_wizards_schedule(self.pycamp) |
| 141 | + # Verify Gandalf is not assigned to slots where he is busy |
| 142 | + for (ini, end), w in sched.items(): |
| 143 | + if gandalf.is_busy(ini, end): |
| 144 | + print(ini, end, w.username) |
| 145 | + assert w != gandalf |
| 146 | + |
| 147 | + # If all wizards are busy in a slot, then one is asigned all the same |
| 148 | + @use_test_database |
| 149 | + def test_all_slots_are_signed_a_wizard(self): |
| 150 | + self.init_pycamp() |
| 151 | + gandalf = Pycampista.create(username="gandalf", wizard=True) |
| 152 | + merlin = Pycampista.create(username="merlin", wizard=True) |
| 153 | + for h in [9, 10, 11, 12]: |
| 154 | + # Create 3 slots where Gandalf AND Merlin are busy |
| 155 | + Slot.create( |
| 156 | + code = "A1", |
| 157 | + start=datetime(2024, 6, 21, h, 30, 0), |
| 158 | + current_wizard=gandalf |
| 159 | + ) |
| 160 | + Slot.create( |
| 161 | + code = "A1", |
| 162 | + start=datetime(2024, 6, 21, h, 30, 0), |
| 163 | + current_wizard=merlin |
| 164 | + ) |
| 165 | + sched = wizard.define_wizards_schedule(self.pycamp) |
| 166 | + |
| 167 | + assert all( |
| 168 | + (isinstance(s, Pycampista) and s.wizard) for s in sched.values() |
| 169 | + ) |
0 commit comments