Skip to content

Commit 72e5b96

Browse files
committed
added some functional tests
1 parent b604dbd commit 72e5b96

File tree

3 files changed

+45
-12
lines changed

3 files changed

+45
-12
lines changed

test/conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
from peewee import SqliteDatabase
66
from telegram import Bot
77

8-
from pycamp_bot.models import Pycampista, Slot, Pycamp, WizardAtPycamp
8+
from pycamp_bot.models import Pycampista, Slot, Pycamp, WizardAtPycamp, PycampistaAtPycamp
99

1010

1111
# use an in-memory SQLite for tests.
1212
test_db = SqliteDatabase(':memory:')
1313

14-
MODELS = [Pycampista, Slot, Pycamp, WizardAtPycamp]
14+
MODELS = [Pycampista, Slot, Pycamp, WizardAtPycamp, PycampistaAtPycamp]
1515

1616

1717
def use_test_database(fn):

test/test_pycamp_model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def test_returns_correct_wizard_within_its_turno(self):
4242
init=datetime(2024,6,20),
4343
end=datetime(2024,6,23),
4444
)
45-
pycamper = Pycampista.create(username="pepe", wizard=True)
45+
pycamper = p.add_wizard("pepe", 123)
4646
wizard.persist_wizards_schedule_in_db(p)
4747

4848
assert p.get_current_wizard() == pycamper

test/test_wizard.py

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def teardown_module(module):
2222
# database here. But for tests this is probably not necessary.
2323

2424

25-
class TestWizardScheduleSlots:
25+
class BaseForOtherWizardsTests:
2626

2727
def init_pycamp(self):
2828
self.pycamp = Pycamp.create(
@@ -31,6 +31,8 @@ def init_pycamp(self):
3131
end=datetime(2024,6,24),
3232
)
3333

34+
35+
class TestWizardScheduleSlots(BaseForOtherWizardsTests):
3436
@use_test_database
3537
def test_correct_number_of_slots_in_one_day(self):
3638
p = Pycamp.create(
@@ -95,14 +97,7 @@ def test_no_slot_after_last_day_lunch(self):
9597
assert start >= lunch_time_end
9698

9799

98-
class TestDefineWizardsSchedule:
99-
100-
def init_pycamp(self):
101-
self.pycamp = Pycamp.create(
102-
headquarters="Narnia",
103-
init=datetime(2024,6,20),
104-
end=datetime(2024,6,24),
105-
)
100+
class TestDefineWizardsSchedule(BaseForOtherWizardsTests):
106101

107102
# If no wizards, returns {}
108103
@use_test_database
@@ -164,3 +159,41 @@ def test_all_slots_are_signed_a_wizard(self):
164159
assert all(
165160
(isinstance(s, Pycampista) and s.wizard) for s in sched.values()
166161
)
162+
163+
class TestListWizards(BaseForOtherWizardsTests):
164+
165+
@use_test_database
166+
def test_wizard_registration(self):
167+
self.init_pycamp()
168+
w = self.pycamp.add_wizard("Gandalf", 123)
169+
wizards = self.pycamp.get_wizards()
170+
assert len(wizards) == 1
171+
assert w.username == wizards[0].username
172+
173+
174+
@use_test_database
175+
def test_wizard_registration_works_in_one_pycamp_only(self):
176+
self.init_pycamp()
177+
self.pycamp.add_wizard("Gandalf", 123)
178+
179+
other_pycamp = Pycamp.create(
180+
headquarters="Mordor",
181+
init=datetime(2025,3,22),
182+
end=datetime(2025,3,24),
183+
)
184+
w = other_pycamp.add_wizard("Merlin", 456)
185+
#import ipdb; ipdb.set_trace()
186+
results = other_pycamp.get_wizards()
187+
assert len(results) == 1
188+
assert w.username == results[0].username
189+
190+
191+
# @use_test_database
192+
# def test_no_active_pycamp_then_fail(self):
193+
# self.init_pycamp()
194+
# agregarle un mago
195+
196+
# creo OTRO Pycamp
197+
# agregarle otro mago
198+
199+
# pedir listado: check está el OTRO mago solamente

0 commit comments

Comments
 (0)