|
5 | 5 | from pgcommitfest.commitfest.ajax import getThreads |
6 | 6 |
|
7 | 7 |
|
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} |
27 | 10 |
|
28 | 11 |
|
29 | 12 | 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.""" |
55 | 13 | 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)) |
61 | 15 | for i in range(100) |
62 | 16 | ] |
| 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]] |
63 | 19 |
|
64 | 20 | 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] |
66 | 25 |
|
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: |
69 | 28 | result = getThreads(request) |
70 | 29 |
|
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 | + ] |
0 commit comments