diff --git a/src/bot_quake.py b/src/bot_quake.py index 4d46993..17b3e1c 100644 --- a/src/bot_quake.py +++ b/src/bot_quake.py @@ -21,13 +21,13 @@ async def file_reader(update, context) -> None: # instanzio la zona di interesse ovvero massimo e minimo di latitudine e longitudine zona = ZoneMap() - # Imposto la magnitudo massima che non deve superare 10, questa potra massima_magnitudo = 10 if update.message.text is None: - comandi = "" - else: + await update.message.reply_text(MENU) + return + if update.message.text is not None: comandi = update.message.text # Adesso il comando passato è diviso e ne posso gestire le eventuali funzionalità splitted_command = comandi.split() diff --git a/tests/test_functions.py b/tests/test_functions.py index 072c384..ee5200e 100644 --- a/tests/test_functions.py +++ b/tests/test_functions.py @@ -224,6 +224,63 @@ async def test_handle_message(mocker: MockerFixture): ) # vediamo se la funzione mockata viene invocata e con quali parametri + +@pytest.mark.asyncio +async def test_file_reader_with_range_error(mocker: MockerFixture): + """Effettua il test della funzione test_file_reader""" + + update = mocker.AsyncMock() + update.message.text = ( + "recente 20" # col mock possiamo presettare un valore che ci serve + ) + + update.message.reply_text = mocker.AsyncMock() + + await bot_quake.file_reader( + update, None + ) # invochiamo la funzione che al suo interno invoca update.message.reply_text + + update.message.reply_text.assert_called_once_with( + "Inserire un numero da 1 a 10" + ) # vediamo se la funzione mockata viene invocata e con quali parametri + +@pytest.mark.asyncio +async def test_file_reader_with_type_error(mocker: MockerFixture): + """Effettua il test della funzione test_file_reader""" + + update = mocker.AsyncMock() + update.message.text = ( + "recente a" # col mock possiamo presettare un valore che ci serve + ) + + update.message.reply_text = mocker.AsyncMock() + + await bot_quake.file_reader( + update, None + ) # invochiamo la funzione che al suo interno invoca update.message.reply_text + + update.message.reply_text.assert_called_once_with( + "Inserire un numero da 1 a 10 rilevati caratteri non numerici" + ) # vediamo se la funzione mockata viene invocata e con quali parametri + +@pytest.mark.asyncio +async def test_file_reader_with_none_message_error(mocker: MockerFixture): + """Effettua il test della funzione test_file_reader""" + + update = mocker.AsyncMock() + update.message.text = ( + None # col mock possiamo presettare un valore che ci serve + ) + + update.message.reply_text = mocker.AsyncMock() + + await bot_quake.file_reader( + update, None + ) # invochiamo la funzione che al suo interno invoca update.message.reply_text + + update.message.reply_text.assert_called_once_with( + MENU + ) # vediamo se la funzione mockata viene invocata e con quali parametri def test_build_bot(mocker: MockerFixture): """Effettua il test della funzione build_bot""" Application.builder = mocker.Mock()