Example #1
0
    def test_parse_empty_deltarepos(self):
        # Try to parse deltarepos.xml with no items (the deltarepos.xml is valid!)
        path = os.path.join(self.tmpdir, "empty.xml")
        open(path, "w").write(XML_EMPTY)

        dr = DeltaRepos()
        dr.load(path)

        self.assertEqual(len(dr.records), 0)
Example #2
0
    def test_parse_empty_deltarepos(self):
        # Try to parse deltarepos.xml with no items (the deltarepos.xml is valid!)
        path = os.path.join(self.tmpdir, "empty.xml")
        open(path, "w").write(XML_EMPTY)

        dr = DeltaRepos()
        dr.load(path)

        self.assertEqual(len(dr.records), 0)
Example #3
0
    def test_dump_and_load_empty_deltarepos_02(self):
        # Try to dump and load an empty DeltaRepos object (via files)
        path_without_suffix = os.path.join(self.tmpdir, "dump_empty.xml")

        path = DeltaRepos().dump(path_without_suffix)
        self.assertEqual(path, path_without_suffix+".xz")

        dr = DeltaRepos()
        dr.load(path)

        self.assertEqual(len(dr.records), 0)
Example #4
0
    def test_dump_and_load_empty_deltarepos_02(self):
        # Try to dump and load an empty DeltaRepos object (via files)
        path_without_suffix = os.path.join(self.tmpdir, "dump_empty.xml")

        path = DeltaRepos().dump(path_without_suffix)
        self.assertEqual(path, path_without_suffix + ".xz")

        dr = DeltaRepos()
        dr.load(path)

        self.assertEqual(len(dr.records), 0)
Example #5
0
    def test_update_02(self):
        # Try to update deltarepos.xml.xz (deletion of a repo)
        dir = tempfile.mkdtemp(prefix="update_02-", dir=self.tmpdir)
        path = os.path.join(dir, "deltarepos.xml.xz")

        first = cp(DELTAREPO_01_01, dir)
        cp(DELTAREPO_01_02, dir)
        ret = gen_deltarepos_file(dir, self.logger)
        self.assertEqual(ret, path)
        self.assertTrue(os.path.isfile(path))

        dr = DeltaRepos()
        dr.load(path)
        self.assertEqual(len(dr.records), 2)
        rec = dr.records[0]
        self.assertEqual(rec.location_href, os.path.basename(DELTAREPO_01_01))
        rec = dr.records[1]
        self.assertEqual(rec.location_href, os.path.basename(DELTAREPO_01_02))

        shutil.rmtree(first)
        ret = gen_deltarepos_file(dir, self.logger, update=True)
        self.assertEqual(ret, path)
        self.assertTrue(os.path.isfile(path))

        dr = DeltaRepos()
        dr.load(path)
        self.assertEqual(len(dr.records), 1)
        rec = dr.records[0]
        self.assertEqual(rec.location_href, os.path.basename(DELTAREPO_01_02))
Example #6
0
    def test_one_repo(self):
        # Try to generate deltarepos.xml.xz for a directory with one repo
        dir = tempfile.mkdtemp(prefix="one_repo-", dir=self.tmpdir)
        path = os.path.join(dir, "deltarepos.xml.xz")
        cp(DELTAREPO_01_01, dir)
        ret = gen_deltarepos_file(dir, self.logger)
        self.assertEqual(ret, path)
        self.assertTrue(os.path.isfile(path))

        dr = DeltaRepos()
        dr.load(path)
        self.assertEqual(len(dr.records), 1)
        rec = dr.records[0]
        self.assertEqual(rec.location_href, os.path.basename(DELTAREPO_01_01))
