def test_create_zip(self):
        # create directory
        prepare_path = Path.objects.get(entity="path_preingest_prepare").value
        dirname = os.path.join(prepare_path, "zipdir")
        os.makedirs(dirname)

        # create empty file
        filename = os.path.join(dirname, "file.txt")
        open(filename, "a").close()

        zipname = dirname + ".zip"

        task = ProcessTask(
            name="preingest.tasks.CreateZIP",
            params={
                "dirname": dirname,
                "zipname": zipname
            },
        )
        task.run()

        self.assertTrue(os.path.isdir(dirname))
        self.assertTrue(os.path.isfile(filename))
        self.assertTrue(os.path.isfile(zipname))

        shutil.rmtree(dirname)
        task.undo()

        self.assertTrue(os.path.isdir(dirname))
        self.assertTrue(os.path.isfile(filename))
        self.assertFalse(os.path.isfile(zipname))
    def test_create_physical_model(self):
        ip = InformationPackage.objects.create(Label="ip1")
        prepare_path = Path.objects.get(entity="path_preingest_prepare").value
        path = os.path.join(prepare_path, unicode(ip.pk))

        task = ProcessTask(
            name="preingest.tasks.CreatePhysicalModel",
            params={
                "structure": [{
                    "name": "dir1",
                    "type": "folder"
                }, {
                    "name": "dir2",
                    "type": "folder",
                }, {
                    "name": "file1",
                    "type": "file"
                }]
            },
            information_package=ip,
        )
        task.run()

        self.assertTrue(os.path.isdir(os.path.join(path, 'dir1')))
        self.assertTrue(os.path.isdir(os.path.join(path, 'dir2')))
        self.assertFalse(os.path.isfile(os.path.join(path, 'file1')))

        task.undo()

        self.assertFalse(os.path.isdir(os.path.join(path, 'dir1')))
        self.assertFalse(os.path.isdir(os.path.join(path, 'dir2')))
Exemple #3
0
    def test_receive_sip(self):
        ip = InformationPackage.objects.create()

        srctar = os.path.join(self.ingest_reception, "%s.tar" % ip.pk)
        srcxml = os.path.join(self.ingest_reception, "%s.xml" % ip.pk)
        open(srctar, "a").close()
        open(srcxml, "a").close()

        ip.ObjectPath = os.path.join(self.ingest_reception, str(ip.pk) + ".tar")
        ip.save()

        task = ProcessTask(
            name="preingest.tasks.ReceiveSIP",
            params={
                "ip": ip
            },
        )
        task.run()

        self.assertTrue(os.path.isfile(os.path.join(self.ingest_work, str(ip.pk) + ".tar")))
        self.assertTrue(os.path.isfile(os.path.join(self.ingest_work, str(ip.pk) + ".xml")))

        task.undo()

        self.assertFalse(os.path.isfile(os.path.join(self.ingest_work, str(ip.pk) + ".tar")))
        self.assertFalse(os.path.isfile(os.path.join(self.ingest_work, str(ip.pk) + ".xml")))
    def test_create_ip_root_dir(self):
        ip = InformationPackage.objects.create(Label="ip1")
        prepare_path = Path.objects.get(entity="path_preingest_prepare").value
        prepare_path = os.path.join(prepare_path, unicode(ip.pk))

        task = ProcessTask(
            name="preingest.tasks.CreateIPRootDir",
            params={
                "information_package": ip,
            },
        )
        task.run()

        self.assertTrue(os.path.isdir(prepare_path))

        task.undo()

        self.assertFalse(os.path.isdir(prepare_path))
    def test_prepare_ip(self):
        label = "ip1"
        user = User.objects.create(username="******")

        task = ProcessTask(name="preingest.tasks.PrepareIP",
                           params={
                               "label": label,
                               "responsible": user
                           },
                           responsible=user)
        task.run()

        self.assertTrue(
            InformationPackage.objects.filter(Label=label).exists())

        task.undo()

        self.assertFalse(
            InformationPackage.objects.filter(Label=label).exists())
    def test_submit_sip(self):
        ip = InformationPackage.objects.create(Label="ip1")

        srctar = os.path.join(self.preingest_reception, "%s.tar" % ip.pk)
        srcxml = os.path.join(self.preingest_reception, "%s.xml" % ip.pk)
        dsttar = os.path.join(self.ingest_reception, "%s.tar" % ip.pk)
        dstxml = os.path.join(self.ingest_reception, "%s.xml" % ip.pk)
        open(srctar, "a").close()
        open(srcxml, "a").close()

        task = ProcessTask(
            name="preingest.tasks.SubmitSIP",
            params={"ip": ip},
        )
        task.run()

        self.assertTrue(os.path.isfile(dsttar))
        self.assertTrue(os.path.isfile(dstxml))

        task.undo()

        self.assertFalse(os.path.isfile(dsttar))
        self.assertFalse(os.path.isfile(dstxml))