def test_update_errata_units(self): # existing errata is older than available; should purge and resync available_errata = errata.get_available_errata(self.repo_dir) self.assertEqual(52, len(available_errata)) unit_key = dict() unit_key['id'] = "RHBA-2007:0112" metadata = {'updated' : "2007-03-13 00:00:00"} existing_units = [Unit(TYPE_ID_ERRATA, unit_key, metadata, '')] existing_units[0].updated = "2007-03-13 00:00:00" sync_conduit = importer_mocks.get_sync_conduit(existing_units=existing_units) created_existing_units = errata.get_existing_errata(sync_conduit) self.assertEquals(len(created_existing_units), 1) new_errata, new_units, sync_conduit = errata.get_new_errata_units(available_errata, sync_conduit) self.assertEquals(len(available_errata), len(new_errata))
def test_new_errata_units(self): # existing errata is newer or same as available errata; should skip sync for 1 errata available_errata = errata.get_available_errata(self.repo_dir) print len(available_errata) self.assertEqual(52, len(available_errata)) unit_key = dict() unit_key['id'] = "RHBA-2007:0112" metadata = {} existing_units = [Unit(TYPE_ID_ERRATA, unit_key, metadata, '')] existing_units[0].updated = "2007-03-14 00:00:00" sync_conduit = importer_mocks.get_sync_conduit(existing_units=existing_units) created_existing_units = errata.get_existing_errata(sync_conduit) self.assertEquals(len(created_existing_units), 1) self.assertEquals(len(existing_units), len(created_existing_units)) new_errata, new_units, sync_conduit = errata.get_new_errata_units(available_errata, created_existing_units, sync_conduit) print len(available_errata) - len(created_existing_units), len(new_errata) self.assertEquals(len(available_errata) - len(created_existing_units), len(new_errata))
def test_get_new_errata_units_saves_existing_units(self): # This test is for https://bugzilla.redhat.com/show_bug.cgi?id=870495 available_errata = errata.get_available_errata(self.repo_dir) self.assertEqual(52, len(available_errata)) unit_key = {'id': "RHBA-2007:0112"} metadata = {'updated' : "2007-03-14 00:00:00", 'pkglist': [{'name': 'RHEL Virtualization (v. 5 for 32-bit x86)'}]} existing_units = [Unit(TYPE_ID_ERRATA, unit_key, metadata, '')] existing_units[0].updated = metadata['updated'] sync_conduit = importer_mocks.get_sync_conduit(existing_units=existing_units) created_existing_units = errata.get_existing_errata(sync_conduit) self.assertEquals(len(created_existing_units), 1) self.assertEquals(len(existing_units), len(created_existing_units)) new_errata, new_units, sync_conduit = errata.get_new_errata_units(available_errata, sync_conduit) # The one pre-existing errata makes the number of new errata one less self.assertEquals(len(new_errata), len(available_errata) - 1) # The one existing unit that we passed in as an existing unit should cause save_unit() to be # called one time self.assertEqual(len(sync_conduit.save_unit.mock_calls), 1) # Assert that save_unit was called with the pre-existing errata self.assertEqual(sync_conduit.save_unit.mock_calls[0][1][0], existing_units[0])