Example #7
0
    def test_parse_deltarepos_01(self):
        # Try to parse deltarepos.xml with some content
        path = os.path.join(self.tmpdir, "01.xml")
        open(path, "w").write(XML_01)

        dr = DeltaRepos()
        dr.load(path)

        self.assertEqual(len(dr.records), 1)

        rec = dr.records[0]

        self.assertEqual(rec.location_base, None)
        self.assertEqual(rec.location_href, "deltarepos/ei7as764ly-043fds4red")
        self.assertEqual(rec.size_total, 8729)
        self.assertEqual(rec.revision_src, "1387077123")
        self.assertEqual(rec.revision_dst, "1387087456")
        self.assertEqual(rec.timestamp_src, 1387075111)
        self.assertEqual(rec.timestamp_dst, 1387086222)

        self.assertEqual(rec.get_data("primary").get("size"), 7766)
Example #8
0
    def test_parse_deltarepos_01(self):
        # Try to parse deltarepos.xml with some content
        path = os.path.join(self.tmpdir, "01.xml")
        open(path, "w").write(XML_01)

        dr = DeltaRepos()
        dr.load(path)

        self.assertEqual(len(dr.records), 1)

        rec = dr.records[0]

        self.assertEqual(rec.location_base, None)
        self.assertEqual(rec.location_href, "deltarepos/ei7as764ly-043fds4red")
        self.assertEqual(rec.size_total, 8729)
        self.assertEqual(rec.revision_src, "1387077123")
        self.assertEqual(rec.revision_dst, "1387087456")
        self.assertEqual(rec.timestamp_src, 1387075111)
        self.assertEqual(rec.timestamp_dst, 1387086222)

        self.assertEqual(rec.get_data("primary").get("size"), 7766)
Example #9
0
    def test_dump_deltarepos_01(self):
        # Ty to dump fully filled DeltaRepos object
        rec = DeltaRepoRecord()

        # An empty record shouldn't be valid
        self.assertRaises(TypeError, rec.validate)

        # Fill the record with valid data
        rec.location_href = "deltarepos/ei7as764ly-043fds4red"
        rec.revision_src = "1387077123"
        rec.revision_dst = "1387086456"
        rec.contenthash_src = "a"
        rec.contenthash_dst = "b"
        rec.contenthash_type = "md5"
        rec.timestamp_src = 1387075111
        rec.timestamp_dst = 1387086222

        rec.set_data("primary", size=7766)

        rec.repomd_timestamp = 123456789
        rec.repomd_size = 963
        rec.repomd_checksums = [("sha256", "foobarchecksum")]

        # All mandatory arguments should be filled and thus the record should be valid
        rec.validate()

        # Dump the content to a file
        dr = DeltaRepos()
        dr.append_record(rec)
        path = dr.dump(os.path.join(self.tmpdir, "dump_01.xml"))

        # Load the content
        dr = DeltaRepos()
        dr.load(path)

        # Check the content
        self.assertEqual(len(dr.records), 1)
        self.assertEqual(dr.records[0].__dict__, rec.__dict__)
Example #10
0
    def test_dump_deltarepos_01(self):
        # Ty to dump fully filled DeltaRepos object
        rec = DeltaRepoRecord()

        # An empty record shouldn't be valid
        self.assertRaises(TypeError, rec.validate)

        # Fill the record with valid data
        rec.location_href = "deltarepos/ei7as764ly-043fds4red"
        rec.revision_src = "1387077123"
        rec.revision_dst = "1387086456"
        rec.contenthash_src = "a"
        rec.contenthash_dst = "b"
        rec.contenthash_type = "md5"
        rec.timestamp_src = 1387075111
        rec.timestamp_dst = 1387086222

        rec.set_data("primary", size=7766)

        rec.repomd_timestamp = 123456789
        rec.repomd_size = 963
        rec.repomd_checksums = [("sha256", "foobarchecksum")]

        # All mandatory arguments should be filled and thus the record should be valid
        rec.validate()

        # Dump the content to a file
        dr = DeltaRepos()
        dr.append_record(rec)
        path = dr.dump(os.path.join(self.tmpdir, "dump_01.xml"))

        # Load the content
        dr = DeltaRepos()
        dr.load(path)

        # Check the content
        self.assertEqual(len(dr.records), 1)
        self.assertEqual(dr.records[0].__dict__, rec.__dict__)
