Skip to content

Commit 9c73a39

Browse files
committed
Simplify tests
1 parent 13ff01f commit 9c73a39

File tree

2 files changed

+26
-67
lines changed

2 files changed

+26
-67
lines changed

pgcommitfest/commitfest/tests/test_closure_notifications.py

Lines changed: 23 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ def test_no_auto_move_without_email_activity(alice, in_progress_cf, open_cf):
255255
mail = QueuedMail.objects.first()
256256
body = get_email_body(mail)
257257
assert "Inactive Patch" in body
258-
assert "need" in body # "needs attention"
258+
assert "needs attention" in body
259259

260260

261261
def test_no_auto_move_when_failing_too_long(alice, in_progress_cf, open_cf):
@@ -290,6 +290,12 @@ def test_no_auto_move_when_failing_too_long(alice, in_progress_cf, open_cf):
290290
patch.refresh_from_db()
291291
assert patch.current_commitfest().id == in_progress_cf.id
292292

293+
# Author should receive closure notification
294+
assert QueuedMail.objects.count() == 1
295+
mail = QueuedMail.objects.first()
296+
body = get_email_body(mail)
297+
assert "Failing Patch" in body
298+
293299

294300
def test_auto_move_when_failing_within_threshold(alice, in_progress_cf, open_cf):
295301
"""Patches failing CI within the threshold should still be auto-moved."""
@@ -327,68 +333,22 @@ def test_auto_move_when_failing_within_threshold(alice, in_progress_cf, open_cf)
327333
assert QueuedMail.objects.count() == 0
328334

329335

330-
def test_no_auto_move_with_null_lastmail(alice, in_progress_cf, open_cf):
331-
"""Patches with no email activity (null lastmail) should NOT be auto-moved."""
332-
patch = Patch.objects.create(
333-
name="No Activity Patch",
334-
lastmail=None,
335-
)
336-
patch.authors.add(alice)
337-
PatchOnCommitFest.objects.create(
338-
patch=patch,
339-
commitfest=in_progress_cf,
340-
enterdate=datetime.now(),
341-
status=PatchOnCommitFest.STATUS_REVIEW,
342-
)
343-
344-
in_progress_cf.auto_move_active_patches()
345-
346-
patch.refresh_from_db()
347-
assert patch.current_commitfest().id == in_progress_cf.id
348-
349-
350-
def test_auto_move_patch_without_cfbot_branch(alice, in_progress_cf, open_cf):
351-
"""Patches with recent activity but no CI branch should be auto-moved."""
352-
patch = Patch.objects.create(
353-
name="No CI Patch",
354-
lastmail=datetime.now() - timedelta(days=5),
355-
)
356-
patch.authors.add(alice)
357-
PatchOnCommitFest.objects.create(
358-
patch=patch,
359-
commitfest=in_progress_cf,
360-
enterdate=datetime.now(),
361-
status=PatchOnCommitFest.STATUS_REVIEW,
362-
)
363-
364-
# No CfbotBranch created - CI never ran
365-
366-
in_progress_cf.auto_move_active_patches()
367-
in_progress_cf.send_closure_notifications()
368-
369-
patch.refresh_from_db()
370-
assert patch.current_commitfest().id == open_cf.id
371-
372-
# No closure email for moved patches
373-
assert QueuedMail.objects.count() == 0
374-
375-
376336
def test_regular_cf_does_not_move_to_draft_cf(alice, in_progress_cf):
377337
"""Regular commitfest should move patches to the next regular CF, not a draft CF."""
378-
# Create a draft CF - should be ignored for regular CF patches
338+
# Create a draft CF with earlier startdate - should be ignored for regular CF patches
379339
draft_cf = CommitFest.objects.create(
380-
name="2025-05-draft",
340+
name="2024-12-draft",
381341
status=CommitFest.STATUS_OPEN,
382-
startdate=date(2025, 5, 1),
383-
enddate=date(2025, 5, 31),
342+
startdate=date(2024, 12, 1),
343+
enddate=date(2024, 12, 31),
384344
draft=True,
385345
)
386-
# Create a regular CF - this is where patches should go
346+
# Create a regular CF with later startdate - this is where patches should go
387347
regular_cf = CommitFest.objects.create(
388-
name="2025-01",
348+
name="2025-03",
389349
status=CommitFest.STATUS_OPEN,
390-
startdate=date(2025, 1, 1),
391-
enddate=date(2025, 1, 31),
350+
startdate=date(2025, 3, 1),
351+
enddate=date(2025, 3, 31),
392352
draft=False,
393353
)
394354

