Exemplo n.º 1
0
 def test_02_resource_created(self):
     # ResourceChange with created
     r1 = ResourceChange('http://example.org/r/1',
                         1234,
                         9999,
                         'Q2hlY2sgSW50ZWdyaXR5IQ==',
                         changetype='CREATED')
     xml = Sitemap().resource_as_xml(r1)
     self.assertEqual(
         xml,
         "<?xml version='1.0' encoding='UTF-8'?>\n<url><loc>http://example.org/r/1</loc><lastmod rs:type=\"created\">1970-01-01T00:20:34Z</lastmod><rs:size>9999</rs:size><rs:fixity type=\"md5\">Q2hlY2sgSW50ZWdyaXR5IQ==</rs:fixity></url>"
     )
     # Now make inventory
     i = Inventory()
     i.add(r1)
     inv_xml = Sitemap().resources_as_xml(i)
     self.assertEqual(
         inv_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/\"><url><loc>http://example.org/r/1</loc><lastmod rs:type=\"created\">1970-01-01T00:20:34Z</lastmod><rs:size>9999</rs:size><rs:fixity type=\"md5\">Q2hlY2sgSW50ZWdyaXR5IQ==</rs:fixity></url></urlset>"
     )
     # and try parsing back
     s = Sitemap()
     s.resource_class = ResourceChange
     i = s.inventory_parse_xml(fh=StringIO.StringIO(inv_xml))
     self.assertEqual(len(i), 1)
     r = iter(i).next()
     self.assertEqual(r.uri, 'http://example.org/r/1')
     self.assertEqual(r.timestamp, 1234)
     self.assertEqual(r.changetype, 'CREATED')
Exemplo n.º 2
0
    def test_11_parse_2(self):
        xml = "<?xml version='1.0' encoding='UTF-8'?>\n\
<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\" xmlns:rs=\"http://resourcesync.org/change/0.1\">\
<url><loc>/tmp/rs_test/src/file_a</loc><lastmod>2012-03-14T18:37:36</lastmod><rs:size>12</rs:size></url>\
<url><loc>/tmp/rs_test/src/file_b</loc><lastmod>2012-03-14T18:37:36</lastmod><rs:size>32</rs:size></url>\
</urlset>"
        s = Sitemap()
        i = s.inventory_parse_xml(fh=StringIO.StringIO(xml))
        self.assertEqual(s.resources_created, 2, "got 2 resources")
Exemplo n.º 3
0
    def test_11_parse_2(self):
        xml='<?xml version=\'1.0\' encoding=\'UTF-8\'?>\n\
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:rs="http://resourcesync.org/change/0.1">\
<url><loc>/tmp/rs_test/src/file_a</loc><lastmod>2012-03-14T18:37:36</lastmod><rs:size>12</rs:size></url>\
<url><loc>/tmp/rs_test/src/file_b</loc><lastmod>2012-03-14T18:37:36</lastmod><rs:size>32</rs:size></url>\
</urlset>'
        s=Sitemap()
        i=s.inventory_parse_xml(fh=StringIO.StringIO(xml))
        self.assertEqual( s.resources_created, 2, 'got 2 resources')
Exemplo n.º 4
0
    def test_11_parse_2(self):
        xml='<?xml version=\'1.0\' encoding=\'UTF-8\'?>\n\
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:rs="http://resourcesync.org/change/0.1">\
<url><loc>/tmp/rs_test/src/file_a</loc><lastmod>2012-03-14T18:37:36</lastmod><rs:size>12</rs:size></url>\
<url><loc>/tmp/rs_test/src/file_b</loc><lastmod>2012-03-14T18:37:36</lastmod><rs:size>32</rs:size></url>\
</urlset>'
        fh=StringIO.StringIO(xml)
        s=Sitemap()
        i=s.inventory_parse_xml(fh)
        self.assertEqual( s.resources_added, 2, 'got 2 resources')
Exemplo n.º 5
0
    def test_10_sitemap(self):
        xml = "<?xml version='1.0' encoding='UTF-8'?>\n\
<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\" xmlns:rs=\"http://resourcesync.org/change/0.1\">\
<url><loc>http://e.com/a</loc><lastmod>2012-03-14T18:37:36</lastmod><rs:size>12</rs:size><rs:md5>aabbccdd</rs:md5></url>\
</urlset>"
        s = Sitemap()
        i = s.inventory_parse_xml(fh=StringIO.StringIO(xml))
        self.assertEqual(s.resources_created, 1, "got 1 resources")
        r = i.resources["http://e.com/a"]
        self.assertTrue(r is not None, "got the uri expected")
        self.assertEqual(r.uri, "http://e.com/a")
        self.assertEqual(r.lastmod, "2012-03-14T18:37:36")
        self.assertEqual(r.size, 12)
        self.assertEqual(r.md5, "aabbccdd")
