def test_find_object_by_id(): """Test find_object_by_id""" object1 = o.object(p.identifier('local', 'id1', 'object')) object2 = o.object(p.identifier('local', 'id2', 'object')) object3 = o.object(p.identifier('local', 'id3', 'object')) xml = p.premis(child_elements=[object1, object2, object3]) obj = o.find_object_by_id(xml, 'id2') assert p.parse_identifier_type_value(p.parse_identifier(obj)) == ('local', 'id2')
def test_find_agent_by_id(): """Test find_agent_by_id""" agent1 = a.agent(p.identifier('local', 'id1', 'agent'), 'name', 'type1') agent2 = a.agent(p.identifier('local', 'id2', 'agent'), 'name', 'type2') agent3 = a.agent(p.identifier('local', 'id3', 'agent'), 'name', 'type3') xml = p.premis(child_elements=[agent1, agent2, agent3]) agent = a.find_agent_by_id(xml, 'id2') assert p.parse_identifier_type_value(p.parse_identifier(agent, 'agent'), 'agent') == ('local', 'id2')
def test_parse_identifier(): """Test parse_identifier""" obj = o.object(p.identifier('local', 'id01')) object_id = ( '<premis:objectIdentifier xmlns:premis="info:lc/xmlns/premis-v2" ' 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">' '<premis:objectIdentifierType>local</premis:objectIdentifierType>' '<premis:objectIdentifierValue>id01</premis:objectIdentifierValue>' '</premis:objectIdentifier>') assert u.compare_trees(p.parse_identifier(obj), ET.fromstring(object_id))
def test_find_event_by_id(): """Test find_event_by_id""" event1 = e.event(p.identifier('local', 'id1', 'event'), 'tyyppi', '2012-12-12T12:12:12', 'detaili1') event2 = e.event(p.identifier('local', 'id2', 'event'), 'tyyppi', '2012-12-12T12:12:12', 'detaili2') event3 = e.event(p.identifier('local', 'id3', 'event'), 'tyyppi2', '2012-12-12T12:12:12', 'detaili2') xml = p.premis(child_elements=[event1, event2, event3]) event = e.find_event_by_id(xml, 'id2') assert p.parse_identifier_type_value(p.parse_identifier(event, 'event'), 'event') == ('local', 'id2')
def test_objects_with_type(): """Test objects_with_type""" obj1 = o.object(p.identifier('x1', 'y1', 'object')) obj2 = o.object(p.identifier('x1', 'y2', 'object')) obj3 = o.object(p.identifier('x2', 'y3', 'object')) filtered = o.objects_with_type([obj1, obj2, obj3], 'x1') i = 0 for filt_el in filtered: i = i + 1 (id_type, _) = p.parse_identifier_type_value( p.parse_identifier(filt_el, 'object'), 'object') assert id_type == 'x1' assert i == 2
def test_iter_objects(): """Test iter_objects""" obj1 = o.object(p.identifier('x', 'y1', 'object')) obj2 = o.object(p.identifier('x', 'y2', 'object')) obj3 = o.object(p.identifier('x', 'y3', 'object')) prem = p.premis(child_elements=[obj1, obj2, obj3]) iterator = o.iter_objects(prem) i = 0 for iter_elem in iterator: i = i + 1 (_, id_value) = p.parse_identifier_type_value( p.parse_identifier(iter_elem, 'object'), 'object') assert id_value == 'y' + six.text_type(i) assert i == 3
def test_filter_objects(): """Test filter_objects""" obj1 = o.object(p.identifier('x', 'y1', 'object')) obj2 = o.object(p.identifier('x', 'y2', 'object')) obj3 = o.object(p.identifier('x', 'y3', 'object')) prem1 = p.premis(child_elements=[obj1, obj2, obj3]) prem2 = p.premis(child_elements=[obj1, obj3]) filtered = o.filter_objects(o.iter_objects(prem1), prem2) i = 0 for filt_el in filtered: i = i + 1 (_, id_value) = p.parse_identifier_type_value( p.parse_identifier(filt_el, 'object'), 'object') assert id_value == 'y2' assert i == 1