125 lines
4.2 KiB
Python
125 lines
4.2 KiB
Python
|
import os
|
||
|
import shutil
|
||
|
|
||
|
from tests.utils import bot, CHANNEL, OWNER, SENDER
|
||
|
|
||
|
|
||
|
def setup_function():
|
||
|
shutil.copyfile("tests/datas/reviewstats.csv", "tests/reviews/reviewstats.csv")
|
||
|
|
||
|
|
||
|
def test_hook_listen_anniv(bot):
|
||
|
bot.on_public_message(CHANNEL, SENDER, "!anniv")
|
||
|
assert len(bot.answers) == 3
|
||
|
assert bot.answers[0].message.startswith("La revue")
|
||
|
assert bot.answers[1].message.startswith("Hebdobot")
|
||
|
assert bot.answers[2].message.startswith("L'April")
|
||
|
|
||
|
|
||
|
def test_hook_bad_command(bot):
|
||
|
bot.on_public_message(CHANNEL, SENDER, "!aniv")
|
||
|
assert len(bot.answers) == 1
|
||
|
assert bot.answers[0].message == f"{SENDER}, Yo !"
|
||
|
|
||
|
|
||
|
def test_hook_date(bot):
|
||
|
bot.on_public_message(CHANNEL, SENDER, "!date")
|
||
|
assert len(bot.answers) == 1
|
||
|
bot.on_public_message(CHANNEL, SENDER, "!time")
|
||
|
assert len(bot.answers) == 1
|
||
|
bot.on_public_message(CHANNEL, SENDER, "!now")
|
||
|
assert len(bot.answers) == 1
|
||
|
|
||
|
|
||
|
def test_hook_default(bot):
|
||
|
bot.on_public_message(CHANNEL, SENDER, "some message")
|
||
|
assert bot.answers == []
|
||
|
|
||
|
|
||
|
def test_hook_hello(bot):
|
||
|
bot.on_public_message(CHANNEL, SENDER, "!salut")
|
||
|
assert len(bot.answers) == 1
|
||
|
assert bot.answers[0].message == f"{SENDER}, bonjour \\o/"
|
||
|
bot.on_public_message(CHANNEL, SENDER, "!bonjour")
|
||
|
assert len(bot.answers) == 1
|
||
|
assert bot.answers[0].message == f"{SENDER}, bonjour \\o/"
|
||
|
bot.on_public_message(CHANNEL, SENDER, "!hello")
|
||
|
assert len(bot.answers) == 1
|
||
|
assert bot.answers[0].message == f"{SENDER}, bonjour \\o/"
|
||
|
bot.on_public_message(CHANNEL, SENDER, "bonjour hebdobot")
|
||
|
assert len(bot.answers) == 1
|
||
|
assert bot.answers[0].message == f"{SENDER}, bonjour \\o/"
|
||
|
|
||
|
|
||
|
def test_hook_help(bot):
|
||
|
bot.on_public_message(CHANNEL, SENDER, "!help")
|
||
|
assert len(bot.answers) == 15
|
||
|
bot.on_public_message(CHANNEL, SENDER, "!aide")
|
||
|
assert len(bot.answers) == 15
|
||
|
|
||
|
|
||
|
def test_hook_license(bot):
|
||
|
bot.on_public_message(CHANNEL, SENDER, "!license")
|
||
|
assert len(bot.answers) == 1
|
||
|
assert bot.answers[0].message.startswith("Hebdobot est un logiciel libre")
|
||
|
bot.on_public_message(CHANNEL, SENDER, "!licence")
|
||
|
assert len(bot.answers) == 1
|
||
|
assert bot.answers[0].message.startswith("Hebdobot est un logiciel libre")
|
||
|
|
||
|
|
||
|
def test_hook_listen_alexandrie(bot):
|
||
|
bot.on_public_message(CHANNEL, "alexandrie", "!version")
|
||
|
assert bot.answers == []
|
||
|
bot.on_public_message(CHANNEL, SENDER, "!version")
|
||
|
assert bot.answers != []
|
||
|
|
||
|
|
||
|
def test_hook_record(bot):
|
||
|
bot.on_public_message(CHANNEL, SENDER, "!record")
|
||
|
assert len(bot.answers) == 1
|
||
|
assert bot.answers[0].message.startswith("Le record de participation")
|
||
|
|
||
|
|
||
|
def test_hook_stats(bot):
|
||
|
bot.on_public_message(CHANNEL, SENDER, "!stats")
|
||
|
assert len(bot.answers) == 5
|
||
|
assert bot.answers[0].message.startswith("% Il y a eu ")
|
||
|
|
||
|
|
||
|
def test_hook_stats_with_no_review(bot):
|
||
|
os.remove("tests/reviews/reviewstats.csv")
|
||
|
bot.on_public_message(CHANNEL, SENDER, "!stats")
|
||
|
assert len(bot.answers) == 5
|
||
|
assert bot.answers[0].message == "% Il n'y a pas encore eu de revue."
|
||
|
|
||
|
|
||
|
def test_hook_status(bot):
|
||
|
bot.on_public_message(CHANNEL, SENDER, "!status")
|
||
|
assert len(bot.answers) == 3
|
||
|
assert bot.answers[0].message.startswith(f"{SENDER}, voici l'état")
|
||
|
bot.on_public_message(CHANNEL, SENDER, "!statut")
|
||
|
assert len(bot.answers) == 3
|
||
|
assert bot.answers[0].message.startswith(f"{SENDER}, voici l'état")
|
||
|
assert bot.answers[1].message == f" revue en cours : {bot.review is not None}"
|
||
|
assert bot.answers[2].message == " animateur revue : none"
|
||
|
|
||
|
|
||
|
def test_hook_status_started_review(bot):
|
||
|
bot.on_public_message(CHANNEL, OWNER, "!start")
|
||
|
bot.on_public_message(CHANNEL, SENDER, "!statut")
|
||
|
assert len(bot.answers) == 3
|
||
|
assert bot.answers[0].message.startswith(f"{SENDER}, voici l'état")
|
||
|
assert bot.answers[1].message == f" revue en cours : {bot.review is not None}"
|
||
|
assert bot.answers[2].message == f" animateur revue : {OWNER}"
|
||
|
|
||
|
|
||
|
def test_hook_thanks(bot):
|
||
|
bot.on_public_message(CHANNEL, SENDER, "!merci")
|
||
|
assert len(bot.answers) == 1
|
||
|
assert bot.answers[0].message == f"{SENDER}, de rien \\o/"
|
||
|
|
||
|
|
||
|
def test_hook_version(bot):
|
||
|
bot.on_public_message(CHANNEL, SENDER, "!version")
|
||
|
assert len(bot.answers) == 1
|