from datetime import datetime, timedelta import shutil from tests.utils import bot, OWNER, SENDER def setup_function(): shutil.copyfile("tests/datas/reviewstats.csv", "tests/reviews/reviewstats.csv") def test_review_starting_new(bot): assert bot.review.participants == [] assert bot.review.topics == [] assert bot.review.messages == [] assert bot.review.owner is None assert bot.review.started == False assert bot.review.ended == False assert bot.review.start_time is None assert bot.review.end_time is None bot.test_public_message(bot.channel, OWNER, "!start") assert len(bot.answers) == 5 assert bot.answers[0].target == OWNER assert bot.answers[0].message.startswith(f"% Bonjour {OWNER}") assert bot.answers[1].target == OWNER assert bot.answers[1].message.startswith("% Pour terminer") assert bot.answers[2].target == bot.channel assert bot.answers[2].message.startswith("% Début de") assert bot.answers[3].target == bot.channel assert bot.answers[3].message.startswith("% rappel") assert bot.answers[4].target == bot.channel assert bot.answers[4].message.startswith("% pour connaître") assert bot.review.participants == [] assert bot.review.topics == [] assert len(bot.review.messages) == 3 assert bot.review.owner == OWNER assert bot.review.started == True assert bot.review.ended == False assert bot.review.start_time is not None assert bot.review.end_time is None def test_review_starting_started_review(bot): bot.test_public_message(bot.channel, OWNER, "!start") bot.test_public_message(bot.channel, OWNER, "!start") assert len(bot.answers) == 1 assert bot.answers[0].message == f"% {OWNER}, une revue est déjà en cours." assert bot.review.participants == [] assert bot.review.topics == [] assert bot.review.messages[-1].text == f"% {OWNER}, une revue est déjà en cours." assert bot.review.owner == OWNER assert bot.review.started == True assert bot.review.ended == False assert bot.review.start_time is not None assert bot.review.end_time is None def test_review_ending_not_started_review(bot): bot.test_public_message(bot.channel, OWNER, "!fin") assert len(bot.answers) == 1 assert bot.answers[0].message == f"{OWNER}, pas de revue en cours." assert bot.review.participants == [] assert bot.review.topics == [] assert bot.review.messages == [] assert bot.review.owner is None assert bot.review.started == False assert bot.review.ended == False assert bot.review.start_time is None assert bot.review.end_time is None def test_review_ending_as_not_owner(bot): bot.test_public_message(bot.channel, OWNER, "!start") bot.test_public_message(bot.channel, SENDER, "!fin") assert len(bot.answers) == 1 assert bot.answers[0].message == f"{SENDER}, vous n'êtes pas responsable de la revue." assert bot.review.participants == [] assert bot.review.topics == [] assert bot.review.messages[-1].text == f"{SENDER}, vous n'êtes pas responsable de la revue." assert bot.review.owner == OWNER assert bot.review.started == True assert bot.review.ended == False assert bot.review.start_time is not None assert bot.review.end_time is None def test_review_cancel_last_message_on_collective_topic(bot): bot.test_public_message(bot.channel, OWNER, "!start") bot.test_public_message(bot.channel, OWNER, "## Collective topic") bot.test_public_message(bot.channel, SENDER, "This is my message") assert len(bot.review.current_topic.messages) == 1 assert bot.review.current_topic.messages[0].text == "This is my message" bot.test_public_message(bot.channel, SENDER, "!oups") assert len(bot.review.current_topic.messages) == 0 bot.test_public_message(bot.channel, SENDER, "This is my message") assert len(bot.review.current_topic.messages) == 1 assert bot.review.current_topic.messages[0].text == "This is my message" bot.test_public_message(bot.channel, SENDER, "!oops") assert len(bot.review.current_topic.messages) == 0 bot.test_public_message(bot.channel, SENDER, "This is my message") assert len(bot.review.current_topic.messages) == 1 assert bot.review.current_topic.messages[0].text == "This is my message" bot.test_public_message(bot.channel, SENDER, "!cancelprevious") assert len(bot.review.current_topic.messages) == 0 def test_review_cancel_only_message_on_collective_topic(bot): bot.test_public_message(bot.channel, OWNER, "!start") bot.test_public_message(bot.channel, OWNER, "## Collective topic") bot.test_public_message(bot.channel, OWNER, "This is a message from owner") bot.test_public_message(bot.channel, SENDER, "This is a message from sender") bot.test_public_message(bot.channel, OWNER, "This is another message from owner") assert len(bot.review.current_topic.messages) == 3 assert bot.review.current_topic.messages[1].text == "This is a message from sender" bot.test_public_message(bot.channel, SENDER, "!oups") assert len(bot.answers) == 1 assert len(bot.review.current_topic.messages) == 2 assert bot.review.current_topic.messages[1].text == "This is another message from owner" def test_review_cancel_last_message_from_two_on_collective_topic(bot): bot.test_public_message(bot.channel, OWNER, "!start") bot.test_public_message(bot.channel, OWNER, "## Collective topic") bot.test_public_message(bot.channel, OWNER, "This is a message from owner") bot.test_public_message(bot.channel, SENDER, "This is a message from sender") bot.test_public_message(bot.channel, SENDER, "This is another message from sender") assert len(bot.review.current_topic.messages) == 3 assert bot.review.current_topic.messages[1].text == "This is a message from sender" bot.test_public_message(bot.channel, SENDER, "!oups") assert len(bot.answers) == 1 assert len(bot.review.current_topic.messages) == 2 assert bot.review.current_topic.messages[1].text == "This is a message from sender" def test_review_cancel_first_message_from_three_on_collective_topic(bot): bot.test_public_message(bot.channel, OWNER, "!start") bot.test_public_message(bot.channel, OWNER, "## Collective topic") bot.test_public_message(bot.channel, SENDER, "This is a message from sender") bot.test_public_message(bot.channel, OWNER, "This is a message from owner") bot.test_public_message(bot.channel, OWNER, "This is another message from owner") bot.test_public_message(bot.channel, OWNER, "This is a third message from owner") assert len(bot.review.current_topic.messages) == 4 assert bot.review.current_topic.messages[1].text == "This is a message from owner" bot.test_public_message(bot.channel, SENDER, "!oups") assert len(bot.answers) == 1 assert len(bot.review.current_topic.messages) == 3 assert bot.review.current_topic.messages[1].text == "This is another message from owner" def test_review_cancel_last_message_no_message_on_collective_topic(bot): bot.test_public_message(bot.channel, OWNER, "!start") bot.test_public_message(bot.channel, OWNER, "# Individual topic") bot.test_public_message(bot.channel, OWNER, "This is my message") assert len(bot.review.current_topic.messages) == 1 assert bot.review.current_topic.messages[0].text == "This is my message" bot.test_public_message(bot.channel, SENDER, "!oups") assert len(bot.review.current_topic.messages) == 1 assert bot.review.current_topic.messages[0].text == "This is my message" def test_review_cancel_last_message_on_individual_topic(bot): bot.test_public_message(bot.channel, OWNER, "!start") bot.test_public_message(bot.channel, OWNER, "# Individual topic") bot.test_public_message(bot.channel, SENDER, "This is my message") assert len(bot.review.current_topic.messages) == 1 assert bot.review.current_topic.messages[0].text == "This is my message" bot.test_public_message(bot.channel, SENDER, "!oups") assert len(bot.review.current_topic.messages) == 0 bot.test_public_message(bot.channel, SENDER, "This is my message") assert len(bot.review.current_topic.messages) == 1 assert bot.review.current_topic.messages[0].text == "This is my message" bot.test_public_message(bot.channel, SENDER, "!oops") assert len(bot.review.current_topic.messages) == 0 bot.test_public_message(bot.channel, SENDER, "This is my message") assert len(bot.review.current_topic.messages) == 1 assert bot.review.current_topic.messages[0].text == "This is my message" bot.test_public_message(bot.channel, SENDER, "!cancelprevious") assert len(bot.review.current_topic.messages) == 0 def test_review_cancel_only_message_on_individual_topic(bot): bot.test_public_message(bot.channel, OWNER, "!start") bot.test_public_message(bot.channel, OWNER, "# Individual topic") bot.test_public_message(bot.channel, OWNER, "This is a message from owner") bot.test_public_message(bot.channel, SENDER, "This is a message from sender") bot.test_public_message(bot.channel, OWNER, "This is another message from owner") assert len(bot.review.current_topic.messages) == 3 assert bot.review.current_topic.messages[1].text == "This is a message from sender" bot.test_public_message(bot.channel, SENDER, "!oups") assert len(bot.answers) == 1 assert len(bot.review.current_topic.messages) == 2 assert bot.review.current_topic.messages[1].text == "This is another message from owner" def test_review_cancel_last_message_from_two_on_individual_topic(bot): bot.test_public_message(bot.channel, OWNER, "!start") bot.test_public_message(bot.channel, OWNER, "# Individual topic") bot.test_public_message(bot.channel, OWNER, "This is a message from owner") bot.test_public_message(bot.channel, SENDER, "This is a message from sender") bot.test_public_message(bot.channel, SENDER, "This is another message from sender") assert len(bot.review.current_topic.messages) == 3 assert bot.review.current_topic.messages[1].text == "This is a message from sender" bot.test_public_message(bot.channel, SENDER, "!oups") assert len(bot.answers) == 1 assert len(bot.review.current_topic.messages) == 2 assert bot.review.current_topic.messages[1].text == "This is a message from sender" def test_review_cancel_first_message_from_three_on_individual_topic(bot): bot.test_public_message(bot.channel, OWNER, "!start") bot.test_public_message(bot.channel, OWNER, "# Individual topic") bot.test_public_message(bot.channel, SENDER, "This is a message from sender") bot.test_public_message(bot.channel, OWNER, "This is a message from owner") bot.test_public_message(bot.channel, OWNER, "This is another message from owner") bot.test_public_message(bot.channel, OWNER, "This is a third message from owner") assert len(bot.review.current_topic.messages) == 4 assert bot.review.current_topic.messages[1].text == "This is a message from owner" bot.test_public_message(bot.channel, SENDER, "!oups") assert len(bot.answers) == 1 assert len(bot.review.current_topic.messages) == 3 assert bot.review.current_topic.messages[1].text == "This is another message from owner" def test_review_cancel_last_message_no_message_on_individual_topic(bot): bot.test_public_message(bot.channel, OWNER, "!start") bot.test_public_message(bot.channel, OWNER, "# Individual topic") bot.test_public_message(bot.channel, OWNER, "This is my message") assert len(bot.review.current_topic.messages) == 1 assert bot.review.current_topic.messages[0].text == "This is my message" bot.test_public_message(bot.channel, SENDER, "!oups") assert len(bot.review.current_topic.messages) == 1 assert bot.review.current_topic.messages[0].text == "This is my message" def test_review_cancel_last_message_no_review(bot): bot.test_public_message(bot.channel, SENDER, "!oups") assert len(bot.answers) == 1 assert bot.answers[0].message == f"{SENDER}, pas de revue en cours." def test_review_cancel_last_message_no_topic(bot): bot.test_public_message(bot.channel, OWNER, "!start") bot.test_public_message(bot.channel, SENDER, "!oups") assert len(bot.answers) == 1 assert bot.answers[0].message == f"{SENDER}, pas de sujet en cours." def test_review_collective_topic(bot): bot.test_public_message(bot.channel, OWNER, "!start") assert len(bot.review.topics) == 0 assert bot.review.current_topic is None bot.test_public_message(bot.channel, OWNER, "## collective topic") assert len(bot.answers) == 4 assert len(bot.review.topics) == 1 assert bot.review.current_topic is not None assert bot.review.current_topic.collective def test_review_second_collective_topic(bot): bot.test_public_message(bot.channel, OWNER, "!start") assert len(bot.review.topics) == 0 assert bot.review.current_topic is None bot.test_public_message(bot.channel, OWNER, "## collective topic") bot.test_public_message(bot.channel, OWNER, "This is my message") bot.test_public_message(bot.channel, SENDER, "This is a message from sender") bot.test_public_message(bot.channel, OWNER, "## second collective topic") assert len(bot.answers) == 6 assert len(bot.review.topics) == 2 assert bot.review.current_topic is not None assert bot.review.current_topic.collective def test_review_collective_no_review(bot): bot.test_public_message(bot.channel, OWNER, "## collective topic") assert len(bot.answers) == 0 assert not bot.review.is_started assert len(bot.review.topics) == 0 assert bot.review.current_topic is None def test_review_collective_topic_not_owner(bot): bot.test_public_message(bot.channel, OWNER, "!start") bot.test_public_message(bot.channel, SENDER, "## collective topic") assert len(bot.answers) == 1 assert bot.answers[0].message == f"{SENDER}, vous n'êtes pas responsable de la réunion" def test_review_comment(bot): bot.test_public_message(bot.channel, OWNER, "!start") bot.test_public_message(bot.channel, SENDER, "% This is a comment") assert len(bot.answers) == 0 assert bot.review.messages[-1].text == "% This is a comment" assert bot.review.current_topic is None def test_review_current_without_review(bot): bot.test_public_message(bot.channel, OWNER, "!courant") assert len(bot.answers) == 1 assert bot.answers[0].message == f"{OWNER}, pas de revue en cours." assert not bot.review.is_started def test_review_current_without_topic(bot): bot.test_public_message(bot.channel, OWNER, "!start") bot.test_public_message(bot.channel, OWNER, "!courant") assert len(bot.answers) == 1 assert bot.answers[0].message == "% Pas de sujet en cours." assert bot.review.is_started def test_review_current_with_collective_topic(bot): bot.test_public_message(bot.channel, OWNER, "!start") bot.test_public_message(bot.channel, OWNER, "## collective topic") bot.test_public_message(bot.channel, OWNER, "!courant") assert len(bot.answers) == 1 assert bot.review.current_topic.title == "collective topic" assert bot.answers[0].message == f"% Sujet collectif en cours : {bot.review.current_topic.title}" def test_review_current_with_individual_topic(bot): bot.test_public_message(bot.channel, OWNER, "!start") bot.test_public_message(bot.channel, OWNER, "# individual topic") bot.test_public_message(bot.channel, OWNER, "!courant") assert len(bot.answers) == 1 assert bot.review.current_topic.title == "individual topic" assert bot.answers[0].message == f"% Sujet individuel en cours : {bot.review.current_topic.title}" def test_review_individual_topic(bot): bot.test_public_message(bot.channel, OWNER, "!start") assert len(bot.review.topics) == 0 assert bot.review.current_topic is None bot.test_public_message(bot.channel, OWNER, "# individual topic") assert len(bot.answers) == 3 assert len(bot.review.topics) == 1 assert bot.review.current_topic is not None assert bot.review.current_topic.individual def test_review_second_individual_topic(bot): bot.test_public_message(bot.channel, OWNER, "!start") assert len(bot.review.topics) == 0 assert bot.review.current_topic is None bot.test_public_message(bot.channel, OWNER, "# individual topic") bot.test_public_message(bot.channel, OWNER, "This is my message") bot.test_public_message(bot.channel, SENDER, "This is a message from sender") bot.test_public_message(bot.channel, OWNER, "# second individual topic") assert len(bot.answers) == 5 assert len(bot.review.topics) == 2 assert bot.review.current_topic is not None assert bot.review.current_topic.individual def test_review_individual_no_review(bot): bot.test_public_message(bot.channel, OWNER, "# individual topic") assert len(bot.answers) == 0 assert not bot.review.is_started assert len(bot.review.topics) == 0 assert bot.review.current_topic is None def test_review_individual_topic_not_owner(bot): bot.test_public_message(bot.channel, OWNER, "!start") bot.test_public_message(bot.channel, SENDER, "# individual topic") assert len(bot.answers) == 1 assert bot.answers[0].message == f"{SENDER}, vous n'êtes pas responsable de la réunion" def test_stop_review(bot): bot.test_public_message(bot.channel, OWNER, "!start") assert bot.review.is_started assert not bot.review.is_ended bot.test_public_message(bot.channel, OWNER, "A messsage") bot.test_public_message(bot.channel, OWNER, "## collective topic") bot.test_public_message(bot.channel, OWNER, "Another messsage") bot.test_public_message(bot.channel, OWNER, "!stop") assert not bot.review.is_started assert not bot.review.is_ended assert len(bot.review.topics) == 0 assert bot.review.current_topic is None assert len(bot.answers) == 1 assert bot.answers[0].message == "Abandon de la revue en cours." def test_stop_review_not_owner(bot): bot.test_public_message(bot.channel, OWNER, "!start") bot.test_public_message(bot.channel, SENDER, "!stop") assert bot.review.is_started assert len(bot.answers) == 1 assert bot.answers[0].message == f"{SENDER}, vous n'êtes pas responsable de la réunion." def test_stop_review_no_review(bot): bot.test_public_message(bot.channel, OWNER, "!stop") assert not bot.review.is_started assert not bot.review.is_ended assert len(bot.review.topics) == 0 assert bot.review.current_topic is None assert len(bot.answers) == 1 assert bot.answers[0].message == f"{OWNER}, pas de revue en cours, abandon impossible." def test_missing_no_review(bot): bot.test_public_message(bot.channel, OWNER, "!manquantes") assert not bot.review.is_started assert len(bot.answers) == 1 assert bot.answers[0].message == f"{OWNER}, pas de revue en cours." def test_missing_no_topic(bot): bot.test_public_message(bot.channel, OWNER, "!start") assert bot.review.is_started bot.test_public_message(bot.channel, OWNER, "!manquantes") assert len(bot.answers) == 1 assert bot.answers[0].message == "% Pas de sujet en cours." def test_missing_no_one_is_missing(bot): bot.test_public_message(bot.channel, OWNER, "!start") bot.test_public_message(bot.channel, OWNER, "## collective topic") bot.test_public_message(bot.channel, SENDER, "This is my message") bot.test_public_message(bot.channel, OWNER, "This is owner message") bot.test_public_message(bot.channel, OWNER, "!manquantes") assert len(bot.answers) == 1 assert bot.answers[0].message == "% Tout le monde s'est exprimé sur le sujet courant \\o/" def test_missing_no_one_is_missing_through_ras(bot): bot.test_public_message(bot.channel, OWNER, "!start") bot.test_public_message(bot.channel, OWNER, "## collective topic") bot.test_public_message(bot.channel, SENDER, "%ras") bot.test_public_message(bot.channel, OWNER, "This is owner message") bot.test_public_message(bot.channel, OWNER, "!manquantes") assert len(bot.answers) == 1 assert bot.answers[0].message == "% Tout le monde s'est exprimé sur le sujet courant \\o/" def test_missing_one_is_missing(bot): bot.test_public_message(bot.channel, OWNER, "!start") bot.test_public_message(bot.channel, OWNER, "## collective topic") bot.test_public_message(bot.channel, SENDER, "This is my message") bot.test_public_message(bot.channel, OWNER, "This is owner message") bot.test_public_message(bot.channel, OWNER, "## a second collective topic") bot.test_public_message(bot.channel, OWNER, "This is the second owner message") bot.test_public_message(bot.channel, OWNER, "!manquantes") assert len(bot.answers) == 1 assert bot.answers[0].message == ( "% Personnes participantes ne s'étant pas exprimées sur le " f"sujet courant : {', '.join([SENDER])}" ) def test_chrono_no_review(bot): bot.test_public_message(bot.channel, OWNER, "!chrono") assert len(bot.answers) == 1 assert bot.answers[0].message == "n/a" def test_chrono(bot): bot.test_public_message(bot.channel, OWNER, "!start") bot.review.start_time = datetime.today() - timedelta(seconds=87) bot.test_public_message(bot.channel, OWNER, "!chrono") assert len(bot.answers) == 1 assert bot.answers[0].message == "01:27" def test_finish_review(bot): bot.test_public_message(bot.channel, OWNER, "!start") bot.test_public_message(bot.channel, OWNER, "## collective topic") bot.test_public_message(bot.channel, OWNER, "Owner message on collective topic") bot.test_public_message(bot.channel, SENDER, "Sender message on collective topic") bot.test_public_message(bot.channel, OWNER, "# individual topic") bot.test_public_message(bot.channel, OWNER, "Owner message on individual topic") bot.test_public_message(bot.channel, SENDER, "Sender message on individual topic") bot.test_public_message(bot.channel, OWNER, "!fin") assert len(bot.answers) == 10 assert bot.answers[-2].message == "% Fin de la revue hebdomadaire" assert bot.answers[-1].message == "Revue finie." def test_finish_review_no_review(bot): bot.test_public_message(bot.channel, OWNER, "!fin") assert len(bot.answers) == 1 assert bot.answers[0].message == f"{OWNER}, pas de revue en cours." def test_finish_review_already_finished(bot): bot.test_public_message(bot.channel, OWNER, "!start") bot.test_public_message(bot.channel, OWNER, "## collective topic") bot.test_public_message(bot.channel, OWNER, "Owner message on collective topic") bot.test_public_message(bot.channel, SENDER, "Sender message on collective topic") bot.test_public_message(bot.channel, OWNER, "# individual topic") bot.test_public_message(bot.channel, OWNER, "Owner message on individual topic") bot.test_public_message(bot.channel, SENDER, "Sender message on individual topic") bot.test_public_message(bot.channel, OWNER, "!fin") bot.test_public_message(bot.channel, OWNER, "!fin") assert len(bot.answers) == 1 assert bot.answers[0].message.endswith(", pas de revue en cours.") def test_finish_review_not_owner(bot): bot.test_public_message(bot.channel, OWNER, "!start") bot.test_public_message(bot.channel, OWNER, "## collective topic") bot.test_public_message(bot.channel, OWNER, "Owner message on collective topic") bot.test_public_message(bot.channel, SENDER, "Sender message on collective topic") bot.test_public_message(bot.channel, OWNER, "# individual topic") bot.test_public_message(bot.channel, OWNER, "Owner message on individual topic") bot.test_public_message(bot.channel, SENDER, "Sender message on individual topic") bot.test_public_message(bot.channel, SENDER, "!fin") assert len(bot.answers) == 1 assert bot.answers[0].message == f"{SENDER}, vous n'êtes pas responsable de la revue." def test_finish_review_no_participation(bot): bot.test_public_message(bot.channel, OWNER, "!start") bot.test_public_message(bot.channel, OWNER, "!fin") assert len(bot.answers) == 1 assert bot.answers[0].message == "Participation nulle détectée. La revue est ignorée."