def test_build_ex_18(self):
     """Resource Dump Manifest with 2 entries and some metadata"""
     rdm = ResourceDumpManifest()
     rdm.up = 'http://example.com/dataset1/capabilitylist.xml'
     rdm.md_at = "2013-01-03T09:00:00Z"
     rdm.md_completed = "2013-01-03T09:02:00Z"
     rdm.add(
         Resource(uri='http://example.com/res1',
                  lastmod='2013-01-02T13:00:00Z',
                  md5='1584abdf8ebdc9802ac0c6a7402c03b6',
                  length=8876,
                  mime_type='text/html',
                  path='/resources/res1'))
     rdm.add(
         Resource(
             uri='http://example.com/res2',
             lastmod='2013-01-02T14:00:00Z',
             md5='1e0d5cb8ef6ba40c99b14c0237be735e',
             sha256=
             '854f61290e2e197a11bc91063afce22e43f8ccc655237050ace766adc68dc784',
             length=14599,
             mime_type='application/pdf',
             path='/resources/res2'))
     ex_xml = self._open_ex('resourcesync_ex_18').read()
     self._assert_xml_equal(rdm.as_xml(), ex_xml)
Beispiel #2
0
    def get_resource_dump_manifest(self, record_id):
        """
        Get resource dump manifest.

        :param record_id: Identifier of record.
        :return: (xml) content of resourcedumpmanifest
        """
        _validation = self._validation(record_id)
        if self.resource_dump_manifest and _validation:
            rdm = ResourceDumpManifest()
            rdm.up = '{}resync/{}/resourcedump.xml'.format(
                request.url_root, self.repository_id)
            record = WekoRecord.get_record_by_pid(record_id)
            if record:
                for file in record.files:
                    current_app.logger.debug(file.info())
                    file_info = file.info()
                    path = 'recid_{}/{}'.format(record.get('recid'),
                                                file_info.get('key'))
                    lastmod = str(datetime.datetime.utcnow().replace(
                        tzinfo=datetime.timezone.utc).isoformat())
                    rdm.add(
                        Resource(
                            '{}record/{}/files/{}'.format(
                                request.url_root, record.get('recid'),
                                file_info.get('key')),
                            lastmod=lastmod,
                            sha256=file_info.get('checksum').split(':')[1],
                            length=str(file_info.get('size')),
                            path=path))
            return rdm.as_xml()
        return None
Beispiel #3
0
 def test01_as_xml(self):
     rdm = ResourceDumpManifest()
     rdm.add( Resource('a.zip',timestamp=1) )
     rdm.add( Resource('b.zip',timestamp=2) )
     xml = rdm.as_xml()
     self.assertTrue( re.search(r'<rs:md .*capability="resourcedump-manifest"', xml), 'XML has capability' )
     self.assertTrue( re.search(r'<url><loc>a.zip</loc><lastmod>1970-01-01T00:00:01Z</lastmod></url>', xml), 'XML has resource a' ) 
 def test01_as_xml(self):
     rdm = ResourceDumpManifest()
     rdm.add(Resource('a.zip', timestamp=1))
     rdm.add(Resource('b.zip', timestamp=2))
     xml = rdm.as_xml()
     self.assertTrue(
         re.search(r'<rs:md .*capability="resourcedump-manifest"', xml),
         'XML has capability')
     self.assertTrue(
         re.search(
             r'<url><loc>a.zip</loc><lastmod>1970-01-01T00:00:01Z</lastmod></url>',
             xml), 'XML has resource a')
Beispiel #5
0
 def test00_dump_zip_resource_list(self):
     rl = ResourceDumpManifest()
     rl.add(Resource('http://ex.org/a', length=7, path='tests/testdata/a'))
     rl.add(Resource('http://ex.org/b', length=21, path='tests/testdata/b'))
     d = Dump()
     zipf = os.path.join(self.tmpdir, "test00_dump.zip")
     d.write_zip(resources=rl, dumpfile=zipf)  # named args
     self.assertTrue(os.path.exists(zipf))
     self.assertTrue(zipfile.is_zipfile(zipf))
     zo = zipfile.ZipFile(zipf, 'r')
     self.assertEqual(len(zo.namelist()), 3)
     zo.close()
     os.unlink(zipf)
Beispiel #6
0
 def test00_dump_zip_resource_list(self):
     rl=ResourceDumpManifest()
     rl.add( Resource('http://ex.org/a', length=7, path='resync/test/testdata/a') )
     rl.add( Resource('http://ex.org/b', length=21, path='resync/test/testdata/b') )
     d=Dump()
     zipf=os.path.join(self.tmpdir,"test00_dump.zip")
     d.write_zip(resources=rl,dumpfile=zipf) # named args
     self.assertTrue( os.path.exists(zipf) )
     self.assertTrue( zipfile.is_zipfile(zipf) )
     zo=zipfile.ZipFile(zipf,'r')
     self.assertEqual( len(zo.namelist()), 3 )
     zo.close()
     os.unlink(zipf)
Beispiel #7
0
 def test_build_ex_05(self):
     """Simple Resource Dump Manifest document """
     rdm = ResourceDumpManifest()
     rdm.md_at = '2013-01-03T09:00:00Z'
     rdm.add( Resource(uri='http://example.com/res1',
                       lastmod='2013-01-03T03:00:00Z',
                       md5='1584abdf8ebdc9802ac0c6a7402c03b6',
                       path='/resources/res1') )
     rdm.add( Resource(uri='http://example.com/res2',
                       lastmod='2013-01-03T04:00:00Z',
                       md5='1e0d5cb8ef6ba40c99b14c0237be735e',
                       path='/resources/res2') )
     ex_xml = self._open_ex('resourcesync_ex_5').read()
     self._assert_xml_equal( rdm.as_xml(), ex_xml )
Beispiel #8
0
 def test_build_ex_18(self):
     """Resource Dump Manifest with 2 entries and some metadata"""
     rdm = ResourceDumpManifest()
     rdm.up='http://example.com/dataset1/capabilitylist.xml'
     rdm.md_at="2013-01-03T09:00:00Z"
     rdm.md_completed="2013-01-03T09:02:00Z"
     rdm.add( Resource( uri='http://example.com/res1',
                        lastmod='2013-01-02T13:00:00Z',
                        md5='1584abdf8ebdc9802ac0c6a7402c03b6',
                        length=8876,
                        mime_type='text/html',
                        path='/resources/res1') )
     rdm.add( Resource( uri='http://example.com/res2',
                        lastmod='2013-01-02T14:00:00Z',
                        md5='1e0d5cb8ef6ba40c99b14c0237be735e',
                        sha256='854f61290e2e197a11bc91063afce22e43f8ccc655237050ace766adc68dc784',
                        length=14599,
                        mime_type='application/pdf',
                        path='/resources/res2') )
     ex_xml = self._open_ex('resourcesync_ex_18').read()
     self._assert_xml_equal( rdm.as_xml(), ex_xml )