def on_post(self, req: falcon.Request, resp: falcon.Response): for message in req.media: chats = Chat.get_chats_by_token(message.get('token')) for chat in chats: send_message(chat, message.get('text'), message.get('disable_notification')) resp.status = falcon.HTTP_200
def _set_token(message): text_split = message.text.split() if len(text_split) != 2: return token = text_split[1] chat = Chat.set_token(message.chat.id, token) send_message(chat, 'New token {}'.format(chat.token))
def on_get(self, req: falcon.Request, resp: falcon.Response): token = req.params.get('token') if token is None: raise falcon.HTTP_BAD_REQUEST text = req.params.get('text') if text is None: raise falcon.HTTP_BAD_REQUEST disable_notification = req.params.get('disable_notification', False) chats = Chat.get_chats_by_token(token) for chat in chats: send_message(chat, text, disable_notification) resp.status = falcon.HTTP_200
def chat(): return Chat.get_chat(123)
def test_get_chats_by_token(chat): obj = Chat.get_chats_by_token(chat.token) assert chat in obj
def test_get_token(): token = Chat.get_token(123) assert isinstance(token, str) assert len(token) == 32
def test_set_token(random_token): Chat.set_token(123, random_token) chat = Chat.get_chat(123) assert chat.token == random_token
def test_get_chat(): chat = Chat.get_chat(123) assert isinstance(chat, Chat) assert chat.id == 123
def _send_token(message): chat = Chat.get_chat(message.chat.id) send_message(chat, chat.token)