Пример #1
0
def test_contains_object():
    """Test contains_object"""
    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, obj2])

    assert o.contains_object(obj3, prem1)
    assert not o.contains_object(obj3, prem2)
Пример #2
0
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
Пример #3
0
def test_object_count():
    """Test object_count"""
    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])
    assert o.object_count(prem) == 3
def test_agent_count():
    """Test agent_count"""
    agent1 = a.agent(p.identifier('a', 'b', 'agent'), 'nimi', 'tyyppi1')
    agent2 = a.agent(p.identifier('a', 'b', 'agent'), 'nimi', 'tyyppi2')
    agent3 = a.agent(p.identifier('a', 'b', 'agent'), 'nimi', 'tyyppi1')
    premisroot = p.premis(child_elements=[agent1, agent2, agent3])
    assert a.agent_count(premisroot) == 3
Пример #5
0
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')
Пример #7
0
def test_event_count():
    """Test event_count"""
    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])
    assert e.event_count(xml) == 3
def test_premis():
    """Test PREMIS root generation"""
    tree = ET.tostring(p.premis())
    xml = ('<premis:premis'
           ' xsi:schemaLocation="info:lc/xmlns/premis-v2'
           ' http://www.loc.gov/standards/premis/v2/premis-v2-3.xsd"'
           ' xmlns:premis = "info:lc/xmlns/premis-v2"'
           ' xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"'
           '  version="2.2"/>')
    tree_xml = ET.tostring(ET.fromstring(xml))
    assert tree == tree_xml
def test_iter_elements():
    """Test iter_elements"""
    obj1 = o.object(p.identifier('local', 'id01'), original_name='nimi1')
    obj2 = o.object(p.identifier('local', 'id02'), original_name='nimi2')
    obj3 = o.object(p.identifier('local', 'id03'), original_name='nimi3')
    xml = p.premis(child_elements=[obj1, obj2, obj3])
    i = 0
    for name in p.iter_elements(xml, 'originalName'):
        i = i + 1
        assert name.text == 'nimi' + str(i)
    assert i == 3
def test_iter_agents():
    """Test iter_agents"""
    agent1 = a.agent(p.identifier('a', 'b', 'agent'), 'nimi1', 'tyyppi')
    agent2 = a.agent(p.identifier('a', 'b', 'agent'), 'nimi2', 'tyyppi')
    agent3 = a.agent(p.identifier('a', 'b', 'agent'), 'nimi3', 'tyyppi')
    premisroot = p.premis(child_elements=[agent1, agent2, agent3])
    i = 0
    for _agent in a.iter_agents(premisroot):
        i = i + 1
        assert a.parse_name(_agent) == 'nimi' + str(i)
    assert i == 3
Пример #11
0
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')
Пример #12
0
def test_iter_events():
    """Test iter_events"""
    event1 = e.event(p.identifier('local', 'id1', 'event'), 'tyyppi1',
                     '2012-12-12T12:12:12', 'detaili1')
    event2 = e.event(p.identifier('local', 'id2', 'event'), 'tyyppi2',
                     '2012-12-12T12:12:12', 'detaili2')
    event3 = e.event(p.identifier('local', 'id3', 'event'), 'tyyppi3',
                     '2012-12-12T12:12:12', 'detaili2')
    premisroot = p.premis(child_elements=[event1, event2, event3])
    i = 0
    for event in e.iter_events(premisroot):
        i = i + 1
        assert e.parse_event_type(event) == 'tyyppi' + six.text_type(i)
    assert i == 3
Пример #13
0
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