def test_merge_pkglists_same_repo_older(self, mock_update_needed, mock_errata_obj, mock_pkglist_obj, mock_save): """ Assert that the existing pkglist is untouched, if the uploaded erratum is older than the existing one. """ existing_collection = copy.deepcopy(self.collection) uploaded_collection = copy.deepcopy(self.collection) uploaded_collection['packages'][0]['version'] = '2.0' existing_pkglist_data = { 'errata_id': 'some erratum', 'collections': [existing_collection] } uploaded_erratum_data = { 'errata_id': 'some erratum', 'pkglist': [uploaded_collection] } existing_pkglist = models.ErratumPkglist(**existing_pkglist_data) uploaded_erratum = models.Errata(**uploaded_erratum_data) mock_pkglist_obj.filter.return_value.first.return_value = existing_pkglist mock_errata_obj.filter.return_value.first.return_value = models.Errata( ) mock_update_needed.return_value = False mock_save.side_effect = NotUniqueError errata_controller.create_or_update_pkglist(uploaded_erratum, 'my_repo') # make sure save() is called once since existing pkglist is untouched self.assertEqual(mock_save.call_count, 1) # make sure pkglist on the Erratum model is empty anyway self.assertEqual(uploaded_erratum.pkglist, [])
def test_rpm_search_dicts_no_checksum(self, mock_erratumpkglist_objects): """ Assert that the rpm_search_dicts() method tolerates a missing checksumtype, as is found when using this demo repo: https://repos.fedorapeople.org/repos/pulp/pulp/demo_repos/zoo/ """ errata = models.Errata() errata_pkglist = models.ErratumPkglist() errata_pkglist.collections = [{ 'packages': [{ 'name': 'foo', 'epoch': '0', 'version': '0.0', 'sum': None, 'release': 'release', 'arch': 'arch' }] }] mock_erratumpkglist_objects.return_value = [errata_pkglist] ret = errata.rpm_search_dicts # sanity-check that there is one result with the correct name self.assertEqual(len(ret), 1) self.assertEqual(ret[0]['name'], 'foo') # make sure this field is still not present self.assertTrue('checksumtype' not in ret[0])
def test_rpm_search_dicts_sanitizes_checksum_type_sums( self, mock_erratumpkglist_objects): """ Assert that the rpm_search_dicts() method properly sanitizes checksum types with the sum is specified with the 'type' attribute. """ errata = models.Errata() errata_pkglist = models.ErratumPkglist() errata_pkglist.collections = [{ 'packages': [{ 'name': 'name', 'epoch': '0', 'version': '0.0', 'sums': ['sum1', 'sum2'], 'release': 'release', 'arch': 'arch', 'type': 'sha' }] }] mock_erratumpkglist_objects.return_value = [errata_pkglist] ret = errata.rpm_search_dicts self.assertEqual(len(ret), 1) self.assertEqual(ret[0]['checksumtype'], 'sha1')
def test_merge_pkglists_same_repo_newer(self, mock_update_needed, mock_errata_obj, mock_pkglist_obj, mock_save): """ Assert that the existing pkglist is overwritten, if the uploaded erratum is newer than the existing one. """ existing_collection = copy.deepcopy(self.collection) uploaded_collection = copy.deepcopy(self.collection) uploaded_collection['packages'][0]['version'] = '2.0' existing_pkglist_data = { 'errata_id': 'some erratum', 'collections': [existing_collection] } uploaded_erratum_data = { 'errata_id': 'some erratum', 'pkglist': [uploaded_collection] } existing_pkglist = models.ErratumPkglist(**existing_pkglist_data) uploaded_erratum = models.Errata(**uploaded_erratum_data) mock_pkglist_obj.filter.return_value.first.return_value = existing_pkglist mock_update_needed.return_value = True mock_save.side_effect = [NotUniqueError, None] errata_controller.create_or_update_pkglist(uploaded_erratum, 'my_repo') # make sure the existing collection is changed self.assertEqual( existing_pkglist.collections[0]['packages'][0]['version'], uploaded_collection['packages'][0]['version']) # make sure save() is called twice since existing pkglist was updated self.assertEqual(mock_save.call_count, 2) # make sure pkglist on the Erratum model is empty self.assertEqual(uploaded_erratum.pkglist, [])