Skip to content

Commit 43952a8

Browse files
fix: do not prematurely dereference status change RelatedDocuments (ietf-tools#3835)
* test: add tests of the person_link tag * fix: do not prematurely dereference status change RelatedDocuments The urlize_related_source_list template tag expects the RelatedDocument instances, not the source Document. * test: add test cases for status changes on document_main view
1 parent b44fc55 commit 43952a8

6 files changed

Lines changed: 125 additions & 8 deletions

File tree

ietf/doc/factories.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ def changes_status_of(obj, create, extracted, **kwargs):
273273
return
274274
if extracted:
275275
for (rel, target) in extracted:
276-
obj.relateddocument_set.create(relationship_id=rel,target=extracted)
276+
obj.relateddocument_set.create(relationship_id=rel,target=target)
277277
else:
278278
obj.relateddocument_set.create(relationship_id='tobcp', target=WgRfcFactory().docalias.first())
279279

ietf/doc/templatetags/ietf_filters.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ def urlize_ietf_docs(string, autoescape=None):
232232

233233
@register.filter(name='urlize_related_source_list', is_safe=True, needs_autoescape=True)
234234
def urlize_related_source_list(related, autoescape=None):
235-
"""Convert a list of DocumentRelations into list of links using the source document's canonical name"""
235+
"""Convert a list of RelatedDocuments into list of links using the source document's canonical name"""
236236
links = []
237237
names = set()
238238
titles = set()
@@ -256,7 +256,7 @@ def urlize_related_source_list(related, autoescape=None):
256256

257257
@register.filter(name='urlize_related_target_list', is_safe=True, needs_autoescape=True)
258258
def urlize_related_target_list(related, autoescape=None):
259-
"""Convert a list of DocumentRelations into list of links using the source document's canonical name"""
259+
"""Convert a list of RelatedDocuments into list of links using the target document's canonical name"""
260260
links = []
261261
for rel in related:
262262
name=rel.target.document.canonical_name()

ietf/doc/tests.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,51 @@ def assert_correct_wg_group_link(self, r, group):
797797
msg_prefix='WG-like group %s (%s) should include group type in link' % (group.acronym, group.type),
798798
)
799799