Exemplo n.º 6
0
    def test_30_parse_changeset(self):
        xml = "<?xml version='1.0' encoding='UTF-8'?>\n\
<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\" xmlns:rs=\"http://resourcesync.org/change/0.1\">\
<url><loc>/tmp/rs_test/src/file_a</loc><lastmod>2012-03-14T18:37:36</lastmod><rs:size>12</rs:size><rs:changetype>UP</rs:changetype></url>\
<url><loc>/tmp/rs_test/src/file_b</loc><lastmod>2012-03-14T18:37:36</lastmod><rs:size>32</rs:size><rs:changeid>123</rs:changeid></url>\
</urlset>"
        s = Sitemap()
        s.resource_class = ResourceChange
        i = s.inventory_parse_xml(fh=StringIO.StringIO(xml))
        self.assertEqual(s.resources_created, 2, "got 2 resources")
        self.assertEqual(i.resources["/tmp/rs_test/src/file_a"].changetype, "UP")
        self.assertEqual(i.resources["/tmp/rs_test/src/file_a"].changeid, None)
        self.assertEqual(i.resources["/tmp/rs_test/src/file_b"].changetype, None)
        self.assertEqual(i.resources["/tmp/rs_test/src/file_b"].changeid, "123")
Exemplo n.º 7
0
    def test_10_sitemap(self):
        xml='<?xml version=\'1.0\' encoding=\'UTF-8\'?>\n\
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:rs="http://resourcesync.org/change/0.1">\
<url><loc>http://e.com/a</loc><lastmod>2012-03-14T18:37:36</lastmod><rs:size>12</rs:size><rs:md5>aabbccdd</rs:md5></url>\
</urlset>'
        s=Sitemap()
        i=s.inventory_parse_xml(fh=StringIO.StringIO(xml))
        self.assertEqual( s.resources_created, 1, 'got 1 resources')
        r=i.resources['http://e.com/a']
        self.assertTrue( r is not None, 'got the uri expected')
        self.assertEqual( r.uri, 'http://e.com/a' )
        self.assertEqual( r.lastmod, '2012-03-14T18:37:36' )
        self.assertEqual( r.size, 12 )
        self.assertEqual( r.md5, 'aabbccdd' )
Exemplo n.º 8
0
    def test_30_parse_changeset(self):
        xml='<?xml version=\'1.0\' encoding=\'UTF-8\'?>\n\
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:rs="http://resourcesync.org/change/0.1">\
<url><loc>/tmp/rs_test/src/file_a</loc><lastmod>2012-03-14T18:37:36</lastmod><rs:size>12</rs:size><rs:changetype>UP</rs:changetype></url>\
<url><loc>/tmp/rs_test/src/file_b</loc><lastmod>2012-03-14T18:37:36</lastmod><rs:size>32</rs:size><rs:changeid>123</rs:changeid></url>\
</urlset>'
        s=Sitemap()
        s.resource_class=ResourceChange
        i=s.inventory_parse_xml(fh=StringIO.StringIO(xml))
        self.assertEqual( s.resources_created, 2, 'got 2 resources')
        self.assertEqual( i.resources['/tmp/rs_test/src/file_a'].changetype, 'UP' )
        self.assertEqual( i.resources['/tmp/rs_test/src/file_a'].changeid, None )
        self.assertEqual( i.resources['/tmp/rs_test/src/file_b'].changetype, None )
        self.assertEqual( i.resources['/tmp/rs_test/src/file_b'].changeid, '123' )
Exemplo n.º 9
0
    def test_10_sitemap(self):
        xml='<?xml version=\'1.0\' encoding=\'UTF-8\'?>\n\
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:rs="http://resourcesync.org/change/0.1">\
<url><loc>http://e.com/a</loc><lastmod>2012-03-14T18:37:36</lastmod><rs:size>12</rs:size><rs:md5>aabbccdd</rs:md5></url>\
</urlset>'
        fh=StringIO.StringIO(xml)
        s=Sitemap()
        i=s.inventory_parse_xml(fh)
        self.assertEqual( s.resources_added, 1, 'got 1 resources')
        r=i.resources['http://e.com/a']
        self.assertTrue( r is not None, 'got the uri expected')
        self.assertEqual( r.uri, 'http://e.com/a' )
        self.assertEqual( r.lastmod, '2012-03-14T18:37:36' )
        self.assertEqual( r.size, 12 )
        self.assertEqual( r.md5, 'aabbccdd' )
