def test_Metadata_validate():
    """Nothing is implemented in validate().

    This is here for coverage.
    """
    metadata = us.Metadata()
    assert metadata.validate() is None
def test_Metadata_create_element_dict():
    """Test a UNTL Python object converts to dictionary."""
    metadata = us.Metadata()
    title_text = u'An Official Title'
    series_text = u'The Series Title'
    name_text = u'Oudrid, C. (Cristóbal), 1825-1877.'
    title = us.Title(content=title_text, qualifier=u'officialtitle')
    series_title = us.Title(content=series_text, qualifier=u'seriestitle')
    contributor = us.Contributor(qualifier=u'cmp')
    type_ = us.Type(content=u'per')
    name = us.Name(content=name_text)
    contributor.add_child(type_)
    contributor.add_child(name)
    metadata.add_child(title)
    metadata.add_child(series_title)
    metadata.add_child(contributor)

    untl_dict = metadata.create_element_dict()
    assert untl_dict == {
        'contributor': [
            {'content': {'name': name_text, 'type': u'per'}, 'qualifier': u'cmp'}
        ],
        'title': [
            {'content': title_text, 'qualifier': u'officialtitle'},
            {'content': series_text, 'qualifier': u'seriestitle'}
        ]
    }
def test_Metadata_create_xml_file_ascii_hex(tmpdir):
    """Test the UNTL XML file is created correctly.

    Uses pytest tmdir fixture for temporary file.
    """
    metadata = us.Metadata()
    title = us.Title(content=u'Colecci\xf3n', qualifier=u'seriestitle')
    description = us.Description(content=u'"Fortuna te d\xe9 Dios, hijo"',
                                 qualifier=u'content')
    contributor = us.Contributor(qualifier=u'cmp')
    type_ = us.Type(content=u'per')
    name = us.Name(content=u'Oudrid, C. (Crist\xf3bal), 1825-1877.')
    contributor.add_child(type_)
    contributor.add_child(name)
    metadata.add_child(title)
    metadata.add_child(description)
    metadata.add_child(contributor)

    xml_file = tmpdir.join('untl.xml')
    metadata.create_xml_file(xml_file.strpath)
    assert xml_file.read() == (
        '<?xml version="1.0" encoding="UTF-8"?>\n'
        '<metadata>\n'
        '  <title qualifier="seriestitle">Colección</title>\n'
        '  <contributor qualifier="cmp">\n'
        '    <type>per</type>\n'
        '    <name>Oudrid, C. (Cristóbal), 1825-1877.</name>\n'
        '  </contributor>\n'
        '  <description qualifier="content">"Fortuna te dé Dios, hijo"</description>\n'
        '</metadata>\n'
    )
def test_Metadata_create_xml_use_namespace():
    """Check tag can include the namespace."""
    metadata = us.Metadata()
    metadata.add_child(us.Institution(content='UNT'))
    root = metadata.create_xml(useNamespace=True)
    assert root.tag == '{http://digital2.library.unt.edu/untl/}metadata'
    assert root[0].tag == '{http://digital2.library.unt.edu/untl/}institution'
def test_Metadata_create_xml():
    """Test the metadata ElementTree representation."""
    metadata = us.Metadata()
    title_text = u'Colección'
    description_text = u'Adaption of "Fortuna te dé Dios, hijo"'
    name_text = u'Oudrid, C. (Cristóbal), 1825-1877.'
    title = us.Title(content=title_text, qualifier=u'seriestitle')
    description = us.Description(content=description_text,
                                 qualifier=u'content')
    contributor = us.Contributor(qualifier=u'cmp')
    type_ = us.Type(content=u'per')
    name = us.Name(content=name_text)
    contributor.add_child(type_)
    contributor.add_child(name)
    metadata.add_child(title)
    metadata.add_child(description)
    metadata.add_child(contributor)

    root = metadata.create_xml(useNamespace=False)
    assert root.tag == 'metadata'
    # Check are children are there in sorted order.
    assert root[0].tag == u'title'
    assert root[0].text == title_text
    assert root[0].get('qualifier') == u'seriestitle'
    assert root[1].tag == u'contributor'
    assert root[1].get('qualifier') == u'cmp'
    assert root[2].tag == u'description'
    assert root[2].text == description_text
    assert root[2].get('qualifier') == u'content'
    # Check that the contributor children are there.
    assert root[1][0].tag == 'type'
    assert root[1][1].tag == 'name'
    assert root[1][1].text == name_text
def test_Metadata_make_unhidden(test_input_elements, test_input_content):
    """Test if a UNTL hidden element is altered to unhidden."""
    metadata = us.Metadata()
    metadata.children = test_input_elements
    assert metadata.is_hidden is test_input_content
    metadata.make_unhidden()
    assert metadata.is_hidden is False
def test_generate_form_data(_):
    """Test this returns a FormGenerator object."""
    metadata = us.Metadata()
    assert not metadata.children
    fg = metadata.generate_form_data(sort_order=UNTL_PTH_ORDER)
    assert isinstance(fg, us.FormGenerator)
    # Check missing children were added.
    assert len(metadata.children) == len(metadata.contained_children)
