More tests

This commit is contained in:
Simeon Warner 2018-10-23 10:45:58 -04:00
parent 0125b39757
commit 9de1e5b51e
2 changed files with 17 additions and 3 deletions

View File

@ -15,6 +15,9 @@ class TestUtill(unittest.TestCase):
self.assertEqual(h.md5, None)
self.assertEqual(h.sha1, '49844dd211aa33071a252d7cdc250a52cf39af33')
self.assertEqual(h.sha256, '69fe6314a94800456af959d380f5d6932052478ea03d5ccac7ba0a14bd5e67c6')
h = resync.hashes.Hashes(['sha-256'])
h.compute_for_file('tests/testdata/a')
self.assertEqual(h.sha1, None)
def test02_bad_type(self):
self.assertRaises(Exception, resync.hashes.Hashes, ['md5', 'xyz'])

View File

@ -13,7 +13,18 @@ class TestSourceDescription(unittest.TestCase):
rsd.md_at = None
self.assertEqual(rsd.as_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:ln href="http://example.org/about" rel="describedby" /><rs:md capability="description" /></urlset>')
def test02_one_caplist(self):
def test02_add(self):
rsd = SourceDescription()
self.assertEqual(len(rsd), 0)
rsd.add(Resource("http://example.org/u1"))
rsd.add([Resource("http://example.org/u2"),
Resource("http://example.org/u3")])
self.assertEqual(rsd.uris(),
['http://example.org/u1',
'http://example.org/u2',
'http://example.org/u3'])
def test03_one_caplist(self):
rsd = SourceDescription()
rsd.describedby = "http://example.org/about"
self.assertEqual(len(rsd), 0)
@ -22,7 +33,7 @@ class TestSourceDescription(unittest.TestCase):
self.assertEqual(len(rsd), 1)
self.assertEqual(rsd.as_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:ln href="http://example.org/about" rel="describedby" /><rs:md capability="description" /><url><loc>http://example.org/ds1/cl.xml</loc><rs:md capability="capabilitylist" /></url></urlset>')
def test03_a_bunch(self):
def test04_a_bunch(self):
rsd = SourceDescription()
rsd.describedby = "http://example.org/about"
self.assertEqual(len(rsd), 0)
@ -32,7 +43,7 @@ class TestSourceDescription(unittest.TestCase):
self.assertEqual(len(rsd), 3)
self.assertEqual(rsd.as_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:ln href="http://example.org/about" rel="describedby" /><rs:md capability="description" /><url><loc>http://example.org/ds1/cl.xml</loc><rs:md capability="capabilitylist" /></url><url><loc>http://example.org/ds2/cl.xml</loc><rs:md capability="capabilitylist" /></url><url><loc>http://example.org/ds3/cl.xml</loc><rs:md capability="capabilitylist" /></url></urlset>')
def test04_parse(self):
def test05_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:ln href="http://example.org/about" rel="describedby" /><rs:md capability="description" /><url><loc>http://example.org/ds1/cl.xml</loc><rs:md capability="capabilitylist" /></url><url><loc>http://example.org/ds2/cl.xml</loc><rs:md capability="capabilitylist" /></url><url><loc>http://example.org/ds3/cl.xml</loc><rs:md capability="capabilitylist" /></url></urlset>'
sd = SourceDescription()
sd.parse(str_data=xml)