def test_parsing_success(self): epub_filepath = self.pack_epub(os.path.join(TEST_DATA_DIR, 'book')) # Parse an EPUB. from cnxepub import EPUB epub = EPUB.from_filepath(epub_filepath) # EPUBs have packages which the object treats as iterable items. self.assertEqual(len(epub), 1) package = epub[0] # EPUB Packages have contents... both documents and resources. self.assertEqual(len(package), 3) # Verify the package metadata. # The important bits to check for are our custom properties expected_package_metadata = { 'title': "[email protected]", 'creator': "Connexions", 'identifier': "[email protected]", 'language': "en-us", 'publisher': "Connexions", 'rights': "This work is shared with the public using the Attribution 3.0 Unported (CC BY 3.0) license.", 'license_url': "http://creativecommons.org/licenses/by/3.0/", 'base_attribution_url': "http://cnx.org/contents", 'publication_message': "Loosely publishing these here modules.", } self.assertEqual(package.metadata, expected_package_metadata) # Check the navigation order expected_nav_document = package.grab_by_name( "*****@*****.**") self.assertTrue(expected_nav_document.is_navigation) self.assertEqual(package.navigation, expected_nav_document) # Verify reference to a resource item. # This also checks iteration and containment resource = [ i for i in package if i.name == "e3d625fe893b3f1f9aaef3bdf6bfa15c.png" ][0] self.assertIn(resource, package)
def test_parsing_success(self): epub_filepath = self.pack_epub(os.path.join(TEST_DATA_DIR, 'book')) # Parse an EPUB. from cnxepub import EPUB epub = EPUB.from_filepath(epub_filepath) # EPUBs have packages which the object treats as iterable items. self.assertEqual(len(epub), 1) package = epub[0] # EPUB Packages have contents... both documents and resources. self.assertEqual(len(package), 3) # Verify the package metadata. # The important bits to check for are our custom properties expected_package_metadata = { 'title': "[email protected]", 'creator': "Connexions", 'identifier': "[email protected]", 'language': "en-us", 'publisher': "Connexions", 'rights': "This work is shared with the public using the Attribution 3.0 Unported (CC BY 3.0) license.", 'license_url': "http://creativecommons.org/licenses/by/3.0/", 'base_attribution_url': "http://cnx.org/contents", 'publication_message': "Loosely publishing these here modules.", } self.assertEqual(package.metadata, expected_package_metadata) # Check the navigation order expected_nav_document = package.grab_by_name( "*****@*****.**") self.assertTrue(expected_nav_document.is_navigation) self.assertEqual(package.navigation, expected_nav_document) # Verify reference to a resource item. # This also checks iteration and containment resource = [i for i in package if i.name == "e3d625fe893b3f1f9aaef3bdf6bfa15c.png"][0] self.assertIn(resource, package)