Exemplo n.º 1
0
    def test_restore_zipd(self):
        os.system("cd %s; zip -qr samplebag_3.mbag.zip samplebag_3.mbag" %
                  self.tempdir)
        shutil.rmtree(os.path.join(self.tempdir, "samplebag_3.mbag"))

        restored = os.path.join(self.tempdir, "restored")
        rstr = restore.BagRestorer(self.v1 + ".zip",
                                   restored,
                                   compdir=self.tempdir)
        self.assertTrue(not os.path.exists(restored))

        rstr.restore()
        self.assertTrue(os.path.isdir(restored))
        self.assertTrue(
            os.path.isfile(os.path.join(restored, "data", "trial1.json")))
        self.assertTrue(
            os.path.isfile(os.path.join(restored, "data", "trial2.json")))
        self.assertTrue(
            os.path.isfile(
                os.path.join(restored, "data", "trial3", "trial3a.json")))
        self.assertTrue(
            not os.path.isfile(os.path.join(restored, "data", "trial4.json")))

        restoredbag = open_bag(self.v2)
        restoredbag.validate()

        rstr = restore.BagRestorer(self.v2, compdir=self.tempdir)
        self.assertTrue(os.path.exists(self.v2))
        self.assertTrue(
            not os.path.exists(os.path.join(self.v2, "data", "trial1.json")))
        self.assertTrue(
            os.path.exists(os.path.join(self.v2, "data", "trial2.json")))
        self.assertTrue(
            os.path.exists(os.path.join(self.v2, "data", "trial4.json")))
        self.assertTrue(
            not os.path.exists(os.path.join(self.v2, "data", "trial3")))

        rstr.restore()
        self.assertTrue(os.path.isdir(self.v2))
        self.assertTrue(
            os.path.isfile(os.path.join(self.v2, "data", "trial2.json")))
        self.assertTrue(
            os.path.isfile(
                os.path.join(self.v2, "data", "trial3", "trial3a.json")))
        self.assertTrue(
            os.path.isfile(os.path.join(self.v2, "data", "trial4.json")))
        self.assertTrue(
            not os.path.isfile(os.path.join(self.v2, "data", "trial1.json")))
        with open(os.path.join(self.v2, "data", "trial2.json")) as fd:
            content = fd.read()
        self.assertEqual('"Goober!"\n', content)

        restoredbag = open_bag(self.v2)
        restoredbag.validate()
Exemplo n.º 2
0
    def test_restore(self):
        restored = os.path.join(self.tempdir, "restored")
        rstr = restore.BagRestorer(self.v1, restored, compdir=self.tempdir)
        self.assertTrue(not os.path.exists(restored))

        rstr.restore()
        self.assertTrue(os.path.isdir(restored))
        self.assertTrue(
            os.path.isfile(os.path.join(restored, "data", "trial1.json")))
        self.assertTrue(
            os.path.isfile(os.path.join(restored, "data", "trial2.json")))
        self.assertTrue(
            os.path.isfile(
                os.path.join(restored, "data", "trial3", "trial3a.json")))
        self.assertTrue(
            not os.path.isfile(os.path.join(restored, "data", "trial4.json")))

        restoredbag = open_bag(restored)
        restoredbag.validate()

        rstr = restore.BagRestorer(self.v2, compdir=self.tempdir)
        self.assertTrue(os.path.exists(self.v2))
        self.assertTrue(
            not os.path.exists(os.path.join(self.v2, "data", "trial1.json")))
        self.assertTrue(
            os.path.exists(os.path.join(self.v2, "data", "trial2.json")))
        self.assertTrue(
            os.path.exists(os.path.join(self.v2, "data", "trial4.json")))
        self.assertTrue(
            not os.path.exists(os.path.join(self.v2, "data", "trial3")))

        rstr.restore()
        self.assertTrue(os.path.isdir(self.v2))
        self.assertTrue(
            os.path.isfile(os.path.join(self.v2, "data", "trial2.json")))
        self.assertTrue(
            os.path.isfile(
                os.path.join(self.v2, "data", "trial3", "trial3a.json")))
        self.assertTrue(
            os.path.isfile(os.path.join(self.v2, "data", "trial4.json")))
        self.assertTrue(
            not os.path.isfile(os.path.join(self.v2, "data", "trial1.json")))
        with open(os.path.join(self.v2, "data", "trial2.json")) as fd:
            content = fd.read()
        self.assertEqual('"Goober!"\n', content)

        restoredbag = open_bag(self.v2)
        restoredbag.validate()
