-
Notifications
You must be signed in to change notification settings - Fork 396
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: merge main to release
- Loading branch information
Showing
20 changed files
with
448 additions
and
533 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,6 @@ | |
from pathlib import Path | ||
from pyquery import PyQuery | ||
from urllib.parse import urlparse, parse_qs | ||
from tempfile import NamedTemporaryFile | ||
from collections import defaultdict | ||
from zoneinfo import ZoneInfo | ||
|
||
|
@@ -51,6 +50,7 @@ | |
DraftAliasGenerator, | ||
generate_idnits2_rfc_status, | ||
generate_idnits2_rfcs_obsoleted, | ||
get_doc_email_aliases, | ||
) | ||
from ietf.group.models import Group, Role | ||
from ietf.group.factories import GroupFactory, RoleFactory | ||
|
@@ -2169,24 +2169,6 @@ def test_references(self): | |
self.assertContains(r, doc1.name) | ||
|
||
class GenerateDraftAliasesTests(TestCase): | ||
def setUp(self): | ||
super().setUp() | ||
self.doc_aliases_file = NamedTemporaryFile(delete=False, mode="w+") | ||
self.doc_aliases_file.close() | ||
self.doc_virtual_file = NamedTemporaryFile(delete=False, mode="w+") | ||
self.doc_virtual_file.close() | ||
self.saved_draft_aliases_path = settings.DRAFT_ALIASES_PATH | ||
self.saved_draft_virtual_path = settings.DRAFT_VIRTUAL_PATH | ||
settings.DRAFT_ALIASES_PATH = self.doc_aliases_file.name | ||
settings.DRAFT_VIRTUAL_PATH = self.doc_virtual_file.name | ||
|
||
def tearDown(self): | ||
settings.DRAFT_ALIASES_PATH = self.saved_draft_aliases_path | ||
settings.DRAFT_VIRTUAL_PATH = self.saved_draft_virtual_path | ||
os.unlink(self.doc_aliases_file.name) | ||
os.unlink(self.doc_virtual_file.name) | ||
super().tearDown() | ||
|
||
@override_settings(TOOLS_SERVER="tools.example.org", DRAFT_ALIAS_DOMAIN="draft.example.org") | ||
def test_generator_class(self): | ||
"""The DraftAliasGenerator should generate the same lists as the old mgmt cmd""" | ||
|
@@ -2286,6 +2268,28 @@ def test_generator_class(self): | |
{k: sorted(v) for k, v in expected_dict.items()}, | ||
) | ||
|
||
# check single name | ||
output = [(alias, alist) for alias, alist in DraftAliasGenerator(Document.objects.filter(name=doc1.name))] | ||
alias_dict = dict(output) | ||
self.assertEqual(len(alias_dict), len(output)) # no duplicate aliases | ||
expected_dict = { | ||
doc1.name: [author1.email_address()], | ||
doc1.name + ".ad": [ad.email_address()], | ||
doc1.name + ".authors": [author1.email_address()], | ||
doc1.name + ".shepherd": [shepherd.email_address()], | ||
doc1.name | ||
+ ".all": [ | ||
author1.email_address(), | ||
ad.email_address(), | ||
shepherd.email_address(), | ||
], | ||
} | ||
# Sort lists for comparison | ||
self.assertEqual( | ||
{k: sorted(v) for k, v in alias_dict.items()}, | ||
{k: sorted(v) for k, v in expected_dict.items()}, | ||
) | ||
|
||
@override_settings(TOOLS_SERVER="tools.example.org", DRAFT_ALIAS_DOMAIN="draft.example.org") | ||
def test_get_draft_notify_emails(self): | ||
ad = PersonFactory() | ||
|
@@ -2336,37 +2340,20 @@ def setUp(self): | |
WgDraftFactory(name='draft-ietf-mars-test',group__acronym='mars') | ||
WgDraftFactory(name='draft-ietf-ames-test',group__acronym='ames') | ||
RoleFactory(group__type_id='review', group__acronym='yangdoctors', name_id='secr') | ||
self.doc_alias_file = NamedTemporaryFile(delete=False, mode='w+') | ||
self.doc_alias_file.write("""# Generated by hand at 2015-02-12_16:26:45 | ||
virtual.ietf.org anything | ||
[email protected] xfilter-draft-ietf-mars-test | ||
[email protected] [email protected], [email protected] | ||
[email protected] xfilter-draft-ietf-mars-test.authors | ||
[email protected] [email protected], [email protected] | ||
[email protected] xfilter-draft-ietf-mars-test.chairs | ||
[email protected] [email protected] | ||
[email protected] xfilter-draft-ietf-mars-test.all | ||
[email protected] [email protected], [email protected], [email protected] | ||
[email protected] xfilter-draft-ietf-ames-test | ||
[email protected] [email protected], [email protected] | ||
[email protected] xfilter-draft-ietf-ames-test.authors | ||
[email protected] [email protected], [email protected] | ||
[email protected] xfilter-draft-ietf-ames-test.chairs | ||
[email protected] [email protected] | ||
[email protected] xfilter-draft-ietf-ames-test.all | ||
[email protected] [email protected], [email protected], [email protected] | ||
""") | ||
self.doc_alias_file.close() | ||
self.saved_draft_virtual_path = settings.DRAFT_VIRTUAL_PATH | ||
settings.DRAFT_VIRTUAL_PATH = self.doc_alias_file.name | ||
|
||
def tearDown(self): | ||
settings.DRAFT_VIRTUAL_PATH = self.saved_draft_virtual_path | ||
os.unlink(self.doc_alias_file.name) | ||
super().tearDown() | ||
|
||
def testAliases(self): | ||
|
||
|
||
@mock.patch("ietf.doc.views_doc.get_doc_email_aliases") | ||
def testAliases(self, mock_get_aliases): | ||
mock_get_aliases.return_value = [ | ||
{"doc_name": "draft-ietf-mars-test", "alias_type": "", "expansion": "[email protected], [email protected]"}, | ||
{"doc_name": "draft-ietf-mars-test", "alias_type": ".authors", "expansion": "[email protected], [email protected]"}, | ||
{"doc_name": "draft-ietf-mars-test", "alias_type": ".chairs", "expansion": "[email protected]"}, | ||
{"doc_name": "draft-ietf-mars-test", "alias_type": ".all", "expansion": "[email protected], [email protected], [email protected]"}, | ||
{"doc_name": "draft-ietf-ames-test", "alias_type": "", "expansion": "[email protected], [email protected]"}, | ||
{"doc_name": "draft-ietf-ames-test", "alias_type": ".authors", "expansion": "[email protected], [email protected]"}, | ||
{"doc_name": "draft-ietf-ames-test", "alias_type": ".chairs", "expansion": "[email protected]"}, | ||
{"doc_name": "draft-ietf-ames-test", "alias_type": ".all", "expansion": "[email protected], [email protected], [email protected]"}, | ||
] | ||
PersonFactory(user__username='plain') | ||
url = urlreverse('ietf.doc.urls.redirect.document_email', kwargs=dict(name="draft-ietf-mars-test")) | ||
r = self.client.get(url) | ||
|
@@ -2376,16 +2363,70 @@ def testAliases(self): | |
login_testing_unauthorized(self, "plain", url) | ||
r = self.client.get(url) | ||
self.assertEqual(r.status_code, 200) | ||
self.assertEqual(mock_get_aliases.call_args, mock.call()) | ||
self.assertTrue(all([x in unicontent(r) for x in ['mars-test@','mars-test.authors@','mars-test.chairs@']])) | ||
self.assertTrue(all([x in unicontent(r) for x in ['ames-test@','ames-test.authors@','ames-test.chairs@']])) | ||
|
||
def testExpansions(self): | ||
|
||
@mock.patch("ietf.doc.views_doc.get_doc_email_aliases") | ||
def testExpansions(self, mock_get_aliases): | ||
mock_get_aliases.return_value = [ | ||
{"doc_name": "draft-ietf-mars-test", "alias_type": "", "expansion": "[email protected], [email protected]"}, | ||
{"doc_name": "draft-ietf-mars-test", "alias_type": ".authors", "expansion": "[email protected], [email protected]"}, | ||
{"doc_name": "draft-ietf-mars-test", "alias_type": ".chairs", "expansion": "[email protected]"}, | ||
{"doc_name": "draft-ietf-mars-test", "alias_type": ".all", "expansion": "[email protected], [email protected], [email protected]"}, | ||
] | ||
url = urlreverse('ietf.doc.views_doc.document_email', kwargs=dict(name="draft-ietf-mars-test")) | ||
r = self.client.get(url) | ||
self.assertEqual(mock_get_aliases.call_args, mock.call("draft-ietf-mars-test")) | ||
self.assertEqual(r.status_code, 200) | ||
self.assertContains(r, '[email protected]') | ||
self.assertContains(r, 'iesg_ballot_saved') | ||
|
||
@mock.patch("ietf.doc.utils.DraftAliasGenerator") | ||
def test_get_doc_email_aliases(self, mock_alias_gen_cls): | ||
mock_alias_gen_cls.return_value = [ | ||
("draft-something-or-other.some-type", ["[email protected]"]), | ||
("draft-something-or-other", ["[email protected]"]), | ||
("draft-nothing-at-all", ["[email protected]"]), | ||
("draft-nothing-at-all.some-type", ["[email protected]"]), | ||
] | ||
# order is important in the response - should be sorted by doc name and otherwise left | ||
# in order | ||
self.assertEqual( | ||
get_doc_email_aliases(), | ||
[ | ||
{ | ||
"doc_name": "draft-nothing-at-all", | ||
"alias_type": "", | ||
"expansion": "[email protected]", | ||
}, | ||
{ | ||
"doc_name": "draft-nothing-at-all", | ||
"alias_type": ".some-type", | ||
"expansion": "[email protected]", | ||
}, | ||
{ | ||
"doc_name": "draft-something-or-other", | ||
"alias_type": ".some-type", | ||
"expansion": "[email protected]", | ||
}, | ||
{ | ||
"doc_name": "draft-something-or-other", | ||
"alias_type": "", | ||
"expansion": "[email protected]", | ||
}, | ||
], | ||
) | ||
self.assertEqual(mock_alias_gen_cls.call_args, mock.call(None)) | ||
|
||
# Repeat with a name, no need to re-test that the alias list is actually passed through, just | ||
# check that the DraftAliasGenerator is called correctly | ||
draft = WgDraftFactory() | ||
get_doc_email_aliases(draft.name) | ||
self.assertQuerySetEqual(mock_alias_gen_cls.call_args[0][0], Document.objects.filter(pk=draft.pk)) | ||
|
||
|
||
class DocumentMeetingTests(TestCase): | ||
|
||
def setUp(self): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.