Example #11
0
    def test_dump_and_load_with_different_compressions(self):
        # Try to dump DeltaRepos with different compression types
        dr = DeltaRepos()
        path_without_suffix = os.path.join(self.tmpdir, "dump_with_different_suffixes.xml")

        # Default (XZ)
        path = dr.dump(path_without_suffix)
        self.assertTrue(os.path.isfile(path))
        self.assertEqual(path, path_without_suffix+".xz")
        DeltaRepos().load(path)  # Exception shouldn't be raised

        # No compression
        path = dr.dump(path_without_suffix, deltarepo.NO_COMPRESSION)
        self.assertTrue(os.path.isfile(path))
        self.assertEqual(path, path_without_suffix)
        DeltaRepos().load(path)  # Exception shouldn't be raised

        # GZ
        path = dr.dump(path_without_suffix, deltarepo.GZ)
        self.assertTrue(os.path.isfile(path))
        self.assertEqual(path, path_without_suffix+".gz")
        DeltaRepos().load(path)  # Exception shouldn't be raised

        # BZ2
        path = dr.dump(path_without_suffix, deltarepo.BZ2)
        self.assertTrue(os.path.isfile(path))
        self.assertEqual(path, path_without_suffix+".bz2")
        DeltaRepos().load(path)  # Exception shouldn't be raised

        # XZ
        path = dr.dump(path_without_suffix, deltarepo.XZ)
        self.assertTrue(os.path.isfile(path))
        self.assertEqual(path, path_without_suffix+".xz")
        DeltaRepos().load(path)  # Exception shouldn't be raised

        # Error cases

        # Auto-detect compression
        self.assertRaises(DeltaRepoError, dr.dump, path_without_suffix, deltarepo.AUTO_DETECT_COMPRESSION)

        # Unknown compression
        self.assertRaises(DeltaRepoError, dr.dump, path_without_suffix, deltarepo.UNKNOWN_COMPRESSION)
Example #12
0
    def test_dump_and_load_with_different_compressions(self):
        # Try to dump DeltaRepos with different compression types
        dr = DeltaRepos()
        path_without_suffix = os.path.join(self.tmpdir,
                                           "dump_with_different_suffixes.xml")

        # Default (XZ)
        path = dr.dump(path_without_suffix)
        self.assertTrue(os.path.isfile(path))
        self.assertEqual(path, path_without_suffix + ".xz")
        DeltaRepos().load(path)  # Exception shouldn't be raised

        # No compression
        path = dr.dump(path_without_suffix, deltarepo.NO_COMPRESSION)
        self.assertTrue(os.path.isfile(path))
        self.assertEqual(path, path_without_suffix)
        DeltaRepos().load(path)  # Exception shouldn't be raised

        # GZ
        path = dr.dump(path_without_suffix, deltarepo.GZ)
        self.assertTrue(os.path.isfile(path))
        self.assertEqual(path, path_without_suffix + ".gz")
        DeltaRepos().load(path)  # Exception shouldn't be raised

        # BZ2
        path = dr.dump(path_without_suffix, deltarepo.BZ2)
        self.assertTrue(os.path.isfile(path))
        self.assertEqual(path, path_without_suffix + ".bz2")
        DeltaRepos().load(path)  # Exception shouldn't be raised

        # XZ
        path = dr.dump(path_without_suffix, deltarepo.XZ)
        self.assertTrue(os.path.isfile(path))
        self.assertEqual(path, path_without_suffix + ".xz")
        DeltaRepos().load(path)  # Exception shouldn't be raised

        # Error cases

        # Auto-detect compression
        self.assertRaises(DeltaRepoError, dr.dump, path_without_suffix,
                          deltarepo.AUTO_DETECT_COMPRESSION)

        # Unknown compression
        self.assertRaises(DeltaRepoError, dr.dump, path_without_suffix,
                          deltarepo.UNKNOWN_COMPRESSION)
Example #13
0
 def test_dump_and_load_empty_deltarepos_01(self):
     # Try to dump and load an empty DeltaRepos object (only via memory)
     content = DeltaRepos().dumps()
     dr = DeltaRepos().loads(content)
     self.assertEqual(len(dr.records), 0)