Exemple #8
0
def test_untlpy2dict():
    title = us.Title(qualifier='serialtitle', content='The Bronco')
    elements = us.Metadata()
    elements.add_child(title)
    untl_dict = untldoc.untlpy2dict(elements)
    assert untl_dict == {
        'title': [{
            'qualifier': 'serialtitle',
            'content': 'The Bronco'
        }]
    }
Exemple #9
0
def test_untl_to_hash_dict(meaningful_meta, expected_hash_dict):
    title = us.Title(qualifier='serialtitle', content='The Bronco')
    meta_modifier = us.Meta(qualifier='metadataModifier', content='Daniel')
    meta_modification = us.Meta(qualifier='metadataModificationDate',
                                content='2007-09-20, 13:46:15')
    meta_object = us.Meta(qualifier='objectType', content='simple')
    elements = us.Metadata()
    elements.add_child(title)
    elements.add_child(meta_modification)
    elements.add_child(meta_modifier)
    elements.add_child(meta_object)
    hash_dict = untldoc.untl_to_hash_dict(elements, meaningful_meta)
    assert hash_dict == expected_hash_dict
def test_Metadata_create_xml_string():
    """Test our metadata xml is written as expected string."""
    metadata = us.Metadata()
    title = us.Title(content=u'Colección', qualifier=u'seriestitle')
    description = us.Description(content=u'Adaption of "Fortuna te dé Dios, hijo"',
                                 qualifier=u'content')
    metadata.children = [title, description]
    expected_text = """<?xml version="1.0" encoding="UTF-8"?>
<metadata>
  <title qualifier="seriestitle">Colección</title>
  <description qualifier="content">Adaption of "Fortuna te dé Dios, hijo"</description>
</metadata>\n"""
    assert metadata.create_xml_string() == expected_text.encode()
def test_Metadata_sort_untl():
    """Test that elements are sorted correctly."""
    metadata = us.Metadata()
    child1 = us.UNTLElement()
    child1.tag = 'ziggy'
    child2 = us.UNTLElement()
    child2.tag = 'apple'
    child3 = us.UNTLElement()
    child3.tag = 'dash'
    metadata.children = [child1, child2, child3]
    # Sort by the tags in this order.
    metadata.sort_untl(['dash', 'ziggy', 'apple'])
    assert metadata.children == [child3, child1, child2]
def test_Metadata_create_xml_file(tmpdir):
    """Test the UNTL XML file is created correctly.

    Uses pytest tmdir fixture for temporary file.
    """
    metadata = us.Metadata()
    title = us.Title(content=u'Colección', qualifier=u'seriestitle')
    description = us.Description(content=u'"Fortuna te dé Dios, hijo"',
                                 qualifier=u'content')
    contributor = us.Contributor(qualifier=u'cmp')
    type_ = us.Type(content=u'per')
    name = us.Name(content=u'Oudrid, C. (Cristóbal), 1825-1877.')
    contributor.add_child(type_)
    contributor.add_child(name)
    metadata.add_child(title)
    metadata.add_child(description)
    metadata.add_child(contributor)

    xml_file = tmpdir.join('untl.xml')
    metadata.create_xml_file(xml_file.strpath)
    assert xml_file.read() == """<?xml version="1.0" encoding="UTF-8"?>
Exemple #13
0
def test_py2dict():
    """Test UNTL Elements are converted to a dictionary."""
    title = us.Title(qualifier='serialtitle', content='The Bronco')
    name = us.Name(content='Case, J.')
    creator = us.Creator(qualifier='aut')
    creator.add_child(name)
    elements = us.Metadata()
    elements.add_child(title)
    elements.add_child(creator)
    metadata_dict = mg.py2dict(elements)
    assert metadata_dict == {
        'title': [{
            'qualifier': 'serialtitle',
            'content': 'The Bronco'
        }],
        'creator': [{
            'qualifier': 'aut',
            'content': {
                'name': 'Case, J.'
            }
        }]
    }
Exemple #14
0
def test_generate_untl_json(input_indent, json_output):
    title = us.Title(qualifier='serialtitle', content='The Bronco')
    elements = us.Metadata()
    elements.add_child(title)
    untl_json = untldoc.generate_untl_json(elements, input_indent)
    assert untl_json == json_output
def test_Metadata_is_hidden(test_input_content, test_output):
    """Check if a UNTL element is hidden."""
    metadata = us.Metadata()
    metadata.children = test_input_content
    assert metadata.is_hidden is test_output
def test_Metadata_create_xml_file_exception_raised():
    """Test exception when XML file can't be written."""
    metadata = us.Metadata()
    with pytest.raises(us.UNTLStructureException):
        metadata.create_xml_file('/slkfjsldfjsdf/not/real')
def test_Metadata_is_hidden_with_no_meta_hidden_element(capsys):
    metadata = us.Metadata()
    metadata.children = [us.Meta(content='DC', qualifier='system')]
    assert metadata.is_hidden is False
    captured = capsys.readouterr()
    assert captured.err == 'A hidden meta element does not exist.'