2024-01-11 08:17:25 +01:00
|
|
|
from datetime import datetime
|
|
|
|
import shutil
|
|
|
|
|
2024-07-23 21:59:02 +02:00
|
|
|
from review.stats import ReviewStats
|
2024-04-01 19:27:52 +02:00
|
|
|
from tests.utils import bot, OWNER, SENDER
|
2024-01-11 08:17:25 +01:00
|
|
|
|
|
|
|
|
|
|
|
def setup_function():
|
|
|
|
shutil.copyfile("tests/datas/reviewstats.csv", "tests/reviews/reviewstats.csv")
|
|
|
|
|
|
|
|
|
|
|
|
def test_complete_review(bot):
|
|
|
|
with open("tests/datas/irc.txt") as file_handle:
|
|
|
|
content = file_handle.read().splitlines()
|
|
|
|
messages = []
|
|
|
|
for line in content:
|
|
|
|
data = line.split(":")
|
|
|
|
author = data[0].strip()
|
|
|
|
text = ":".join(data[1:]).strip()
|
|
|
|
messages.append((author, text))
|
|
|
|
|
2024-04-01 19:27:52 +02:00
|
|
|
bot.test_public_message(bot.channel, "lllll", "!start")
|
2024-01-11 08:17:25 +01:00
|
|
|
bot.review.start_time = datetime(2023, 12, 1, 12, 0, 0)
|
|
|
|
for message in messages:
|
2024-04-01 19:27:52 +02:00
|
|
|
bot.test_public_message(bot.channel, message[0], message[1])
|
2024-01-11 08:17:25 +01:00
|
|
|
|
|
|
|
# compare contents
|
|
|
|
with open("tests/datas/20231201-log-irc-revue-hebdomadaire.txt") as file_handle:
|
|
|
|
content_ok = file_handle.read()
|
|
|
|
with open("tests/reviews/20231201-log-irc-revue-hebdomadaire.txt") as file_handle:
|
|
|
|
content_tested = file_handle.read()
|
|
|
|
assert content_ok in content_tested
|
2024-04-06 10:03:48 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_other_review(bot):
|
|
|
|
with open("tests/datas/irc_2.txt") as file_handle:
|
|
|
|
content = file_handle.read().splitlines()
|
|
|
|
messages = []
|
|
|
|
for line in content:
|
|
|
|
data = line.split(":")
|
|
|
|
author = data[0].strip()
|
|
|
|
text = ":".join(data[1:]).strip()
|
|
|
|
messages.append((author, text))
|
|
|
|
|
|
|
|
bot.test_public_message(bot.channel, "lllll", "!start")
|
|
|
|
bot.review.start_time = datetime(2024, 4, 2, 9, 59, 0)
|
|
|
|
for message in messages:
|
|
|
|
bot.test_public_message(bot.channel, message[0], message[1])
|
|
|
|
|
|
|
|
# compare contents
|
|
|
|
with open("tests/datas/20240402-log-irc-revue-hebdomadaire.txt") as file_handle:
|
|
|
|
content_ok = file_handle.read()
|
|
|
|
with open("tests/reviews/20240402-log-irc-revue-hebdomadaire.txt") as file_handle:
|
|
|
|
content_tested = file_handle.read()
|
|
|
|
assert content_ok in content_tested
|
2024-07-23 21:46:06 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_fast_review(bot):
|
|
|
|
bot.test_public_message(bot.channel, "lllll", "!start")
|
|
|
|
bot.test_public_message(bot.channel, "lllll", "# new test")
|
|
|
|
bot.test_public_message(bot.channel, "lllll", "test")
|
|
|
|
bot.test_public_message(bot.channel, "lllll", "!fin")
|
|
|
|
bot.test_public_message(bot.channel, "lllll", "!stats")
|
2024-07-23 21:59:02 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_review_with_one_user_dont_update_stats(bot):
|
|
|
|
review = ReviewStats("tests/reviews/reviewstats.csv")
|
|
|
|
review.load()
|
|
|
|
size = review.size
|
|
|
|
bot.test_public_message(bot.channel, "lllll", "!start")
|
|
|
|
bot.test_public_message(bot.channel, "lllll", "# new test")
|
|
|
|
bot.test_public_message(bot.channel, "lllll", "test")
|
|
|
|
bot.test_public_message(bot.channel, "lllll", "!fin")
|
|
|
|
review = ReviewStats("tests/reviews/reviewstats.csv")
|
|
|
|
review.load()
|
|
|
|
assert review.size == size
|
|
|
|
|
|
|
|
|
|
|
|
def test_review_with_two_user_update_stats(bot):
|
|
|
|
review = ReviewStats("tests/reviews/reviewstats.csv")
|
|
|
|
review.load()
|
|
|
|
size = review.size
|
|
|
|
bot.test_public_message(bot.channel, "lllll", "!start")
|
|
|
|
bot.test_public_message(bot.channel, "lllll", "# new test")
|
|
|
|
bot.test_public_message(bot.channel, "lllll", "test")
|
|
|
|
bot.test_public_message(bot.channel, "ooooo", "another test")
|
|
|
|
bot.test_public_message(bot.channel, "lllll", "!fin")
|
|
|
|
review = ReviewStats("tests/reviews/reviewstats.csv")
|
|
|
|
review.load()
|
|
|
|
assert review.size == (size + 1)
|