Exemplo n.º 10
0
 def test_02_resource_deleted(self):
     # ResourceChange with deleted
     r1 = ResourceChange('http://example.org/r/1',1234,9999,'Q2hlY2sgSW50ZWdyaXR5IQ==',changetype='DELETED')
     self.assertEqual( Sitemap().resource_as_xml(r1), "<?xml version='1.0' encoding='UTF-8'?>\n<url><loc>http://example.org/r/1</loc><expires>1970-01-01T00:20:34Z</expires><rs:size>9999</rs:size><rs:fixity type=\"md5\">Q2hlY2sgSW50ZWdyaXR5IQ==</rs:fixity></url>" )
     # Now make inventory
     i = Inventory()
     i.add(r1)
     inv_xml = Sitemap().resources_as_xml(i)
     # and try parsing back
     s = Sitemap()
     s.resource_class = ResourceChange
     i = s.inventory_parse_xml(fh=StringIO.StringIO(inv_xml))
     self.assertEqual( len(i), 1 )
     r = iter(i).next()
     self.assertEqual( r.uri, 'http://example.org/r/1')
     self.assertEqual( r.timestamp, 1234)
     self.assertEqual( r.changetype, 'DELETED')
Exemplo n.º 11
0
 def test_02_resource_created(self):
     # ResourceChange with created
     r1 = ResourceChange('http://example.org/r/1',1234,9999,'Q2hlY2sgSW50ZWdyaXR5IQ==',changetype='CREATED')
     xml = Sitemap().resource_as_xml(r1)
     self.assertEqual( xml, "<?xml version='1.0' encoding='UTF-8'?>\n<url><loc>http://example.org/r/1</loc><lastmod rs:type=\"created\">1970-01-01T00:20:34Z</lastmod><rs:size>9999</rs:size><rs:fixity type=\"md5\">Q2hlY2sgSW50ZWdyaXR5IQ==</rs:fixity></url>" )
     # Now make inventory
     i = Inventory()
     i.add(r1)
     inv_xml = Sitemap().resources_as_xml(i)
     self.assertEqual( inv_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/\"><url><loc>http://example.org/r/1</loc><lastmod rs:type=\"created\">1970-01-01T00:20:34Z</lastmod><rs:size>9999</rs:size><rs:fixity type=\"md5\">Q2hlY2sgSW50ZWdyaXR5IQ==</rs:fixity></url></urlset>" )
     # and try parsing back
     s = Sitemap()
     s.resource_class = ResourceChange
     i = s.inventory_parse_xml(fh=StringIO.StringIO(inv_xml))
     self.assertEqual( len(i), 1 )
     r = iter(i).next()
     self.assertEqual( r.uri, 'http://example.org/r/1')
     self.assertEqual( r.timestamp, 1234)
     self.assertEqual( r.changetype, 'CREATED')
Exemplo n.º 12
0
 def test_02_resource_deleted(self):
     # ResourceChange with deleted
     r1 = ResourceChange('http://example.org/r/1',
                         1234,
                         9999,
                         'Q2hlY2sgSW50ZWdyaXR5IQ==',
                         changetype='DELETED')
     self.assertEqual(
         Sitemap().resource_as_xml(r1),
         "<?xml version='1.0' encoding='UTF-8'?>\n<url><loc>http://example.org/r/1</loc><expires>1970-01-01T00:20:34Z</expires><rs:size>9999</rs:size><rs:fixity type=\"md5\">Q2hlY2sgSW50ZWdyaXR5IQ==</rs:fixity></url>"
     )
     # Now make inventory
     i = Inventory()
     i.add(r1)
     inv_xml = Sitemap().resources_as_xml(i)
     # and try parsing back
     s = Sitemap()
     s.resource_class = ResourceChange
     i = s.inventory_parse_xml(fh=StringIO.StringIO(inv_xml))
     self.assertEqual(len(i), 1)
     r = iter(i).next()
     self.assertEqual(r.uri, 'http://example.org/r/1')
     self.assertEqual(r.timestamp, 1234)
     self.assertEqual(r.changetype, 'DELETED')