800+
def test_draft_status_changes(self):
801+
draft = WgRfcFactory()
802+
status_change_doc = StatusChangeFactory(
803+
group=draft.group,
804+
changes_status_of=[('tops', draft.docalias.first())],
805+
)
806+
status_change_url = urlreverse(
807+
'ietf.doc.views_doc.document_main',
808+
kwargs={'name': status_change_doc.name},
809+
)
810+
proposed_status_change_doc = StatusChangeFactory(
811+
group=draft.group,
812+
changes_status_of=[('tobcp', draft.docalias.first())],
813+
states=[State.objects.get(slug='needshep', type='statchg')],
814+
)
815+
proposed_status_change_url = urlreverse(
816+
'ietf.doc.views_doc.document_main',
817+
kwargs={'name': proposed_status_change_doc.name},
818+
)
819+
820+
r = self.client.get(
821+
urlreverse(
822+
'ietf.doc.views_doc.document_main',
823+
kwargs={'name': draft.canonical_name()},
824+
)
825+
)
826+
self.assertEqual(r.status_code, 200)
827+
response_content = r.content.decode()
828+
self.assertInHTML(
829+
'Status changed by <a href="{url}" title="{title}">{name}</a>'.format(
830+
name=status_change_doc.name,
831+
title=status_change_doc.title,
832+
url=status_change_url,
833+
),
834+
response_content,
835+
)
836+
self.assertInHTML(
837+
'Proposed status changed by <a href="{url}" title="{title}">{name}</a>'.format(
838+
name=proposed_status_change_doc.name,
839+
title=proposed_status_change_doc.title,
840+
url=proposed_status_change_url,
841+
),
842+
response_content,
843+
)
844+
800845
def assert_correct_non_wg_group_link(self, r, group):
801846
"""Assert correct format for non-WG-like group types"""
802847
self.assertContains(

ietf/doc/views_doc.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -348,9 +348,17 @@ def document_main(request, name, rev=None):
348348
# conflict reviews
349349
conflict_reviews = [r.source.name for r in interesting_relations_that.filter(relationship="conflrev")]
350350

351-
status_change_docs = interesting_relations_that.filter(relationship__in=STATUSCHANGE_RELATIONS)
352-
status_changes = [ r.source for r in status_change_docs if r.source.get_state_slug() in ('appr-sent','appr-pend')]
353-
proposed_status_changes = [ r.source for r in status_change_docs if r.source.get_state_slug() in ('needshep','adrev','iesgeval','defer','appr-pr')]
351+
# status changes
352+
status_changes = []
353+
proposed_status_changes = []
354+
for r in interesting_relations_that.filter(relationship__in=STATUSCHANGE_RELATIONS):
355+
state_slug = r.source.get_state_slug()
356+
if state_slug in ('appr-sent', 'appr-pend'):
357+
status_changes.append(r)
358+
elif state_slug in ('needshep','adrev','iesgeval','defer','appr-pr'):
359+
proposed_status_changes.append(r)
360+
else:
361+
pass
354362

355363
presentations = doc.future_presentations()
356364

ietf/person/templatetags/tests.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Copyright The IETF Trust 2022, All Rights Reserved
2+
from ietf.person.factories import PersonFactory
3+
from ietf.utils.test_utils import TestCase
4+
5+
from .person_filters import person_link
6+
7+
8+
class PersonLinkTests(TestCase):
9+
# Tests of the person_link template tag. These assume it is implemented as an
10+
# inclusion tag.
11+
# TODO test that the template actually renders the data in the dict
12+
def test_person_link(self):
13+
person = PersonFactory()
14+
self.assertEqual(
15+
person_link(person),
16+
{
17+
'name': person.name,
18+
'plain_name': person.plain_name(),
19+
'email': person.email_address(),
20+
'title': '',
21+
'class': '',
22+
'with_email': True,
23+
}
24+
)
25+
self.assertEqual(
26+
person_link(person, with_email=False),
27+
{
28+
'name': person.name,
29+
'plain_name': person.plain_name(),
30+
'email': person.email_address(),
31+
'title': '',
32+
'class': '',
33+
'with_email': False,
34+
}
35+
)
36+
self.assertEqual(
37+
person_link(person, title='Random Title'),
38+
{
39+
'name': person.name,
40+
'plain_name': person.plain_name(),
41+
'email': person.email_address(),
42+
'title': 'Random Title',
43+
'class': '',
44+
'with_email': True,
45+
}
46+
)
47+
self.assertEqual(
48+
# funny syntax because 'class' is a Python keyword
49+
person_link(person, **{'class': 'some-class'}),
50+
{
51+
'name': person.name,
52+
'plain_name': person.plain_name(),
53+
'email': person.email_address(),
54+
'title': '',
55+
'class': 'some-class',
56+
'with_email': True,
57+
}
58+
)
59+
60+
def test_invalid_person(self):
61+
"""Generates correct context dict when input is invalid/missing"""
62+
self.assertEqual(person_link(None), {})
63+
self.assertEqual(person_link(''), {})
64+
self.assertEqual(person_link("** No value found for 'somevar' **"), {})

ietf/templates/doc/document_draft.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@
6565
{% if obsoletes %}<div>Obsoletes {{ obsoletes|urlize_related_target_list|join:", " }}</div>{% endif %}
6666
{% if updates %}<div>Updates {{ updates|urlize_related_target_list|join:", " }}</div>{% endif %}
6767
{% if status_changes %}
68-
<div>Status changed by {{ status_changes|join:", "|urlize_related_source_list }}</div>
68+
<div>Status changed by {{ status_changes|urlize_related_source_list|join:", " }}</div>
6969
{% endif %}
7070
{% if proposed_status_changes %}
71-
<div>Proposed status changed by {{ proposed_status_changes|join:", "|urlize_related_source_list }}</div>
71+
<div>Proposed status changed by {{ proposed_status_changes|urlize_related_source_list|join:", " }}</div>
7272
{% endif %}
7373
{% if rfc_aliases %}<div>Also known as {{ rfc_aliases|join:", "|urlize_ietf_docs }}</div>{% endif %}
7474
{% if draft_name %}

0 commit comments

Comments
 (0)