Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 56 additions & 2 deletions ietf/doc/tests_utils_rfc_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
PublishedRfcDocEventFactory,
RfcAuthorFactory,
RfcFactory,
RgRfcFactory,
WgRfcFactory,
)
from ietf.doc.models import RelatedDocument
Expand Down Expand Up @@ -245,6 +246,19 @@ def test_april_first_date_format(self):

self.assertEqual(data["pub_date"], "1 April 2020")

def test_empty_keywords_filtered(self):
"""Empty-string keywords are stripped from the keywords list."""
rfc = PublishedRfcDocEventFactory(
doc=WgRfcFactory(keywords=["foo", "", "bar"]),
).doc
_put_pub_levels(rfc.rfc_number, "ps")
_put_empty_errata()

generate_rfc_json(rfc.rfc_number)
data = _read_json(rfc.rfc_number)

self.assertEqual(data["keywords"], ["foo", "bar"])

def test_non_april_first_april_date(self):
"""An April publication that is NOT in the April Fools list gets 'April YYYY'."""
rfc = PublishedRfcDocEventFactory(
Expand All @@ -260,7 +274,7 @@ def test_non_april_first_april_date(self):
self.assertEqual(data["pub_date"], "April 2020")

def test_source_ietf_wg(self):
"""IETF-stream WG RFC: source is 'acronym (area)'."""
"""IETF-stream WG RFC: source is the group's full name."""
area = GroupFactory(type_id="area")
wg = GroupFactory(type_id="wg", parent=area)
rfc = PublishedRfcDocEventFactory(
Expand All @@ -272,7 +286,7 @@ def test_source_ietf_wg(self):
generate_rfc_json(rfc.rfc_number)
data = _read_json(rfc.rfc_number)

self.assertEqual(data["source"], f"{wg.acronym} ({area.acronym})")
self.assertEqual(data["source"], wg.name)

def test_source_ietf_no_wg(self):
"""IETF-stream individual RFC (group acronym 'none'): source is 'IETF - NON WORKING GROUP'."""
Expand All @@ -293,6 +307,22 @@ def test_source_ietf_no_wg(self):

self.assertEqual(data["source"], "IETF - NON WORKING GROUP")

def test_source_ietf_area(self):
"""IETF-stream RFC with area-type group: source is 'IETF - NON WORKING GROUP'."""
area = GroupFactory(type_id="area")
area.parent = GroupFactory()
area.save()
rfc = PublishedRfcDocEventFactory(
doc=RfcFactory(group=area, stream_id="ietf"),
).doc
_put_pub_levels(rfc.rfc_number, "inf")
_put_empty_errata()

generate_rfc_json(rfc.rfc_number)
data = _read_json(rfc.rfc_number)

self.assertEqual(data["source"], "IETF - NON WORKING GROUP")

def test_source_iab(self):
"""IAB-stream RFC: source is 'IAB'."""
rfc = PublishedRfcDocEventFactory(
Expand All @@ -319,6 +349,30 @@ def test_source_ise(self):

self.assertEqual(data["source"], "INDEPENDENT")

def test_source_irtf_rg(self):
"""IRTF-stream RG RFC: source is the group's full name."""
rfc = PublishedRfcDocEventFactory(doc=RgRfcFactory()).doc
_put_pub_levels(rfc.rfc_number, "inf")
_put_empty_errata()

generate_rfc_json(rfc.rfc_number)
data = _read_json(rfc.rfc_number)

self.assertEqual(data["source"], rfc.group.name)

def test_source_irtf_no_rg(self):
"""IRTF-stream RFC with no specific RG (group acronym 'none'): source is 'IRTF'."""
rfc = PublishedRfcDocEventFactory(
doc=RfcFactory(stream_id="irtf", group=GroupFactory(acronym="none")),
).doc
_put_pub_levels(rfc.rfc_number, "inf")
_put_empty_errata()

generate_rfc_json(rfc.rfc_number)
data = _read_json(rfc.rfc_number)

self.assertEqual(data["source"], "IRTF")

def test_pub_levels_passed_in(self):
"""When pub_levels is passed in, get_publication_std_levels() is not called."""
rfc = PublishedRfcDocEventFactory(doc=WgRfcFactory()).doc
Expand Down
20 changes: 9 additions & 11 deletions ietf/doc/utils_rfc_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,31 +105,29 @@ def generate_rfc_json(rfc_number: int, *, pub_levels=None) -> None:
stream_slug = rfc.stream.slug
group_acronym = rfc.group.acronym

area_acronym = None
if stream_slug == "ietf":
if rfc.group.parent is None:
assertion("rfc.group.parent is not None")
log(
f"Malformed document object encountered for rfc{rfc_number}. Aborting update of rfc{rfc_number}.json"
)
return
else:
area_acronym = rfc.group.parent.acronym

if stream_slug == "ise":
source = "INDEPENDENT"
elif stream_slug == "iab":
source = "IAB"
elif stream_slug == "ietf" and (
group_acronym in ("none", "gen") or not area_acronym
group_acronym == "none" or rfc.group.type_id == "area"
):
source = "IETF - NON WORKING GROUP"
elif group_acronym not in ("none", ""):
source = group_acronym
if stream_slug == "ietf" and area_acronym:
source += f" ({area_acronym})"
elif stream_slug:
source += f" ({stream_slug})"
elif stream_slug == "irtf":
if group_acronym == "none":
source = "IRTF"
else:
source = rfc.group.name
elif group_acronym not in ("none", "") and stream_slug in ["ietf", "editorial"]:
source = rfc.group.name
elif stream_slug:
source = "Legacy" if stream_slug == "legacy" else stream_slug.upper()
else:
Expand Down Expand Up @@ -207,7 +205,7 @@ def _rfc_list(qs, attr):
"source": source,
"abstract": rfc.abstract,
"pub_date": pub_date,
"keywords": rfc.keywords,
"keywords": [kw for kw in rfc.keywords if kw],
"obsoletes": obsoletes,
"obsoleted_by": obsoleted_by,
"updates": updates,
Expand Down
Loading