Пример #1
0
def test_generate_highwire_xml():
    untl_elements = untldoc.untldict2py(UNTL_DICTIONARY)
    highwire_list = untldoc.untlpy2highwirepy(untl_elements)
    xml = untldoc.generate_highwire_xml(highwire_list)
    expected_xml = (
        b'<?xml version="1.0" encoding="UTF-8"?>\n'
        b'<metadata>\n'
        b'  <meta content="Tres Actos" name="citation_title"/>\n'
        b'  <meta content="Last, Furston, 1807-1865." name="citation_author"/>\n'
        b'  <meta content="Fake Publishing" name="citation_publisher"/>\n'
        b'  <meta content="1944" name="citation_publication_date"/>\n'
        b'</metadata>\n')

    # Get a sorted list of attributes for child elements in the generated and expected XML.
    generated_tree = fromstring(xml)
    generated_attribs = [child.attrib for child in generated_tree]
    generated_attribs = sorted(generated_attribs,
                               key=lambda i: (i['content'], i['name']))
    expected_attribs = [child.attrib for child in fromstring(expected_xml)]
    expected_attribs = sorted(expected_attribs,
                              key=lambda i: (i['content'], i['name']))
    assert expected_attribs == generated_attribs

    # Our generated XML has a `metadata` element with all `meta` element children.
    assert generated_tree.tag == 'metadata'
    for child in generated_tree:
        assert child.tag == 'meta'
Пример #2
0
def test_generate_highwire_json():
    untl_elements = untldoc.untldict2py(UNTL_DICTIONARY)
    highwire_list = untldoc.untlpy2highwirepy(untl_elements)
    highwire_json = untldoc.generate_highwire_json(highwire_list)
    assert highwire_json == (
        '{\n'
        '    "citation_author": [\n'
        '        {\n'
        '            "content": "Last, Furston, 1807-1865."\n'
        '        }\n'
        '    ],\n'
        '    "citation_publication_date": [\n'
        '        {\n'
        '            "content": "1944"\n'
        '        }\n'
        '    ],\n'
        '    "citation_publisher": [\n'
        '        {\n'
        '            "content": "Fake Publishing"\n'
        '        }\n'
        '    ],\n'
        '    "citation_title": [\n'
        '        {\n'
        '            "content": "Tres Actos"\n'
        '        }\n'
        '    ]\n'
        '}')
Пример #3
0
    def testXml(self):
        """Test highwire elements are converted to XML bytes.

        Because the order of attributes is not guaranteed, we convert the
        generated bytes and expected bytes into ElementTrees to compare
        the attributes.
        """
        untlpy = untldict2py(UNTL_DICT)
        highwire_elements = untlpy2highwirepy(untlpy)
        highwire_xml = generate_highwire_xml(highwire_elements)

        # Get a sorted list of attributes for child elements in the generated and expected XML.
        generated_tree = fromstring(highwire_xml)
        generated_attribs = [child.attrib for child in generated_tree]
        generated_attribs = sorted(generated_attribs,
                                   key=lambda i: (i['content'], i['name']))
        expected_attribs = [child.attrib for child in fromstring(HIGHWIRE_XML)]
        expected_attribs = sorted(expected_attribs,
                                  key=lambda i: (i['content'], i['name']))
        self.assertEqual(expected_attribs, generated_attribs)

        # Our generated XML has a `metadata` element with all `meta` element children.
        self.assertEqual(generated_tree.tag, 'metadata')
        for child in generated_tree:
            self.assertEqual(child.tag, 'meta')
Пример #4
0
def test_generate_highwire_text():
    untl_elements = untldoc.untldict2py(UNTL_DICTIONARY)
    highwire_list = untldoc.untlpy2highwirepy(untl_elements)
    text = untldoc.generate_highwire_text(highwire_list)
    assert text == ('citation_title: Tres Actos\n'
                    'citation_author: Last, Furston, 1807-1865.\n'
                    'citation_publisher: Fake Publishing\n'
                    'citation_publication_date: 1944')
Пример #5
0
def test_untlpy2highwirepy_not_official_title():
    untl_dict = {
        'title': [{
            'qualifier': 'alternatetitle',
            'content': 'Tres Actos'
        }]
    }
    untl_elements = untldoc.untldict2py(untl_dict)
    highwire_list = untldoc.untlpy2highwirepy(untl_elements)
    assert len(highwire_list) == 1
    assert highwire_list[0].qualifier == 'alternatetitle'
    assert highwire_list[0].name == 'citation_title'
    assert highwire_list[0].content == 'Tres Actos'
