def __create_resourcelist__(src, checksum=True): """ Create a resourcelist xml for the source denominated by src. :param src: 's1', 's2' etc. :param checksum: should checksums be added to the xml. :return: None """ abs_path = os.path.dirname(os.path.abspath(__name__)) data = [] path = os.path.join(abs_path, "rs/source", src, "files") for root, directories, filenames in os.walk(path): for filename in filenames: data.append(os.path.join(root, filename)) paths = ",".join(data) outfile = os.path.join(abs_path, "rs/source", src, "resourcelist.xml") # create a resourcelist from the files in test/rs/source/{src}/files client = Client(checksum=checksum) prefix = "http://localhost:8000/rs/source/" + src + "/files" resourcedir = os.path.join(abs_path, "rs/source", src, "files") args = [prefix, resourcedir] client.set_mappings(args) client.write_resource_list(paths, outfile)
def __create_resourcelist__(src, checksum=True): """ Create a resourcelist xml for the source denominated by src. :param src: 's1', 's2' etc. :param checksum: should checksums be added to the xml. :return: None """ abs_path = os.path.dirname(os.path.abspath(__name__)) data = [] path = os.path.join(abs_path, "rs/source", src, "files") for root, directories, filenames in os.walk(path): for filename in filenames: data.append(os.path.join(root, filename)) paths = ",".join(data) outfile = os.path.join(abs_path, "rs/source", src, "resourcelist.xml") # create a resourcelist from the files in test/rs/source/{src}/files client = Client(checksum=checksum) prefix = "http://localhost:8000/rs/source/" + src + "/files" resourcedir = os.path.join(abs_path, "rs/source", src, "files") args = [prefix, resourcedir] client.set_mappings(args) client.write_resource_list(paths, outfile)
def test41_write_resource_list_path(self): c = Client() c.set_mappings( ['http://example.org/','resync/test/testdata/'] ) # with an explicit paths setting only the specified paths will be included with capture_stdout() as capturer: c.write_resource_list(paths='resync/test/testdata/dir1') sys.stderr.write(capturer.result) self.assertTrue( re.search(r'<rs:md at="\S+" capability="resourcelist"', capturer.result ) ) self.assertTrue( re.search(r'<url><loc>http://example.org/dir1/file_a</loc>', capturer.result ) ) self.assertTrue( re.search(r'<url><loc>http://example.org/dir1/file_b</loc>', capturer.result ) ) self.assertFalse( re.search(r'<url><loc>http://example.org/dir2/file_x</loc>', capturer.result ) )
def test40_write_resource_list_mappings(self): c = Client() c.set_mappings( ['http://example.org/','resync/test/testdata/'] ) # with no explicit paths seting the mapping will be used with capture_stdout() as capturer: c.write_resource_list() #sys.stderr.write(capturer.result) self.assertTrue( re.search(r'<rs:md at="\S+" capability="resourcelist"', capturer.result ) ) self.assertTrue( re.search(r'<url><loc>http://example.org/dir1/file_a</loc>', capturer.result ) ) self.assertTrue( re.search(r'<url><loc>http://example.org/dir1/file_b</loc>', capturer.result ) ) self.assertTrue( re.search(r'<url><loc>http://example.org/dir2/file_x</loc>', capturer.result ) )
def test41_write_resource_list_path(self): c = Client() c.set_mappings( ['http://example.org/','tests/testdata/'] ) links=[{'rel':'uri_c','href':'uri_d'}] # with an explicit paths setting only the specified paths will be included with capture_stdout() as capturer: c.write_resource_list(paths='tests/testdata/dir1', links=links) self.assertTrue( re.search(r'<rs:md at="\S+" capability="resourcelist"', capturer.result ) ) self.assertTrue( re.search(r'<url><loc>http://example.org/dir1/file_a</loc>', capturer.result ) ) self.assertTrue( re.search(r'<url><loc>http://example.org/dir1/file_b</loc>', capturer.result ) ) self.assertFalse( re.search(r'<url><loc>http://example.org/dir2/file_x</loc>', capturer.result ) ) # check link present self.assertTrue( re.search(r'rel="uri_c"', capturer.result ) ) self.assertTrue( re.search(r'href="uri_d"', capturer.result ) ) # Travis CI does not preserve timestamps from github so test here for the file # size but not the datestamp #self.assertTrue( re.search(r'<url><loc>http://example.org/dir1/file_a</loc><lastmod>[\w\-:]+</lastmod><rs:md length="20" /></url>', capturer.result ) ) #self.assertTrue( re.search(r'<url><loc>http://example.org/dir1/file_b</loc><lastmod>[\w\-:]+</lastmod><rs:md length="45" /></url>', capturer.result ) ) # to file outfile = os.path.join(self.tmpdir,'rl_out.xml') c.write_resource_list(paths='tests/testdata/dir1', outfile=outfile) self.assertTrue( os.path.getsize(outfile)>100 ) # dump instead (default file) c.default_resource_dump = os.path.join(self.tmpdir,'rl_out_dump_def') outfile = c.default_resource_dump+'00000.zip' self.assertFalse( os.path.exists(outfile) ) c.write_resource_list(paths='tests/testdata/dir1', dump=True) self.assertTrue( os.path.getsize(outfile)>100 ) # (specific file) outbase = os.path.join(self.tmpdir,'rl_out_dump') outfile = outbase+'00000.zip' self.assertFalse( os.path.exists(outfile) ) c.write_resource_list(paths='tests/testdata/dir1', dump=True, outfile=outbase) self.assertTrue( os.path.getsize(outfile)>100 )
def test41_write_resource_list_path(self): c = Client() c.set_mappings(['http://example.org/', 'resync/test/testdata/']) # with an explicit paths setting only the specified paths will be included with capture_stdout() as capturer: c.write_resource_list(paths='resync/test/testdata/dir1') sys.stderr.write(capturer.result) self.assertTrue( re.search(r'<rs:md at="\S+" capability="resourcelist"', capturer.result)) self.assertTrue( re.search(r'<url><loc>http://example.org/dir1/file_a</loc>', capturer.result)) self.assertTrue( re.search(r'<url><loc>http://example.org/dir1/file_b</loc>', capturer.result)) self.assertFalse( re.search(r'<url><loc>http://example.org/dir2/file_x</loc>', capturer.result))
def test40_write_resource_list_mappings(self): c = Client() c.set_mappings(['http://example.org/', 'resync/test/testdata/']) # with no explicit paths seting the mapping will be used with capture_stdout() as capturer: c.write_resource_list() #sys.stderr.write(capturer.result) self.assertTrue( re.search(r'<rs:md at="\S+" capability="resourcelist"', capturer.result)) self.assertTrue( re.search(r'<url><loc>http://example.org/dir1/file_a</loc>', capturer.result)) self.assertTrue( re.search(r'<url><loc>http://example.org/dir1/file_b</loc>', capturer.result)) self.assertTrue( re.search(r'<url><loc>http://example.org/dir2/file_x</loc>', capturer.result))
def test41_write_resource_list_path(self): c = Client() c.set_mappings(['http://example.org/', 'tests/testdata/']) links = [{'rel': 'uri_c', 'href': 'uri_d'}] # with an explicit paths setting only the specified paths will be # included with capture_stdout() as capturer: c.write_resource_list(paths='tests/testdata/dir1', links=links) self.assertTrue( re.search(r'<rs:md at="\S+" capability="resourcelist"', capturer.result)) self.assertTrue( re.search(r'<url><loc>http://example.org/dir1/file_a</loc>', capturer.result)) self.assertTrue( re.search(r'<url><loc>http://example.org/dir1/file_b</loc>', capturer.result)) self.assertFalse( re.search(r'<url><loc>http://example.org/dir2/file_x</loc>', capturer.result)) # check link present self.assertTrue(re.search(r'rel="uri_c"', capturer.result)) self.assertTrue(re.search(r'href="uri_d"', capturer.result)) # Travis CI does not preserve timestamps from github so test here for the file # size but not the datestamp # self.assertTrue( re.search(r'<url><loc>http://example.org/dir1/file_a</loc><lastmod>[\w\-:]+</lastmod><rs:md length="20" /></url>', capturer.result ) ) # self.assertTrue( re.search(r'<url><loc>http://example.org/dir1/file_b</loc><lastmod>[\w\-:]+</lastmod><rs:md length="45" /></url>', capturer.result ) ) # to file outfile = os.path.join(self.tmpdir, 'rl_out.xml') c.write_resource_list(paths='tests/testdata/dir1', outfile=outfile) self.assertTrue(os.path.getsize(outfile) > 100) # dump instead (default file) c.default_resource_dump = os.path.join(self.tmpdir, 'rl_out_dump_def') outfile = c.default_resource_dump + '00000.zip' self.assertFalse(os.path.exists(outfile)) c.write_resource_list(paths='tests/testdata/dir1', dump=True) self.assertTrue(os.path.getsize(outfile) > 100) # (specific file) outbase = os.path.join(self.tmpdir, 'rl_out_dump') outfile = outbase + '00000.zip' self.assertFalse(os.path.exists(outfile)) c.write_resource_list(paths='tests/testdata/dir1', dump=True, outfile=outbase) self.assertTrue(os.path.getsize(outfile) > 100)