Skip to content

Commit

Permalink
Merge pull request #40 from unt-libraries/test-doSimpleXMLAssignment
Browse files Browse the repository at this point in the history
Tests for doSimpleXMLAssignment.
  • Loading branch information
damonkelley committed Oct 27, 2015
2 parents aaba8e8 + 8184edc commit e2cc171
Showing 1 changed file with 101 additions and 0 deletions.
101 changes: 101 additions & 0 deletions tests/test_presentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,3 +573,104 @@ def test_agent_type(self):
element = agent_xml.agentType
assert element == agent.agent_type
assert has_premis_namespace(element)


class TestDoSimpleXMLAssignment:

@pytest.fixture
def record_obj(self):
class Record(object):
value = None
return Record()

def test_attribute_not_set_when_element_value_is_none(self, record_obj):
tree = etree.fromstring(
"""<root>
<element/>
</root>
"""
)

chain = ['element']

record_obj.value = 10
presentation.doSimpleXMLAssignment(record_obj, 'd', tree, chain)
assert record_obj.value == 10

def test_without_nested_elements(self, record_obj):
tree = etree.fromstring(
"""<root>
<element>1</element>
</root>
"""
)

chain = ['element']

# Since the function mutates the object, we will verify that the
# attribute is the expected value before the function call.
assert record_obj.value is None
presentation.doSimpleXMLAssignment(record_obj, 'value', tree, chain)
assert record_obj.value == '1'

def test_chain_is_name_of_element(self, record_obj):
tree = etree.fromstring(
"""<root>
<element>1</element>
</root>
"""
)

chain = 'element'

assert record_obj.value is None
presentation.doSimpleXMLAssignment(record_obj, 'value', tree, chain)
assert record_obj.value == '1'

def test_with_one_nested_element(self, record_obj):
tree = etree.fromstring(
"""<root>
<element>
<subelement>1</subelement>
</element>
</root>
"""
)

chain = ['element', 'subelement']

assert record_obj.value is None
presentation.doSimpleXMLAssignment(record_obj, 'value', tree, chain)
assert record_obj.value == '1'

def test_with_two_nested_elements(self, record_obj):
tree = etree.fromstring(
"""<root>
<element>
<subelement>
<subsubelement>1</subsubelement>
</subelement>
</element>
</root>
"""
)

chain = ['element', 'subelement', 'subsubelement']

assert record_obj.value is None
presentation.doSimpleXMLAssignment(record_obj, 'value', tree, chain)
assert record_obj.value == '1'

def test_element_text_is_stripped(self, record_obj):
tree = etree.fromstring(
"""<root>
<element> 1 </element>
</root>
"""
)

chain = ['element']

assert record_obj.value is None
presentation.doSimpleXMLAssignment(record_obj, 'value', tree, chain)
assert record_obj.value == '1'

0 comments on commit e2cc171

Please sign in to comment.