Skip to content

Commit

Permalink
Fix an issue with updaterecord md generation w/ new api
Browse files Browse the repository at this point in the history
  • Loading branch information
dralley committed May 10, 2024
1 parent 4bde262 commit 70ad284
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 20 deletions.
4 changes: 1 addition & 3 deletions src/python/createrepo_c/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -714,10 +714,8 @@ def finish(self):
if self._updaterecords:
upd_xml_path = self.repodata_dir / ("updateinfo.xml" + self._compression_suffix)
writer = UpdateInfoXmlFile(str(upd_xml_path), compressiontype=self._compression)
updateinfo = UpdateInfo()
for rec in self._updaterecords:
updateinfo.append(rec)
writer.add_chunk(updateinfo.xml_dump())
writer.add_chunk(_createrepo_c.xml_dump_updaterecord(rec))
self.working_metadata_files["updateinfo"] = MetadataInfoHolder(upd_xml_path, writer)

# Create all the repomdrecords for the standard metadata
Expand Down
66 changes: 49 additions & 17 deletions tests/python/tests/test_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def test_count_packages(self):

assert reader.package_count() == 1


class TestCaseRepositoryWriter(unittest.TestCase):

def setUp(self):
Expand Down Expand Up @@ -99,13 +100,18 @@ def test_defaults(self):
record_path = os.path.join(self.tmpdir, record.location_href)
assert os.path.exists(record_path)

reader = cr.RepositoryReader.from_path(self.tmpdir)
for pkg in reader.iter_packages():
# test that the package files are present where expected
pkg_path = os.path.join(self.tmpdir, pkg.location_href)
assert os.path.exists(pkg_path)
# test that the package checksum type is correct
assert pkg.checksum_type == "sha256"
reader = cr.RepositoryReader.from_path(self.tmpdir)
for pkg in reader.iter_packages():
# test that the package files are present where expected
pkg_path = os.path.join(self.tmpdir, pkg.location_href)
assert os.path.exists(pkg_path)
# test that the package checksum type is correct
assert pkg.checksum_type == "sha256"

expected_updaterecords = [TEST_UPDATERECORD_UPDATE1]
for expected, actual in zip(expected_updaterecords, reader.advisories()):
assert_updaterecord_equal(expected, actual)


def test_options(self):
"""Test that overriding default options works as intended"""
Expand Down Expand Up @@ -142,15 +148,20 @@ def test_options(self):
record_path = os.path.join(self.tmpdir, record.location_href)
assert os.path.exists(record_path)

reader = cr.RepositoryReader.from_path(self.tmpdir)
for pkg in reader.iter_packages():
# test that the package files are present where expected
pkg_path = os.path.join(self.tmpdir, pkg.location_href)
assert os.path.exists(pkg_path)
# test that changelog_limit works
assert len(pkg.changelogs) <= 1
# test that the package checksum type is correct
assert pkg.checksum_type == "sha512"
reader = cr.RepositoryReader.from_path(self.tmpdir)
for pkg in reader.iter_packages():
# test that the package files are present where expected
pkg_path = os.path.join(self.tmpdir, pkg.location_href)
assert os.path.exists(pkg_path)
# test that changelog_limit works
assert len(pkg.changelogs) <= 1
# test that the package checksum type is correct
assert pkg.checksum_type == "sha512"

expected_updaterecords = [TEST_UPDATERECORD_UPDATE1]
for expected, actual in zip(expected_updaterecords, reader.advisories()):
assert_updaterecord_equal(expected, actual)


def test_add_repo_metadata(self):
"""Test adding an additional repo metadata file to the repository."""
Expand Down Expand Up @@ -239,4 +250,25 @@ def test_add_package(self):
assert pkg.location_href.startswith("Packages/")
# test that the package files are present where expected
pkg_path = os.path.join(self.tmpdir, pkg.location_href)
assert os.path.exists(pkg_path)
assert os.path.exists(pkg_path)


def assert_updaterecord_equal(expected, actual):
assert expected.fromstr == actual.fromstr
assert expected.status == actual.status
assert expected.type == actual.type
assert expected.version == actual.version
assert expected.id == actual.id
assert expected.title == actual.title
assert expected.issued_date == actual.issued_date
assert expected.updated_date == actual.updated_date
assert expected.rights == actual.rights
assert expected.release == actual.release
assert expected.pushcount == actual.pushcount
assert expected.severity == actual.severity
assert expected.summary == actual.summary
assert expected.reboot_suggested == actual.reboot_suggested
assert expected.description == actual.description
assert expected.solution == actual.solution
assert len(expected.references) == len(actual.references)
assert len(expected.collections) == len(actual.collections)

0 comments on commit 70ad284

Please sign in to comment.