77# pyre-unsafe
88
99import email
10+ import email .parser
11+ import email .policy
1012import json
1113import os
1214import random
4244 prs_for_the_same_series ,
4345 reply_email_recipients ,
4446 same_series_different_target ,
45- send_pr_comment_email ,
4647 temporary_patch_file ,
4748 UPSTREAM_REMOTE_NAME ,
4849)
@@ -1480,26 +1481,21 @@ def test_email_submitter_not_in_allowlist_and_allowlist_disabled(self):
14801481 self .assertEqual (expected_email , email )
14811482
14821483 def test_reply_email_recipients (self ):
1483- kpd_config_json = json .loads (read_fixture ("kpd_config.json" ))
1484- kpd_config = KPDConfig .from_json (kpd_config_json )
1485- self .assertIsNotNone (kpd_config )
1486-
14871484 mbox = read_test_data_file (
14881485 "test_sync_patches_pr_summary_success/series-970926.mbox"
14891486 )
1490- # pyrefly: ignore # implicit-import
14911487 parser = email .parser .BytesParser (policy = email .policy .default )
14921488 msg = parser .parsebytes (mbox .encode ("utf-8" ), headersonly = True )
14931489 self .assertIsNotNone (mbox )
1494- # pyrefly: ignore # missing-attribute
1495- denylist = kpd_config .email .pr_comments_forwarding .recipient_denylist
1490+ denylist = [re .compile (".*@vger.kernel.org" )]
14961491 (to_list , cc_list ) = reply_email_recipients (msg , denylist = denylist )
14971492
1498- self .
assertEqual (
to_list , [
"[email protected] " ])
1499- self .assertEqual (len (cc_list ), 17 )
1493+ self .
assertIn (
"[email protected] " ,
to_list )
1494+ self .assertEqual (len (to_list ), 17 )
1495+ self .assertEqual (len (cc_list ), 1 )
15001496
1501- # test allowlist by using the same denylist
1502- (to_list , cc_list ) = reply_email_recipients (msg , allowlist = denylist )
1497+ allowlist = [ re . compile ( ".*@vger.kernel.org" )]
1498+ (to_list , cc_list ) = reply_email_recipients (msg , allowlist = allowlist )
15031499 self .assertEqual (to_list , [])
15041500 self .assertEqual (len (cc_list ), 3 )
15051501
@@ -1509,8 +1505,23 @@ def test_reply_email_recipients(self):
15091505 (to_list , cc_list ) = reply_email_recipients (
15101506 msg , allowlist = allowlist , denylist = denylist
15111507 )
1508+ self .
assertIn (
"[email protected] " ,
to_list )
1509+ self .assertEqual (len (to_list ), 3 )
1510+ self .assertEqual (len (cc_list ), 1 )
1511+
1512+ # test denylist all
1513+ denylist = [re .compile (".*" )]
1514+ (to_list , cc_list ) = reply_email_recipients (msg , denylist = denylist )
1515+ self .assertEqual (to_list , [])
1516+ self .assertEqual (cc_list , [])
1517+
1518+ # test denylist all, but the sender
1519+ denylist = [re .compile (".*" )]
1520+ (to_list , cc_list ) = reply_email_recipients (
1521+ msg , denylist = denylist , always_reply_to_author = True
1522+ )
15121523 self .
assertEqual (
to_list , [
"[email protected] " ])
1513- self .assertEqual (len ( cc_list ), 3 )
1524+ self .assertEqual (cc_list , [] )
15141525
15151526
15161527class TestParsePrRef (unittest .TestCase ):
@@ -1655,6 +1666,7 @@ async def test_forward_pr_comments(self, m: aioresponses) -> None:
16551666 self ._bw .email_config = MagicMock (
16561667 pr_comments_forwarding = PRCommentsForwardingConfig (
16571668 enabled = True ,
1669+ always_reply_to_author = False ,
1658167016591671 commenter_allowlist = ["test_user" ],
16601672 recipient_denylist = [re .compile (".*@vger.kernel.org" )],
@@ -1702,9 +1714,10 @@ async def test_forward_pr_comments(self, m: aioresponses) -> None:
17021714 mock_send_email .call_args [0 ]
17031715 )
17041716
1705- self .
assertEqual ( to_list , [ "[email protected] " ] )
1706- self .assertEqual (len (cc_list ), 18 )
1717+ self .
assertIn ( "[email protected] " , to_list )
1718+ self .assertEqual (len (to_list ), 17 )
17071719 self .
assertIn (
"[email protected] " ,
cc_list )
1720+ self .assertEqual (len (cc_list ), 2 )
17081721 self .assertEqual (
17091722 "Re: [PATCH bpf-next] bpf: clear user buf when bpf_d_path failed" ,
17101723 subject ,
0 commit comments