Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: addition of last tests functions #30

Merged
merged 8 commits into from
Mar 22, 2024
Merged
6 changes: 3 additions & 3 deletions src/bot_quake.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
57 changes: 57 additions & 0 deletions tests/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down