Skip to content

Commit fc25425

Browse files
FennemAIJelteF
authored andcommitted
Hardcode the searched mailing lists and simplify the test
There's no real need for deployments to configure which lists are searched when attaching a thread, so the `ARCHIVES_SEARCH_LISTS` setting is replaced by an inline tuple in `getThreads`. The two tests are folded into one that covers merging, deduplication, ordering and the 100 result cap at once.
1 parent 5aa358f commit fc25425

3 files changed

Lines changed: 21 additions & 58 deletions

File tree

‎pgcommitfest/commitfest/ajax.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def getThreads(request):
9494
params["s"] = search
9595

9696
messages = {}
97-
for listname in settings.ARCHIVES_SEARCH_LISTS:
97+
for listname in ("pgsql-hackers", "pgsql-bugs"):
9898
for m in _archivesAPI("/list/%s/latest.json" % listname, params):
9999
messages.setdefault(m["msgid"], m)
100100

‎pgcommitfest/commitfest/tests/test_get_threads.py‎

Lines changed: 20 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -5,69 +5,34 @@
55
from pgcommitfest.commitfest.ajax import getThreads
66

77

8-
def _msg(msgid, date, subj):
9-
return {"msgid": msgid, "date": date, "from": "a@example.com", "subj": subj}
10-
11-
12-
HACKERS = [
13-
_msg("h1@example.com", "2026-01-03T00:00:00", "hackers thread"),
14-
_msg("both@example.com", "2026-01-01T00:00:00", "sent to both lists"),
15-
]
16-
BUGS = [
17-
_msg("b1@example.com", "2026-01-02T00:00:00", "BUG #1: bugs thread"),
18-
_msg("both@example.com", "2026-01-01T00:00:00", "sent to both lists"),
19-
]
20-
21-
22-
def _fake_archives(suburl, params=None):
23-
return {
24-
"/list/pgsql-hackers/latest.json": HACKERS,
25-
"/list/pgsql-bugs/latest.json": BUGS,
26-
}[suburl]
8+
def _msg(msgid, date):
9+
return {"msgid": msgid, "date": date, "from": "a@example.com", "subj": msgid}
2710

2811

2912
def test_get_threads_searches_hackers_and_bugs():
30-
"""The thread search should return threads from pgsql-bugs too."""
31-
request = RequestFactory().get("/ajax/getThreads/", {"s": "thread", "a": "1"})
32-
33-
with patch(
34-
"pgcommitfest.commitfest.ajax._archivesAPI", side_effect=_fake_archives
35-
) as api:
36-
result = getThreads(request)
37-
38-
# Both lists are searched with the same parameters
39-
assert [c.args for c in api.call_args_list] == [
40-
("/list/pgsql-hackers/latest.json", {"n": 100, "a": 1, "s": "thread"}),
41-
("/list/pgsql-bugs/latest.json", {"n": 100, "a": 1, "s": "thread"}),
42-
]
43-
44-
# Results are merged newest first, and the message sent to both lists
45-
# shows up only once
46-
assert [m["msgid"] for m in result] == [
47-
"h1@example.com",
48-
"b1@example.com",
49-
"both@example.com",
50-
]
51-
52-
53-
def test_get_threads_limits_merged_result():
54-
"""Merging two lists should not return more than one list would."""
5513
hackers = [
56-
_msg("h%d@example.com" % i, "2026-01-01T00:%02d:00" % (i % 60), "h")
57-
for i in range(100)
58-
]
59-
bugs = [
60-
_msg("b%d@example.com" % i, "2026-01-02T00:%02d:00" % (i % 60), "b")
14+
_msg("h%d" % i, "2026-01-01T%02d:%02d:00" % (i // 60, i % 60))
6115
for i in range(100)
6216
]
17+
# b1 is newer than everything on hackers, h99 was sent to both lists
18+
bugs = [_msg("b1", "2026-01-02T00:00:00"), hackers[99]]
6319

6420
def fake(suburl, params=None):
65-
return hackers if "pgsql-hackers" in suburl else bugs
21+
return {
22+
"/list/pgsql-hackers/latest.json": hackers,
23+
"/list/pgsql-bugs/latest.json": bugs,
24+
}[suburl]
6625

67-
request = RequestFactory().get("/ajax/getThreads/")
68-
with patch("pgcommitfest.commitfest.ajax._archivesAPI", side_effect=fake):
26+
request = RequestFactory().get("/ajax/getThreads/", {"s": "x", "a": "1"})
27+
with patch("pgcommitfest.commitfest.ajax._archivesAPI", side_effect=fake) as api:
6928
result = getThreads(request)
7029

71-
assert len(result) == 100
72-
# The bugs messages are all newer, so they are the ones that are kept
73-
assert all(m["msgid"].startswith("b") for m in result)
30+
assert [c.args for c in api.call_args_list] == [
31+
("/list/pgsql-hackers/latest.json", {"n": 100, "a": 1, "s": "x"}),
32+
("/list/pgsql-bugs/latest.json", {"n": 100, "a": 1, "s": "x"}),
33+
]
34+
# Merged newest first, h99 deduplicated, and capped at 100 so the oldest
35+
# message (h0) is dropped.
36+
assert [m["msgid"] for m in result] == ["b1"] + [
37+
"h%d" % i for i in range(99, 0, -1)
38+
]

‎pgcommitfest/settings.py‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,6 @@
157157
ARCHIVES_PORT = "8001"
158158
ARCHIVES_HOST = "archives.postgresql.org" # Host: header to send
159159
ARCHIVES_APIKEY = None
160-
# Mailing lists searched when attaching a thread to a patch
161-
ARCHIVES_SEARCH_LISTS = ["pgsql-hackers", "pgsql-bugs"]
162160

163161
# Email address to pgsql-hackers. Set to something local to test maybe?
164162
HACKERS_EMAIL = "pgsql-hackers-testing@localhost"

0 commit comments

Comments
 (0)