|
| 1 | +from datetime import datetime |
| 2 | +from unittest.mock import patch |
| 3 | + |
| 4 | +import pytest |
| 5 | + |
| 6 | +from pgcommitfest.commitfest.ajax import refresh_single_thread |
| 7 | +from pgcommitfest.commitfest.models import MailThread, Patch, Topic |
| 8 | + |
| 9 | +pytestmark = pytest.mark.django_db |
| 10 | + |
| 11 | + |
| 12 | +def test_refresh_single_thread_updates_patch_lastmail(): |
| 13 | + """Regression test: patch.lastmail should get the new date, not the old one.""" |
| 14 | + old_date = datetime(2024, 1, 1) |
| 15 | + new_date = datetime(2024, 6, 15) |
| 16 | + |
| 17 | + topic = Topic.objects.create(topic="Test") |
| 18 | + thread = MailThread.objects.create( |
| 19 | + messageid="old@example.com", |
| 20 | + subject="Test", |
| 21 | + firstmessage=old_date, |
| 22 | + firstauthor="a@example.com", |
| 23 | + latestmessage=old_date, |
| 24 | + latestauthor="a@example.com", |
| 25 | + latestsubject="Test", |
| 26 | + latestmsgid="old@example.com", |
| 27 | + ) |
| 28 | + p = Patch.objects.create(name="Test Patch", topic=topic, lastmail=old_date) |
| 29 | + p.mailthread_set.add(thread) |
| 30 | + |
| 31 | + api_response = [ |
| 32 | + { |
| 33 | + "msgid": "old@example.com", |
| 34 | + "date": old_date, |
| 35 | + "from": "a", |
| 36 | + "subj": "T", |
| 37 | + "atts": [], |
| 38 | + }, |
| 39 | + { |
| 40 | + "msgid": "new@example.com", |
| 41 | + "date": new_date, |
| 42 | + "from": "b", |
| 43 | + "subj": "T", |
| 44 | + "atts": [], |
| 45 | + }, |
| 46 | + ] |
| 47 | + |
| 48 | + with patch("pgcommitfest.commitfest.ajax._archivesAPI", return_value=api_response): |
| 49 | + refresh_single_thread(thread) |
| 50 | + |
| 51 | + p.refresh_from_db() |
| 52 | + assert p.lastmail == new_date |
0 commit comments