Пример #6
0
def test_highwirepy2dict():
    untl_elements = untldoc.untldict2py(UNTL_DICTIONARY)
    highwire_list = untldoc.untlpy2highwirepy(untl_elements)
    highwire_dict = untldoc.highwirepy2dict(highwire_list)
    assert highwire_dict == {
        'citation_author': [{
            'content': 'Last, Furston, 1807-1865.'
        }],
        'citation_publisher': [{
            'content': 'Fake Publishing'
        }],
        'citation_publication_date': [{
            'content': '1944'
        }],
        'citation_title': [{
            'content': 'Tres Actos'
        }]
    }
Пример #7
0
def test_untlpy2highwirepy():
    untl_elements = untldoc.untldict2py(UNTL_DICTIONARY)
    highwire_list = untldoc.untlpy2highwirepy(untl_elements)
    assert len(highwire_list) == 4
    for element in highwire_list:
        assert element.tag == 'meta'
    assert highwire_list[0].qualifier == 'aut'
    assert highwire_list[0].name == 'citation_author'
    assert highwire_list[0].content == 'Last, Furston, 1807-1865.'
    assert highwire_list[1].qualifier is None
    assert highwire_list[1].name == 'citation_publisher'
    assert highwire_list[1].content == 'Fake Publishing'
    assert highwire_list[2].qualifier == 'creation'
    assert highwire_list[2].name == 'citation_publication_date'
    assert highwire_list[2].content == '1944'
    assert highwire_list[3].qualifier == 'officialtitle'
    assert highwire_list[3].name == 'citation_title'
    assert highwire_list[3].content == 'Tres Actos'
Пример #8
0
 def testTextEscape(self):
     """Test highwire elements are converted to ANVL text when escaped."""
     small_untl_dict = {
         'title': [{
             'content': 'Clifford & Lassie',
             'qualifier': 'officialtitle'
         }],
         'meta': [{
             'content': 'ark:/67531/metapth38622',
             'qualifier': 'ark'
         }, {
             'content': '2008-06-29, 00:31:14',
             'qualifier': 'metadataCreationDate'
         }]
     }
     untlpy = untldict2py(small_untl_dict)
     highwire_elements = untlpy2highwirepy(untlpy, escape=True)
     highwire_text = generate_highwire_text(highwire_elements)
     expected = ('citation_title: Clifford &amp; Lassie\n'
                 'citation_online_date: 06/29/2008')
     self.assertEqual(highwire_text, expected)
Пример #9
0
 def testText(self):
     """Test highwire elements are converted to ANVL text."""
     untlpy = untldict2py(UNTL_DICT)
     highwire_elements = untlpy2highwirepy(untlpy)
     highwire_text = generate_highwire_text(highwire_elements)
     self.assertEqual(highwire_text, HIGHWIRE_TEXT)
Пример #10
0
 def testJson(self):
     """Test highwire elements are converted to a JSON string."""
     untlpy = untldict2py(UNTL_DICT)
     highwire_elements = untlpy2highwirepy(untlpy)
     highwire_json = generate_highwire_json(highwire_elements)
     self.assertEqual(highwire_json, HIGHWIRE_JSON)
Пример #11
0
 def testHighwire2Dict(self):
     """Test dictionary creation from Highwire."""
     untlpy = untldict2py(UNTL_DICT)
     highwi = untlpy2highwirepy(untlpy)
     hidict = highwirepy2dict(highwi)
     self.assertEqual(type(hidict), dict)
Пример #12
0
 def testUNTL2HIGHWIRE(self):
     """Test conversion from UNTL to Highwire."""
     untlpy = untldict2py(UNTL_DICT)
     highwi = untlpy2highwirepy(untlpy)
     for element in highwi:
         self.assertTrue(issubclass(type(element), HighwireElement))
Пример #13
0
 def testUNTL2HIGHWIRE(self):
     """Test conversion from UNTL to Highwire."""
     untlpy = untldict2py(UNTL_DICT)
     highwi = untlpy2highwirepy(untlpy)
     for element in highwi:
         self.assertTrue(issubclass(type(element), HighwireElement))
Пример #14
0
 def testHighwire2Dict(self):
     """Test dictionary creation from Highwire."""
     untlpy = untldict2py(UNTL_DICT)
     highwi = untlpy2highwirepy(untlpy)
     hidict = highwirepy2dict(highwi)
     self.assertEqual(type(hidict), dict)