-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathtest_pycamp_model.py
More file actions
76 lines (63 loc) · 2.61 KB
/
test_pycamp_model.py
File metadata and controls
76 lines (63 loc) · 2.61 KB
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
from datetime import datetime
from freezegun import freeze_time
from pycamp_bot.models import Pycamp, Pycampista, WizardAtPycamp
from pycamp_bot.commands import wizard
from test.conftest import use_test_database, test_db, MODELS
# ---------------------------
# Module Level Setup/TearDown
# ---------------------------
def setup_module(module):
test_db.bind(MODELS, bind_refs=False, bind_backrefs=False)
test_db.connect()
def teardown_module(module):
# Not strictly necessary since SQLite in-memory databases only live
# for the duration of the connection, and in the next step we close
# the connection...but a good practice all the same.
test_db.drop_tables(MODELS)
# Close connection to db.
test_db.close()
# If we wanted, we could re-bind the models to their original
# database here. But for tests this is probably not necessary.
class TestPycampGetCurrentWizard:
def init_pycamp(self):
self.pycamp = Pycamp.create(
headquarters="Narnia",
init=datetime(2024, 6, 20),
end=datetime(2024, 6, 24),
)
@use_test_database
@freeze_time("2024-06-21 11:30:00")
def test_returns_correct_wizard_within_its_turno(self):
"""Integration test using persist_wizards_schedule_in_db."""
p = Pycamp.create(
headquarters="Narnia",
init=datetime(2024,6,20),
end=datetime(2024,6,23),
)
pycamper = p.add_wizard("pepe", 123)
wizard.persist_wizards_schedule_in_db(p)
assert p.get_current_wizard() == pycamper
@use_test_database
def test_no_scheduled_wizard_then_return_none(self):
p = Pycamp.create(
headquarters="Narnia"
)
# Wizard exists, but no time scheduled.
pycamper = Pycampista.create(username="pepe", wizard=True)
assert WizardAtPycamp.select().count() == 0
assert p.get_current_wizard() is None
@use_test_database
@freeze_time("2024-06-20 10:30:00")
def test_many_scheduled_wizard_then_return_one_of_them(self):
p = Pycamp.create(
headquarters="Narnia"
)
# Wizard exists, scheduled in the same time slot.
gandalf = Pycampista.create(username="gandalf", wizard=True)
merlin = Pycampista.create(username="merlin", wizard=True)
ini = datetime(2024,6,20,10,0,0)
end = datetime(2024,6,20,11,0,0)
WizardAtPycamp.create(pycamp=p, wizard=gandalf, init=ini, end=end)
WizardAtPycamp.create(pycamp=p, wizard=merlin, init=ini, end=end)
w = p.get_current_wizard()
assert w == gandalf or w == merlin