Skip to content

Commit

Permalink
tests: asserts <referencegroup> contains the target attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanomunarini committed Dec 27, 2023
1 parent 6660b30 commit 6f45d48
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 7 deletions.
15 changes: 8 additions & 7 deletions xml2rfc_compat/serializers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,14 @@ def serialize(
if anchor:
root.set('anchor', anchor)

# Fill in appropriate target
try:
target = get_suitable_target(as_list(item.link or []))
except ValueError:
pass
else:
root.set('target', target)
if is_referencegroup:
# Fill in appropriate target
try:
target = get_suitable_target(as_list(item.link or []))
except ValueError:
pass
else:
root.set('target', target)

objectify.deannotate(root)
etree.cleanup_namespaces(root)
Expand Down
51 changes: 51 additions & 0 deletions xml2rfc_compat/tests/test_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ def setUp(self):
self.bibitem_referencegroup_data: Dict[str, Any] = {
"id": "ref_02",
"docid": [{"id": "ref_02", "type": "test_dataset_02"}],
"link": {
"content": "https://www.rfc-editor.org/info/std94",
"type": "src"
},
"relation": [
{
"type": "includes",
Expand Down Expand Up @@ -145,6 +149,41 @@ def setUp(self):
{"type": "page", "reference_from": "3"}
]}
},
},{
"type": "includes",
"bibitem": {
"id": "test_id2",
"title": [
{
"content": "title2",
"language": "en",
"script": "Latn",
"format": "text / plain",
}
],
"contributor": [
contributor_organization_data,
self.contributor_person_data,
],
"link": [
{
"content": "https://raw.githubusercontent.com/relaton/relaton-data-ietf/master/data"
"/reference2.RFC"
".19182.xml",
"type": "xml",
}
],
"type": "standard",
"docid": [{"id": "RFC19182", "type": "RFC"}],
"docnumber": "RFC19182",
"date": [{"type": "published", "value": "1998-02-11"}],
"extent": {"locality": [
{"type": "container-title", "reference_from": "Container Title"},
{"type": "volume", "reference_from": "1"},
{"type": "issue", "reference_from": "2"},
{"type": "page", "reference_from": "3"}
]}
},
}
],
}
Expand Down Expand Up @@ -175,6 +214,18 @@ def test_bibliographicitem_to_xml(self):
xmlschema.assertValid(xml_reference)
xmlschema.assertValid(xml_referencegroup)

def test_target_referencegroup(self):
"""
Target should be set as attribute of <referencegroup>.
"""
xml_referencegroup = serialize(self.bibitem_referencegroup)
target = xml_referencegroup.keys()[1]
self.assertEqual(target, "target")
self.assertEqual(
xml_referencegroup.get(target),
self.bibitem_referencegroup_data["link"]["content"]
)

def test_build_refcontent_string(self):
"""
Test build_refcontent_string returns a valid XML output.
Expand Down

0 comments on commit 6f45d48

Please sign in to comment.