def test_as_xml_element_right(self): xml_string = """<metadata xmlns:dc="%s" xmlns:opf="%s"> <dc:rights>Epub Rights</dc:rights> </metadata>""" % (opf.XMLNS_DC, opf.XMLNS_OPF) self.maxDiff = None doc = minidom.parseString(xml_string) xml_element = doc.documentElement xml_element.normalize() result = xml_element.toxml( ).replace('\n', '').replace(' ', '').strip() metadata = opf._parse_xml_metadata(xml_element).as_xml_element().toxml() expected = metadata.replace('\n', '').strip() self.assertEqual(expected, result)
def test_as_xml_element_description(self): xml_string = """<metadata xmlns:dc="%s" xmlns:opf="%s"> <dc:description>This is a very long description. I don't know how you could use it, but...</dc:description> </metadata>""" % (opf.XMLNS_DC, opf.XMLNS_OPF) self.maxDiff = None doc = minidom.parseString(xml_string) xml_element = doc.documentElement xml_element.normalize() result = xml_element.toxml( ).replace('\n', '').replace(' ', '').strip() metadata = opf._parse_xml_metadata(xml_element).as_xml_element().toxml() expected = metadata.replace('\n', '').strip() self.assertEqual(expected, result)
def test_as_xml_element_right(self): xml_string = """<metadata xmlns:dc="%s" xmlns:opf="%s"> <dc:rights>Epub Rights</dc:rights> </metadata>""" % (opf.XMLNS_DC, opf.XMLNS_OPF) self.maxDiff = None doc = minidom.parseString(xml_string) xml_element = doc.documentElement xml_element.normalize() result = xml_element.toxml().replace('\n', '').replace(' ', '').strip() metadata = opf._parse_xml_metadata( xml_element).as_xml_element().toxml() expected = metadata.replace('\n', '').strip() self.assertEqual(expected, result)
def test_as_xml_element_description(self): xml_string = """<metadata xmlns:dc="%s" xmlns:opf="%s"> <dc:description>This is a very long description. I don't know how you could use it, but...</dc:description> </metadata>""" % (opf.XMLNS_DC, opf.XMLNS_OPF) self.maxDiff = None doc = minidom.parseString(xml_string) xml_element = doc.documentElement xml_element.normalize() result = xml_element.toxml().replace('\n', '').replace(' ', '').strip() metadata = opf._parse_xml_metadata( xml_element).as_xml_element().toxml() expected = metadata.replace('\n', '').strip() self.assertEqual(expected, result)
def test_as_xml_element(self): xml_string = """<metadata xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opf="http://www.idpf.org/2007/opf"> <dc:title xml:lang="fr">Le titre.</dc:title> <dc:title xml:lang="en">The title.</dc:title> </metadata>""" self.maxDiff = None doc = minidom.parseString(xml_string) xml_element = doc.documentElement xml_element.normalize() result = xml_element.toxml( ).replace('\n', '').replace(' ', '').strip() metadata = opf._parse_xml_metadata(xml_element).as_xml_element().toxml() expected = metadata.replace('\n', '').strip() self.assertEqual(expected, result)
def test_as_xml_element(self): xml_string = """<metadata xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opf="http://www.idpf.org/2007/opf"> <dc:title xml:lang="fr">Le titre.</dc:title> <dc:title xml:lang="en">The title.</dc:title> </metadata>""" self.maxDiff = None doc = minidom.parseString(xml_string) xml_element = doc.documentElement xml_element.normalize() result = xml_element.toxml().replace('\n', '').replace(' ', '').strip() metadata = opf._parse_xml_metadata( xml_element).as_xml_element().toxml() expected = metadata.replace('\n', '').strip() self.assertEqual(expected, result)
def test_as_xml_element_contributors(self): xml_string = """<metadata xmlns:dc="%s" xmlns:opf="%s"> <dc:contributor>First Contributor of the Book</dc:contributor> <dc:contributor opf:file-as="aut">Second Contributor with File-as attribute</dc:contributor> <dc:contributor opf:role="translator">Third Contributor with role</dc:contributor> <dc:contributor opf:role="translator" opf:file-as="aut">Last Contributor with All</dc:contributor> </metadata>""" % (opf.XMLNS_DC, opf.XMLNS_OPF) self.maxDiff = None doc = minidom.parseString(xml_string) xml_element = doc.documentElement xml_element.normalize() result = xml_element.toxml( ).replace('\n', '').replace(' ', '').strip() metadata = opf._parse_xml_metadata(xml_element).as_xml_element().toxml() expected = metadata.replace('\n', '').strip() self.assertEqual(expected, result)
def test_as_xml_element_contributors(self): xml_string = """<metadata xmlns:dc="%s" xmlns:opf="%s"> <dc:contributor>First Contributor of the Book</dc:contributor> <dc:contributor opf:file-as="aut">Second Contributor with File-as attribute</dc:contributor> <dc:contributor opf:role="translator">Third Contributor with role</dc:contributor> <dc:contributor opf:role="translator" opf:file-as="aut">Last Contributor with All</dc:contributor> </metadata>""" % (opf.XMLNS_DC, opf.XMLNS_OPF) self.maxDiff = None doc = minidom.parseString(xml_string) xml_element = doc.documentElement xml_element.normalize() result = xml_element.toxml().replace('\n', '').replace(' ', '').strip() metadata = opf._parse_xml_metadata( xml_element).as_xml_element().toxml() expected = metadata.replace('\n', '').strip() self.assertEqual(expected, result)
def test_parse_xml_metadata(self): """Test _parse_xml_metadata.""" xml_string = """ <metadata xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opf="http://www.idpf.org/2007/opf"> <dc:identifier opf:scheme="epub_test" id="epub_id"> 1 </dc:identifier> <dc:identifier opf:scheme="uuid" id="uuid_id"> 18430f16-c687-400b-9b9c-54a9c8b0646c </dc:identifier> <dc:title> Metadata for testing purpose </dc:title> <dc:title xml:lang="fr"> Metadonnée pour les tests. </dc:title> <dc:creator opf:file-as="Doe, Jhon" opf:role="aut"> John Doe </dc:creator> <dc:subject> This is an arbitrary subjet. </dc:subject> <dc:subject> Another usefull subject. </dc:subject> <dc:contributor opf:file-as="Python, unittest" opf:role="other.test"> Python unittest </dc:contributor> <dc:contributor opf:file-as="Python, nosetests" opf:role="other.test"> Python nosetests </dc:contributor> <dc:description> A long description. There is not any information about how a description must be. Long, short, etc. We just don't know anything about this. </dc:description> <dc:date opf:event="creation"> 2012-01-05T16:18:00+00:00 </dc:date> <dc:date opf:event="publication"> 2012-01-09T13:37:00+00:00 </dc:date> <dc:type> Is this a type? </dc:type> <dc:format> Well formated, sir! </dc:format> <dc:publisher> Exirel </dc:publisher> <dc:language> en </dc:language> <dc:source> From the far old west (Brittany, France). </dc:source> <dc:relation> It's complicated... </dc:relation> <dc:coverage> An art of cover. </dc:coverage> <dc:rights> To the left! </dc:rights> <meta content="Custom Meta" name="custom:meta"/> <meta content="Another Custom Meta" name="custom:other"/> </metadata> """ element = minidom.parseString(xml_string).documentElement metadata = opf._parse_xml_metadata(element) # dc:identifier self.assertEqual( metadata.identifiers, [('1', 'epub_id', 'epub_test'), ('18430f16-c687-400b-9b9c-54a9c8b0646c', 'uuid_id', 'uuid')]) # dc:title self.assertEqual(metadata.titles, [(u'Metadata for testing purpose', u''), (u'Metadonn\xe9e pour les tests.', u'fr')]) # dc:creator self.assertEqual(metadata.creators, [ ('John Doe', 'aut', 'Doe, Jhon'), ]) # dc:subject self.assertEqual( metadata.subjects, ['This is an arbitrary subjet.', 'Another usefull subject.']) # dc:description self.assertEqual( metadata.description, """A long description. There is not any information about how a description must be. Long, short, etc. We just don't know anything about this.""") # dc:contributor self.assertEqual( metadata.contributors, [('Python unittest', 'other.test', 'Python, unittest'), ('Python nosetests', 'other.test', 'Python, nosetests')]) # dc:date self.assertEqual(metadata.dates, [('2012-01-05T16:18:00+00:00', 'creation'), ('2012-01-09T13:37:00+00:00', 'publication')]) # dc:type self.assertEqual(metadata.dc_type, 'Is this a type?') # dc:format self.assertEqual(metadata.format, 'Well formated, sir!') # dc:publisher self.assertEqual(metadata.publisher, 'Exirel') # dc:language self.assertEqual(metadata.languages, ['en']) # dc:source self.assertEqual(metadata.source, 'From the far old west (Brittany, France).') # dc:relation self.assertEqual(metadata.relation, 'It\'s complicated...') # dc:coverage self.assertEqual(metadata.coverage, 'An art of cover.') # dc:rights self.assertEqual(metadata.right, 'To the left!') # meta self.assertEqual(metadata.metas, [('custom:meta', 'Custom Meta'), ('custom:other', 'Another Custom Meta')])
def test_parse_xml_metadata(self): """Test _parse_xml_metadata.""" xml_string = """ <metadata xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opf="http://www.idpf.org/2007/opf"> <dc:identifier opf:scheme="epub_test" id="epub_id"> 1 </dc:identifier> <dc:identifier opf:scheme="uuid" id="uuid_id"> 18430f16-c687-400b-9b9c-54a9c8b0646c </dc:identifier> <dc:title> Metadata for testing purpose </dc:title> <dc:title xml:lang="fr"> Metadonnée pour les tests. </dc:title> <dc:creator opf:file-as="Doe, Jhon" opf:role="aut"> John Doe </dc:creator> <dc:subject> This is an arbitrary subjet. </dc:subject> <dc:subject> Another usefull subject. </dc:subject> <dc:contributor opf:file-as="Python, unittest" opf:role="other.test"> Python unittest </dc:contributor> <dc:contributor opf:file-as="Python, nosetests" opf:role="other.test"> Python nosetests </dc:contributor> <dc:description> A long description. There is not any information about how a description must be. Long, short, etc. We just don't know anything about this. </dc:description> <dc:date opf:event="creation"> 2012-01-05T16:18:00+00:00 </dc:date> <dc:date opf:event="publication"> 2012-01-09T13:37:00+00:00 </dc:date> <dc:type> Is this a type? </dc:type> <dc:format> Well formated, sir! </dc:format> <dc:publisher> Exirel </dc:publisher> <dc:language> en </dc:language> <dc:source> From the far old west (Brittany, France). </dc:source> <dc:relation> It's complicated... </dc:relation> <dc:coverage> An art of cover. </dc:coverage> <dc:rights> To the left! </dc:rights> <meta content="Custom Meta" name="custom:meta"/> <meta content="Another Custom Meta" name="custom:other"/> </metadata> """ element = minidom.parseString(xml_string).documentElement metadata = opf._parse_xml_metadata(element) # dc:identifier self.assertEqual(metadata.identifiers, [('1', 'epub_id', 'epub_test'), ('18430f16-c687-400b-9b9c-54a9c8b0646c', 'uuid_id', 'uuid')]) # dc:title self.assertEqual(metadata.titles, [(u'Metadata for testing purpose', u''), (u'Metadonn\xe9e pour les tests.', u'fr')]) # dc:creator self.assertEqual(metadata.creators, [('John Doe', 'aut', 'Doe, Jhon'), ]) # dc:subject self.assertEqual(metadata.subjects, ['This is an arbitrary subjet.', 'Another usefull subject.']) # dc:description self.assertEqual(metadata.description, """A long description. There is not any information about how a description must be. Long, short, etc. We just don't know anything about this.""") # dc:contributor self.assertEqual(metadata.contributors, [('Python unittest', 'other.test', 'Python, unittest'), ('Python nosetests', 'other.test', 'Python, nosetests')]) # dc:date self.assertEqual(metadata.dates, [('2012-01-05T16:18:00+00:00', 'creation'), ('2012-01-09T13:37:00+00:00', 'publication')]) # dc:type self.assertEqual(metadata.dc_type, 'Is this a type?') # dc:format self.assertEqual(metadata.format, 'Well formated, sir!') # dc:publisher self.assertEqual(metadata.publisher, 'Exirel') # dc:language self.assertEqual(metadata.languages, ['en']) # dc:source self.assertEqual(metadata.source, 'From the far old west (Brittany, France).') # dc:relation self.assertEqual(metadata.relation, 'It\'s complicated...') # dc:coverage self.assertEqual(metadata.coverage, 'An art of cover.') # dc:rights self.assertEqual(metadata.right, 'To the left!') # meta self.assertEqual(metadata.metas, [('custom:meta', 'Custom Meta'), ('custom:other', 'Another Custom Meta')])