@@ -422,6 +382,14 @@ def test_draft_cf_moves_active_patches_to_next_draft(alice, bob):
422382
enddate=date(2025, 3, 31),
423383
draft=True,
424384
)
385+
# Create a regular open CF with earlier startdate - should be ignored for draft patches
386+
CommitFest.objects.create(
387+
name="2025-05",
388+
status=CommitFest.STATUS_OPEN,
389+
startdate=date(2025, 5, 1),
390+
enddate=date(2025, 5, 31),
391+
draft=False,
392+
)
425393
next_draft_cf = CommitFest.objects.create(
426394
name="2026-03-draft",
427395
status=CommitFest.STATUS_OPEN,

pgcommitfest/commitfest/tests/test_refresh_commitfests.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,10 @@
77
CommitFest,
88
Patch,
99
PatchOnCommitFest,
10-
Topic,
1110
)
1211
from pgcommitfest.userprofile.models import UserProfile
1312

1413

15-
@pytest.fixture
16-
def topic(db):
17-
return Topic.objects.create(topic="General")
18-
19-
2014
@pytest.fixture
2115
def alice(db, django_user_model):
2216
user = django_user_model.objects.create_user(
@@ -41,7 +35,7 @@ def create_closed_cf(name, startdate, enddate):
4135

4236
@pytest.mark.django_db
4337
@freeze_time("2024-12-05")
44-
def test_inprogress_cf_closes_when_enddate_passed(topic, alice):
38+
def test_inprogress_cf_closes_when_enddate_passed(alice):
4539
"""When an in_progress CF's enddate has passed, it should be closed."""
4640
# Create some closed CFs for padding (relevant_commitfests needs history)
4741
create_closed_cf("2024-07", date(2024, 7, 1), date(2024, 7, 31))
@@ -73,7 +67,6 @@ def test_inprogress_cf_closes_when_enddate_passed(topic, alice):
7367
# Create a patch with recent activity that should be auto-moved
7468
patch = Patch.objects.create(
7569
name="Test Patch",
76-
topic=topic,
7770
lastmail=datetime(2024, 11, 25),
7871
)
7972
patch.authors.add(alice)
@@ -133,7 +126,7 @@ def test_open_cf_becomes_inprogress_when_startdate_reached():
133126

134127
@pytest.mark.django_db
135128
@freeze_time("2025-02-05")
136-
def test_open_cf_closes_when_enddate_passed(topic, alice):
129+
def test_open_cf_closes_when_enddate_passed(alice):
137130
"""When an open CF's enddate has passed (skipping in_progress), it closes."""
138131
# Create some closed CFs for padding
139132
create_closed_cf("2024-07", date(2024, 7, 1), date(2024, 7, 31))
@@ -158,7 +151,6 @@ def test_open_cf_closes_when_enddate_passed(topic, alice):
158151
# Create a patch with recent activity
159152
patch = Patch.objects.create(
160153
name="Test Patch",
161-
topic=topic,
162154
lastmail=datetime(2025, 1, 25),
163155
)
164156
patch.authors.add(alice)
@@ -214,7 +206,7 @@ def test_draft_cf_created_when_missing():
214206

215207
@pytest.mark.django_db
216208
@freeze_time("2025-04-05")
217-
def test_draft_cf_closes_when_enddate_passed(topic, alice):
209+
def test_draft_cf_closes_when_enddate_passed(alice):
218210
"""When a draft CF's enddate has passed, it should be closed."""
219211
# Create closed CFs for padding
220212
create_closed_cf("2024-07", date(2024, 7, 1), date(2024, 7, 31))
@@ -241,7 +233,6 @@ def test_draft_cf_closes_when_enddate_passed(topic, alice):
241233
# Create a patch with recent activity
242234
patch = Patch.objects.create(
243235
name="Draft Patch",
244-
topic=topic,
245236
lastmail=datetime(2025, 3, 25),
246237
)
247238
patch.authors.add(alice)

0 commit comments

Comments
 (0)