def test_ex_04(self): """resourcesync_ex_4 is a simple resource dump with one ZIP listed""" rd=ResourceDump() rd.parse('tests/testdata/examples_from_spec/resourcesync_ex_4.xml') self.assertEqual( len(rd.resources), 1, '1 resources') self.assertTrue( 'http://example.com/resourcedump.zip' in rd.resources ) self.assertEqual( rd.resources['http://example.com/resourcedump.zip'].lastmod, '2013-01-03T09:00:00Z' )
def test05_write(self): rd = ResourceDump() rd.add(Resource('aa.zip', timestamp=1)) rd.add(Resource('bb.zip', timestamp=2)) dumpf = os.path.join(self.tmpdir, "test05_dump.xml") rd.write(basename=dumpf) self.assertTrue(os.path.exists(dumpf)) # Now read that back rd2 = ResourceDump() rd2.parse(dumpf) self.assertEqual(len(rd2), 2) self.assertEqual(rd2.uris(), ['aa.zip', 'bb.zip'])
def test10_parse(self): xml='<?xml version=\'1.0\' encoding=\'UTF-8\'?>\n\ <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:rs="http://www.openarchives.org/rs/terms/">\ <rs:md at="2013-01-01" capability="resourcedump"/>\ <url><loc>http://example.com/a.zip</loc><lastmod>2012-03-14T18:37:36Z</lastmod><rs:md length="12345" /></url>\ <url><loc>http://example.com/b.zip</loc><lastmod>2012-03-14T18:37:36Z</lastmod><rs:md length="56789" /></url>\ </urlset>' rd=ResourceDump() rd.parse(fh=io.StringIO(xml)) self.assertEqual( len(rd.resources), 2, 'got 2 resource dumps') self.assertEqual( rd.capability, 'resourcedump', 'capability set' ) self.assertEqual( rd.md_at, '2013-01-01' ) self.assertTrue( 'http://example.com/a.zip' in rd.resources ) self.assertTrue( rd.resources['http://example.com/a.zip'].length, 12345 ) self.assertTrue( 'http://example.com/b.zip' in rd.resources ) self.assertTrue( rd.resources['http://example.com/b.zip'].length, 56789 )
def test02_parse(self): xml = '<?xml version=\'1.0\' encoding=\'UTF-8\'?>\n\ <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:rs="http://www.openarchives.org/rs/terms/">\ <rs:md at="2013-01-01" capability="resourcedump"/>\ <url><loc>http://example.com/a.zip</loc><lastmod>2012-03-14T18:37:36Z</lastmod><rs:md length="12345" /></url>\ <url><loc>http://example.com/b.zip</loc><lastmod>2012-03-14T18:37:36Z</lastmod><rs:md length="56789" /></url>\ </urlset>' rd = ResourceDump() rd.parse(fh=io.StringIO(xml)) self.assertEqual(len(rd.resources), 2, 'got 2 resource dumps') self.assertEqual(rd.capability, 'resourcedump', 'capability set') self.assertEqual(rd.md_at, '2013-01-01') self.assertTrue('http://example.com/a.zip' in rd.resources) self.assertTrue(rd.resources['http://example.com/a.zip'].length, 12345) self.assertTrue('http://example.com/b.zip' in rd.resources) self.assertTrue(rd.resources['http://example.com/b.zip'].length, 56789)