Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pgcommitfest/commitfest/ajax.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def parse_and_add_attachments(threadinfo, mailthread):
# One or more attachments. For now, we're only actually going
# to store and process the first one, even though the API gets
# us all of them.
MailThreadAttachment.objects.get_or_create(
MailThreadAttachment.objects.update_or_create(
mailthread=mailthread,
messageid=t["msgid"],
defaults={
Expand Down
20 changes: 16 additions & 4 deletions pgcommitfest/commitfest/tests/test_refresh_thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
import pytest

from pgcommitfest.commitfest.ajax import refresh_single_thread
from pgcommitfest.commitfest.models import MailThread, Patch
from pgcommitfest.commitfest.models import MailThread, MailThreadAttachment, Patch

pytestmark = pytest.mark.django_db


def test_refresh_single_thread_updates_patch_lastmail():
"""Regression test: patch.lastmail should get the new date, not the old one."""
def test_refresh_single_thread():
"""A new mail updates patch.lastmail and refreshes stale attachment info."""
old_date = datetime(2024, 1, 1)
new_date = datetime(2024, 6, 15)

Expand All @@ -26,14 +26,23 @@ def test_refresh_single_thread_updates_patch_lastmail():
)
p = Patch.objects.create(name="Test Patch", lastmail=old_date)
p.mailthread_set.add(thread)
attachment = MailThreadAttachment.objects.create(
mailthread=thread,
messageid="old@example.com",
attachmentid=1,
filename="old.patch",
date=old_date,
author="a",
)

api_response = [
{
"msgid": "old@example.com",
"date": old_date,
"from": "a",
"subj": "T",
"atts": [],
# The archives assigned a new id to the same attachment
"atts": [{"id": 2, "name": "new.patch"}],
},
{
"msgid": "new@example.com",
Expand All @@ -49,3 +58,6 @@ def test_refresh_single_thread_updates_patch_lastmail():

p.refresh_from_db()
assert p.lastmail == new_date
attachment.refresh_from_db()
assert (attachment.attachmentid, attachment.filename) == (2, "new.patch")
assert MailThreadAttachment.objects.filter(mailthread=thread).count() == 1
Loading