|
| 1 | +from datetime import datetime, timedelta |
| 2 | +from pycamp_bot.models import Pycamp |
| 3 | +from pycamp_bot.commands import wizard |
| 4 | +from test.conftest import use_test_database, test_db, MODELS |
| 5 | + |
| 6 | + |
| 7 | +# --------------------------- |
| 8 | +# Module Level Setup/TearDown |
| 9 | +# --------------------------- |
| 10 | +def setup_module(module): |
| 11 | + """setup any state specific to the execution of the given module.""" |
| 12 | + test_db.bind(MODELS, bind_refs=False, bind_backrefs=False) |
| 13 | + test_db.connect() |
| 14 | + |
| 15 | +def teardown_module(module): |
| 16 | + """teardown any state that was previously setup with a setup_module method.""" |
| 17 | + # Not strictly necessary since SQLite in-memory databases only live |
| 18 | + # for the duration of the connection, and in the next step we close |
| 19 | + # the connection...but a good practice all the same. |
| 20 | + test_db.drop_tables(MODELS) |
| 21 | + |
| 22 | + # Close connection to db. |
| 23 | + test_db.close() |
| 24 | + # If we wanted, we could re-bind the models to their original |
| 25 | + # database here. But for tests this is probably not necessary. |
| 26 | + |
| 27 | + |
| 28 | +class TestWizardScheduleSlots: |
| 29 | + |
| 30 | + def init_pycamp(self): |
| 31 | + self.pycamp = Pycamp.create( |
| 32 | + headquarters="Narnia", |
| 33 | + init=datetime(2024,6,20), |
| 34 | + end=datetime(2024,6,24), |
| 35 | + ) |
| 36 | + |
| 37 | + @use_test_database |
| 38 | + def test_correct_number_of_slots_in_one_day(self): |
| 39 | + p = Pycamp.create( |
| 40 | + headquarters="Narnia", |
| 41 | + init=datetime(2024,6,20), |
| 42 | + end=datetime(2024,6,20), |
| 43 | + ) |
| 44 | + slots = wizard.compute_wizards_slots(p) |
| 45 | + assert len(slots) == 0 |
| 46 | + |
| 47 | + @use_test_database |
| 48 | + def test_correct_number_of_slots_in_three_day(self): |
| 49 | + p = Pycamp.create( |
| 50 | + headquarters="Narnia", |
| 51 | + init=datetime(2024,6,20), |
| 52 | + end=datetime(2024,6,22,23,59,59,99), |
| 53 | + ) |
| 54 | + slots = wizard.compute_wizards_slots(p) |
| 55 | + for i in slots: |
| 56 | + print(i) |
| 57 | + assert len(slots) == 20 |
| 58 | + |
| 59 | + |
| 60 | + @use_test_database |
| 61 | + def test_no_slot_before_first_day_lunch(self): |
| 62 | + self.init_pycamp() |
| 63 | + lunch_time_end = datetime( |
| 64 | + self.pycamp.init.year, |
| 65 | + self.pycamp.init.month, |
| 66 | + self.pycamp.init.day, |
| 67 | + wizard.LUNCH_TIME_END_HOUR |
| 68 | + ) |
| 69 | + for (start, end) in wizard.compute_wizards_slots(self.pycamp): |
| 70 | + assert lunch_time_end <= start |
| 71 | + |
| 72 | + @use_test_database |
| 73 | + def test_no_slot_after_coding_time(self): |
| 74 | + self.init_pycamp() |
| 75 | + for (start, _) in wizard.compute_wizards_slots(self.pycamp): |
| 76 | + assert start.hour < wizard.WIZARD_TIME_END_HOUR |
| 77 | + |
| 78 | + @use_test_database |
| 79 | + def test_no_slot_before_breakfast(self): |
| 80 | + self.init_pycamp() |
| 81 | + for (start, _) in wizard.compute_wizards_slots(self.pycamp): |
| 82 | + assert start.hour >= wizard.WIZARD_TIME_START_HOUR |
| 83 | + |
| 84 | + |
| 85 | + |
| 86 | + @use_test_database |
| 87 | + def test_no_slot_after_last_day_lunch(self): |
| 88 | + self.init_pycamp() |
| 89 | + lunch_time_end = datetime( |
| 90 | + self.pycamp.end.year, |
| 91 | + self.pycamp.end.month, |
| 92 | + self.pycamp.end.day, |
| 93 | + wizard.LUNCH_TIME_END_HOUR |
| 94 | + ) |
| 95 | + for (start, _) in wizard.compute_wizards_slots(self.pycamp): |
| 96 | + print(start) |
| 97 | + if start.day == self.pycamp.end.day: |
| 98 | + assert start >= lunch_time_end |
0 commit comments