async def test_report_cmd(client: TelegramClient): """Tests the /report command Args: client (TelegramClient): client used to simulate the user """ conv: Conversation async with client.conversation(bot_tag, timeout=TIMEOUT) as conv: await conv.send_message("/report") # send a command resp: Message = await conv.get_response() assert resp.text commands = ("/report Test", "/report Test Report") for command in commands: await conv.send_message(command) # send a command resp: Message = await conv.get_response() assert resp.text resp: Message = await conv.get_response() assert resp.text
async def test_rappresentanti_buttons(client: TelegramClient): """Tests all the buttons in the rappresentanti sub-menu Args: client (TelegramClient): client used to simulate the user """ conv: Conversation async with client.conversation(bot_tag, timeout=TIMEOUT) as conv: buttons = ( "md_rappresentanti_dmi", "md_rappresentanti_informatica", "md_rappresentanti_matematica", ) for button in buttons: await conv.send_message("/help") # send a command resp: Message = await conv.get_response() assert resp.text await resp.click(data="sm_rapp_menu" ) # click the "ЁЯСе Rappresentanti" button resp: Message = await conv.get_edit() await resp.click(data=button) resp: Message = await conv.get_edit() assert resp.text
async def test_aulario_cmd(client: TelegramClient): """Tests the /aulario command Args: client (TelegramClient): client used to simulate the user """ conv: Conversation async with client.conversation(bot_tag, timeout=TIMEOUT) as conv: await conv.send_message("/aulario") # send a command resp: Message = await conv.get_response() assert resp.text if "тЪая╕П" in resp.text: return await resp.click(text=f"{datetime.now().day}") # click the button resp: Message = await conv.get_response() assert resp.text await resp.click(data="sm_aulario") # click the button resp: Message = await conv.get_edit() assert resp.text
async def test_fail_conversation(client: TelegramClient): """Tests the create conversation when the user inputs some invalid text when asked for the image Args: client (TelegramClient): client used to simulate the user """ conv: Conversation async with client.conversation(bot_tag, timeout=TIMEOUT) as conv: await conv.send_message("/create") # send a command resp: Message = await conv.get_response() await resp.click(text="DMI") # click inline keyboard resp: Message = await conv.get_edit() await conv.send_message("Test titolo") # send a message resp: Message = await conv.get_response() await conv.send_message("Test descrizione") # send a message resp: Message = await conv.get_response() await resp.click(text="Ridimensiona") # click inline keyboard resp: Message = await conv.get_edit() await conv.send_message("Fail message") # send a message resp: Message = await conv.get_response() assert read_md("fail") == get_telegram_md(resp.text) await conv.send_message("/cancel") # send a command resp: Message = await conv.get_response() assert read_md("cancel") == get_telegram_md(resp.text)
async def test_start_cmd(client: TelegramClient): """Tests the start command Args: client (TelegramClient): client used to simulate the user """ conv: Conversation async with client.conversation(bot_tag, timeout=TIMEOUT) as conv: await conv.send_message("/start") # send a command resp: Message = await conv.get_response() assert read_md("start") == get_telegram_md(resp.text)
async def test_create_random_thread_conversation(client: TelegramClient): """Tests the whole flow of the create conversation with the user provided image The image creation is handled by the main thread Args: client (TelegramClient): client used to simulate the user """ config_map['image']['thread'] = True conv: Conversation async with client.conversation(bot_tag, timeout=TIMEOUT * 2) as conv: await conv.send_message("/create") # send a command resp: Message = await conv.get_response() assert read_md("create") == get_telegram_md(resp.text) await resp.click(text="DMI") # click inline keyboard resp: Message = await conv.get_edit() assert read_md("template") == get_telegram_md(resp.text) await conv.send_message("Test titolo") # send a message resp: Message = await conv.get_response() assert read_md("title") == get_telegram_md(resp.text) await conv.send_message("Test descrizione") # send message resp: Message = await conv.get_response() assert read_md("caption") == get_telegram_md(resp.text) await resp.click(text="Mi sento 🍀") # click inline keyboard resp: Message = await conv.get_edit() assert read_md("resize_mode") == get_telegram_md(resp.text) await conv.send_message("none") # send message resp: Message = await conv.get_response() assert read_md("background") == get_telegram_md(resp.text) resp: Message = await conv.get_response() assert resp.photo is not None await resp.click(text="No, ritenta") # click inline keyboard resp: Message = await conv.get_response() assert resp.photo is not None await resp.click(text="Si") # click inline keyboard resp: Message = await conv.get_edit() assert resp.photo is not None
async def test_create_scale_crop_conversation(client: TelegramClient): """Tests the whole flow of the create conversation with the user provided image The image creation is handled by the main thread Args: client (TelegramClient): client used to simulate the user """ config_map['image']['thread'] = False conv: Conversation async with client.conversation(bot_tag, timeout=TIMEOUT * 2) as conv: await conv.send_message("/create") # send a command resp: Message = await conv.get_response() assert read_md("create") == get_telegram_md(resp.text) await resp.click(text="DMI") # click inline keyboard resp: Message = await conv.get_edit() assert read_md("template") == get_telegram_md(resp.text) await conv.send_message("Test titolo") # send a message resp: Message = await conv.get_response() assert read_md("title") == get_telegram_md(resp.text) await conv.send_message("Test descrizione") # send message resp: Message = await conv.get_response() assert read_md("caption") == get_telegram_md(resp.text) await resp.click(2) # click inline keyboard (Ridimensiona & Ritaglia) resp: Message = await conv.get_edit() assert read_md("resize_mode") == get_telegram_md(resp.text) await conv.send_file("data/img/bg_test.png") # send message resp: Message = await conv.get_response() assert read_md("background") == get_telegram_md(resp.text) resp: Message = await conv.get_response() assert resp.photo is not None await resp.click(text="⬆️") # click inline keyboard resp: Message = await conv.get_response() assert resp.photo is not None await resp.click(text="Genera") # click inline keyboard resp: Message = await conv.get_edit() assert resp.photo is not None
async def worker(loop): api_id = os.environ['TLGM_API_ID'] api_hash = os.environ['TLGM_API_HASH'] api_session = os.environ['TLGM_SESSION'] entity = os.environ['TLGM_ENTITY'] message = os.environ['TLGM_MESSAGE'] client = TelegramClient(StringSession(api_session), api_id, api_hash, loop=loop) await client.connect() async with client.conversation(entity=entity) as conv: await conv.send_message(message) response = await conv.get_response() logging.info(response.text) await conv.mark_read()
async def test_prof_cmd(client: TelegramClient): """Tests the /prof command Args: client (TelegramClient): client used to simulate the user """ conv: Conversation async with client.conversation(bot_tag, timeout=TIMEOUT) as conv: commands = ("/prof", "/prof bilotta", "/prof giuseppe bilotta", "/prof rocco senteta") for command in commands: await conv.send_message(command) # send a command resp: Message = await conv.get_response() assert resp.text
async def test_rappresentanti_cmd(client: TelegramClient): """Tests the /rappresentanti command Args: client (TelegramClient): client used to simulate the user """ conv: Conversation async with client.conversation(bot_tag, timeout=TIMEOUT) as conv: commands = ("/rappresentanti", "/rappresentanti_dmi", "/rappresentanti_informatica", "/rappresentanti_matematica") for command in commands: await conv.send_message(command) # send a command resp: Message = await conv.get_response() assert resp.text
async def test_help_cmd(client: TelegramClient): """Tests the rappresentanti command Args: client (TelegramClient): client used to simulate the user """ conv: Conversation async with client.conversation(bot_tag, timeout=TIMEOUT) as conv: await conv.send_message("/help") # send a command resp: Message = await conv.get_response() assert "@DMI_Bot risponde ai seguenti comandi:" == resp.text await resp.click(text="📖 Esami (link)" ) # click "📖 Esami (link)" inline button resp: Message = await conv.get_edit() assert read_md("esami_link") == get_telegram_md(resp.text)
async def test_regolamentodidattico_cmd(client: TelegramClient): """Tests the /regolamentodidattico command Args: client (TelegramClient): client used to simulate the user """ conv: Conversation async with client.conversation(bot_tag, timeout=TIMEOUT) as conv: buttons = ( "reg_button_triennale_L31", "reg_button_triennale_L35", "reg_button_magistrale_LM18", "reg_button_magistrale_LM40", ) for button in buttons: await conv.send_message("/regolamentodidattico") # send a command resp: Message = await conv.get_response() assert resp.text await resp.click(data=button) # click the button resp = await conv.get_edit() assert resp.text class_num = button.split('_')[-1] rule_button_text = "Regolamento Didattico 2020/2021_{}".format( class_num) await resp.click(data=rule_button_text ) # click "Regolamento" button resp = await conv.get_edit() assert resp.text resp = await conv.get_response() assert resp.document
async def test_help_buttons(client: TelegramClient): """Tests all the md buttons in the help command Args: client (TelegramClient): client used to simulate the user """ conv: Conversation async with client.conversation(bot_tag, timeout=TIMEOUT) as conv: buttons = ( "md_esami_link", "md_lezioni_link", "md_professori", "md_biblioteca", "md_gruppi", "md_cus", "md_cloud", "md_sdidattica", "md_studenti", "md_cea", "md_ersu", "md_ufficioersu", "md_urp", "md_drive", "md_gitlab", "md_opismanager", "md_contributors", "md_help", "exit_cmd", ) for button in buttons: await conv.send_message("/help") # send a command resp: Message = await conv.get_response() assert resp.text await resp.click(data=button) # click the inline button resp: Message = await conv.get_edit() assert resp.text
async def test_templates_conversation(client: TelegramClient): """Tests the selection of all the possible templates in the create conversation Args: client (TelegramClient): client used to simulate the user """ conv: Conversation async with client.conversation(bot_tag, timeout=TIMEOUT) as conv: for template in ('Vuoto', 'DMI', 'Informatica', 'Matematica'): await conv.send_message("/create") # send a command resp: Message = await conv.get_response() await resp.click( text=template ) # click inline keyboard (Vuoto, DMI, Informatica, Matematica) resp: Message = await conv.get_edit() assert read_md("template") == get_telegram_md(resp.text) await conv.send_message("/cancel") # send a command resp: Message = await conv.get_response() assert read_md("cancel") == get_telegram_md(resp.text)
async def test_settings_cmd(client: TelegramClient): """Tests the settings command Args: client (TelegramClient): client used to simulate the user """ config_map['image']['blur'] = config_map['image'][ 'font_size_title'] = config_map['image']['font_size_caption'] = 30 conv: Conversation async with client.conversation(bot_tag, timeout=TIMEOUT) as conv: for button_index in (1, 2, 3): await conv.send_message("/settings") # send a command resp: Message = await conv.get_response() assert read_md("settings") == get_telegram_md(resp.text) await resp.click( button_index ) # click inline keyboard (Sfocatura, Dimensioni testo, Caratteri per linea) resp: Message = await conv.get_edit() assert read_md("settings") == get_telegram_md(resp.text) await resp.click(text="➕") # click inline keyboard (➕) resp: Message = await conv.get_edit() assert read_md("settings") == get_telegram_md(resp.text) await resp.click(text="➖") # click inline keyboard (➖) resp: Message = await conv.get_edit() assert read_md("settings") == get_telegram_md(resp.text) await resp.click(text="Chiudi") # click inline keyboard (Chiudi) resp: Message = await conv.get_edit() assert 30 == config_map['image']['blur'] == \ config_map['image']['font_size_title'] == \ config_map['image']['font_size_caption']
async def test_lezioni_cmd(client: TelegramClient): """Tests all the possible options in the /lezioni command Args: client (TelegramClient): client used to simulate the user """ conv: Conversation async with client.conversation(bot_tag, timeout=TIMEOUT) as conv: await conv.send_message("/lezioni") # send a command resp: Message = await conv.get_response() assert resp.text buttons = ( "sm_lezioni_button_anno", "lezioni_button_anno_1 anno", "sm_lezioni_button_giorno", "lezioni_button_giorno_1 giorno", "sm_lezioni_button_insegnamento", ) for button in buttons: await resp.click(data=button) # click the button resp: Message = await conv.get_edit() assert resp.text await conv.send_message("nome: programmazione") # send a message resp: Message = await conv.get_response() assert resp.text await resp.click(data="lezioni_button_search" ) # click the "Cerca" button resp: Message = await conv.get_edit() assert resp.text
async def test_regolamentodidattico_cmd(client: TelegramClient): """Tests the /regolamentodidattico command Args: client (TelegramClient): client used to simulate the user """ conv: Conversation async with client.conversation(bot_tag, timeout=TIMEOUT) as conv: await conv.send_message("/regolamentodidattico") # send a command resp: Message = await conv.get_response() assert resp.text buttons = ( "reg_button_triennale", "reg_button_home", "reg_button_magistrale", ) for button in buttons: await resp.click(data=button) # click the button resp: Message = await conv.get_edit() assert resp.text await resp.click(data="Regolamento Didattico 2020/2021_m" ) # click "Regolamento" button resp: Message = await conv.get_edit() assert resp.text resp: Message = await conv.get_response() assert resp.document