-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: Add functions for pack/unpack of all identifiers at once
- Loading branch information
1 parent
5f648e5
commit d931400
Showing
2 changed files
with
75 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
from lxml import etree | ||
|
||
from caselawclient.factories import DocumentFactory | ||
from tests.models.identifiers.test_identifiers import TestIdentifier | ||
|
||
|
||
class TestDocumentIdentifiers: | ||
def test_add_identifiers(self): | ||
document = DocumentFactory.build() | ||
|
||
identifier_1 = TestIdentifier(uuid="e28e3ef1-85ed-4997-87ee-e7428a6cc02e", value="TEST-123") | ||
identifier_2 = TestIdentifier(uuid="14ce4b3b-03c8-44f9-a29e-e02ce35fe136", value="TEST-456") | ||
document.add_identifier(identifier_1) | ||
document.add_identifier(identifier_2) | ||
|
||
assert document.identifiers == { | ||
"e28e3ef1-85ed-4997-87ee-e7428a6cc02e": identifier_1, | ||
"14ce4b3b-03c8-44f9-a29e-e02ce35fe136": identifier_2, | ||
} | ||
|
||
def test_identifiers_as_etree(self): | ||
document = DocumentFactory.build() | ||
|
||
identifier_1 = TestIdentifier(uuid="e28e3ef1-85ed-4997-87ee-e7428a6cc02e", value="TEST-123") | ||
identifier_2 = TestIdentifier(uuid="14ce4b3b-03c8-44f9-a29e-e02ce35fe136", value="TEST-456") | ||
document.add_identifier(identifier_1) | ||
document.add_identifier(identifier_2) | ||
|
||
expected_xml = """ | ||
<identifiers> | ||
<identifier> | ||
<namespace>test</namespace> | ||
<uuid>e28e3ef1-85ed-4997-87ee-e7428a6cc02e</uuid> | ||
<value>TEST-123</value> | ||
</identifier> | ||
<identifier> | ||
<namespace>test</namespace> | ||
<uuid>14ce4b3b-03c8-44f9-a29e-e02ce35fe136</uuid> | ||
<value>TEST-456</value> | ||
</identifier> | ||
</identifiers> | ||
""" | ||
|
||
assert etree.canonicalize(document.identifiers_as_etree(), strip_text=True) == etree.canonicalize( | ||
etree.fromstring(expected_xml), strip_text=True | ||
) |