Example #1
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 #2
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 #3
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 #4
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__)