Fix history limit handling.

This commit is contained in:
OK
2023-04-13 18:36:06 +02:00
parent 79e95ab06c
commit 2508a12b44
4 changed files with 24 additions and 19 deletions
+10 -10
View File
@@ -82,34 +82,34 @@ You always try to say something positive about the current day and the Fjærkroa
updater.history = []
updater.history_file = None
question = {"channel": "test_channel", "content": "What is the meaning of life?"}
answer = {"channel": "test_channel", "content": "42"}
question = {"content": '{"channel": "test_channel", "message": "What is the meaning of life?"}'}
answer = {"content": '{"channel": "test_channel", "message": "42"}'}
# Test case 1: Limit set to 2
updater.update_history(question, answer, 2)
self.assertEqual(updater.history, [question, answer])
# Test case 2: Limit set to 4, check limit enforcement (deletion)
new_question = {"channel": "test_channel", "content": "What is AI?"}
new_answer = {"channel": "test_channel", "content": "Artificial Intelligence"}
new_question = {"content": '{"channel": "test_channel", "message": "What is AI?"}'}
new_answer = {"content": '{"channel": "test_channel", "message": "Artificial Intelligence"}'}
updater.update_history(new_question, new_answer, 3)
self.assertEqual(updater.history, [answer, new_question, new_answer])
# Test case 3: Limit set to 4, check limit enforcement (deletion)
other_question = {"channel": "other_channel", "content": "What is XXX?"}
other_answer = {"channel": "other_channel", "content": "Tripple X"}
other_question = {"content": '{"channel": "other_channel", "message": "What is XXX?"}'}
other_answer = {"content": '{"channel": "other_channel", "message": "Tripple X"}'}
updater.update_history(other_question, other_answer, 4)
self.assertEqual(updater.history, [new_question, new_answer, other_question, other_answer])
# Test case 4: Limit set to 4, check limit enforcement (deletion)
next_question = {"channel": "other_channel", "content": "What is YYY?"}
next_answer = {"channel": "other_channel", "content": "Tripple Y"}
next_question = {"content": '{"channel": "other_channel", "message": "What is YYY?"}'}
next_answer = {"content": '{"channel": "other_channel", "message": "Tripple Y"}'}
updater.update_history(next_question, next_answer, 4)
self.assertEqual(updater.history, [new_answer, other_answer, next_question, next_answer])
# Test case 5: Limit set to 4, check limit enforcement (deletion)
next_question2 = {"channel": "other_channel", "content": "What is ZZZ?"}
next_answer2 = {"channel": "other_channel", "content": "Tripple Z"}
next_question2 = {"content": '{"channel": "other_channel", "message": "What is ZZZ?"}'}
next_answer2 = {"content": '{"channel": "other_channel", "message": "Tripple Z"}'}
updater.update_history(next_question2, next_answer2, 4)
self.assertEqual(updater.history, [new_answer, next_answer, next_question2, next_answer2])