Skip to content

Commit 80d77c3

Browse files
committed
Cleanup
1 parent 6826bcb commit 80d77c3

File tree

4 files changed

+17
-20
lines changed

4 files changed

+17
-20
lines changed

src/pycamp_bot/commands/wizard.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
WIZARD_TIME_START_HOUR = 9
1616
WIZARD_TIME_END_HOUR = 20
1717

18+
MSG_MAX_LEN = 4096
19+
1820

1921
def is_wizard_time_slot(slot):
2022
return slot[0].hour in range(WIZARD_TIME_START_HOUR, WIZARD_TIME_END_HOUR)
@@ -231,12 +233,17 @@ async def schedule_wizards(update, context):
231233
agenda = WizardAtPycamp.select().where(WizardAtPycamp.pycamp == pycamp)
232234

233235
msg = format_wizards_schedule(agenda)
234-
235-
await context.bot.send_message(
236-
chat_id=update.message.chat_id,
237-
text=msg,
238-
parse_mode="MarkdownV2"
239-
)
236+
try:
237+
await context.bot.send_message(
238+
chat_id=update.message.chat_id,
239+
text=msg,
240+
parse_mode="MarkdownV2"
241+
)
242+
except BadRequest as e:
243+
m = "Coulnd't return the Wizards list to the admin. ".format(update.message.from_user.username)
244+
if len(msg) >= MSG_MAX_LEN:
245+
m += "The message is too long. Check the data in the DB ;-)"
246+
logger.exception(m)
240247

241248

242249
def format_wizards_schedule(agenda):

src/pycamp_bot/models.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ class Pycamp(BaseModel):
6060
end: time of end
6161
vote_authorized: the vote is auth in this pycamp
6262
project_load_authorized: the project load is auth in this pycamp
63+
active: boolean telling wheter this PyCamp instance is active (or an old one)
64+
wizard_slot_duration: config to compute the schedule of mages
6365
'''
6466
headquarters = pw.CharField(unique=True)
6567
init = pw.DateTimeField(null=True)

test/conftest.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,19 @@
33
from datetime import datetime
44
from functools import wraps
55
from peewee import SqliteDatabase
6-
import pytest
76
from telegram import Bot
87

98
from pycamp_bot.models import Pycampista, Slot, Pycamp, WizardAtPycamp
109

1110

12-
13-
bot = Bot(token=os.environ['TOKEN'])
14-
15-
1611
# use an in-memory SQLite for tests.
1712
test_db = SqliteDatabase(':memory:')
1813

1914
MODELS = [Pycampista, Slot, Pycamp, WizardAtPycamp]
2015

2116

22-
# Bind the given models to the db for the duration of wrapped block.
2317
def use_test_database(fn):
18+
"""Bind the given models to the db for the duration of wrapped block."""
2419
@wraps(fn)
2520
def inner(self):
2621
with test_db.bind_ctx(MODELS):
@@ -30,7 +25,3 @@ def inner(self):
3025
finally:
3126
test_db.drop_tables(MODELS)
3227
return inner
33-
34-
35-
TEST_INIT_DATE = datetime(2024, 6, 20, 0, 0, 0)
36-
TEST_END_DATE = datetime(2024, 6, 24, 23, 59, 59, 99999)

test/test_wizard.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
from datetime import datetime
22
from pycamp_bot.models import Pycamp, Pycampista, Slot
33
from pycamp_bot.commands import wizard
4-
from test.conftest import use_test_database, test_db, MODELS, TEST_END_DATE, TEST_INIT_DATE
4+
from test.conftest import use_test_database, test_db, MODELS
55

66

7-
# ---------------------------
8-
# Module Level Setup/TearDown
9-
# ---------------------------
107
def setup_module(module):
118
"""setup any state specific to the execution of the given module."""
129
test_db.bind(MODELS, bind_refs=False, bind_backrefs=False)

0 commit comments

Comments
 (0)