Exemplo n.º 3
0
    def test_finalize(self):
        self.amender.init_from_amendee()
        self.amender.finalize("3.1")

        bag = bagit.open_bag(self.amendment)
        self.assertEqual(bag.info.get('Multibag-Version'), CURRENT_VERSION)
        self.assertEqual(bag.info.get('Multibag-Tag-Directory'), 'multibag')
        self.assertEqual(bag.info.get('Multibag-Head-Version'), '3.1')
        self.assertEqual(bag.info.get('Multibag-Head-Deprecates'), '1.0')

        tagfile = os.path.join(self.amendment, "multibag", "member-bags.tsv")
        with open(tagfile) as fd:
            names = [line.strip() for line in fd]
        self.assertEquals(names, ["samplembag", "updatebag"])

        tagfile = os.path.join(self.amendment, "multibag", "file-lookup.tsv")
        lu = {}
        nol = 0
        with open(tagfile) as fd:
            for line in fd:
                names = line.strip().split('\t')
                nol += 1
                lu[names[0]] = names[1]

        self.assertEqual(lu.get('data/trial1.json'), 'updatebag')
        self.assertEqual(lu.get('data/trial2.json'), 'samplembag')
        self.assertEqual(lu.get('data/trial3/trial3a.json'), 'samplembag')
        self.assertEqual(lu.get('data/trial3/trial1.json'), 'updatebag')
        self.assertEqual(nol, len(lu))

        # validate it as a headbag
        valid8.validate_headbag(self.amendment)
Exemplo n.º 4
0
 def test_update_for_member(self):
     self.clear_multibag()
     membagdir = os.path.join(datadir, 'samplembag')
     membag = open_bag(membagdir)
     
     self.bag.update_for_member(membag)
     self.assertEqual(self.bag.member_bag_names, ['samplembag'])
     self.assertEqual(self.bag.lookup_file("data/trial2.json"), 'samplembag')
     self.assertEqual(self.bag.lookup_file("data/trial3/trial3a.json"),
                      'samplembag')
     self.assertIsNone(self.bag.lookup_file("metadata/pod.json"))
Exemplo n.º 5
0
    def test_amend_bag_with(self):
        xtrabag1 = os.path.join(self.tempdir, "gooberbag1")
        os.mkdir(xtrabag1)
        srcfile = os.path.join(datadir, "samplembag", "data", "trial2.json")
        shutil.copy(srcfile, xtrabag1)
        bagit.make_bag(xtrabag1)

        xtrabag2 = os.path.join(self.tempdir, "gooberbag2")
        os.mkdir(xtrabag2)
        srcfile = os.path.join(datadir, "samplembag", "data", "trial2.json")
        shutil.copy(srcfile, os.path.join(xtrabag2, "trial4.json"))
        bagit.make_bag(xtrabag2)

        amend.amend_bag_with(self.amendee, self.amendment, "2", xtrabag1,
                             xtrabag2)

        bag = bagit.open_bag(self.amendment)
        self.assertEqual(bag.info.get('Multibag-Version'), CURRENT_VERSION)
        self.assertEqual(bag.info.get('Multibag-Tag-Directory'), 'multibag')
        self.assertEqual(bag.info.get('Multibag-Head-Version'), '2')
        self.assertEqual(bag.info.get('Multibag-Head-Deprecates'), '1.0')

        tagfile = os.path.join(self.amendment, "multibag", "member-bags.tsv")
        with open(tagfile) as fd:
            names = [line.strip() for line in fd]
            self.assertEquals(
                names, ["samplembag", "gooberbag1", "gooberbag2", "updatebag"])

        tagfile = os.path.join(self.amendment, "multibag", "file-lookup.tsv")
        lu = {}
        nol = 0
        with open(tagfile) as fd:
            for line in fd:
                names = line.strip().split('\t')
                nol += 1
                lu[names[0]] = names[1]

        self.assertEqual(lu.get('data/trial1.json'), 'updatebag')
        self.assertEqual(lu.get('data/trial2.json'), 'gooberbag1')
        self.assertEqual(lu.get('data/trial4.json'), 'gooberbag2')
        self.assertEqual(lu.get('data/trial3/trial3a.json'), 'samplembag')
        self.assertEqual(lu.get('data/trial3/trial1.json'), 'updatebag')
        self.assertEqual(nol, len(lu))

        # validate it as a headbag
        valid8.validate_headbag(self.amendment)
Exemplo n.º 6
0
 def setUp(self):
     self.bagroot = os.path.join(datadir, "samplembag.zip")
     self.bag = xtend.as_extended(open_bag(self.bagroot))