def test_rebuild_if_not_exists_already_exists(self, advisories_from_event): handler = UpdateDBOnAdvisoryChange() db_event = Event.create(db.session, "msg124", "123", ErrataAdvisoryRPMsSignedEvent) db.session.commit() for manual in [True, False]: for db_event_state in [ EventState.INITIALIZED, EventState.BUILDING, EventState.COMPLETE, EventState.FAILED, EventState.SKIPPED ]: db_event.state = db_event_state db.session.commit() for state in [ "REL_PREP", "PUSH_READY", "IN_PUSH", "SHIPPED_LIVE" ]: advisories_from_event.return_value = [ ErrataAdvisory(123, "RHSA-2017", state, ["rpm"], "Critical") ] ev = ErrataAdvisoryStateChangedEvent( "msg123", ErrataAdvisory(123, 'RHSA-2017', state, ['rpm'])) ev.manual = manual ev.dry_run = manual # use also manual just for the sake of test. ret = handler.handle(ev) if db_event_state == EventState.FAILED or ev.manual: self.assertEqual(len(ret), 1) self.assertEqual(ret[0].manual, manual) self.assertEqual(ret[0].dry_run, manual) else: self.assertEqual(len(ret), 0)
def test_rebuild_if_errata_state_is_not_allowed_but_manual_is_true( self, rebuild_if_not_exists): rebuild_if_not_exists.return_value = [Mock()] Event.create(db.session, "msg-id-123", "123456", ErrataAdvisoryRPMsSignedEvent, False) db.session.commit() event = ErrataAdvisoryStateChangedEvent( 'msg-id-123', ErrataAdvisory(123456, "name", 'SHIPPED_LIVE', ['rpm'])) event.manual = True handler = UpdateDBOnAdvisoryChange() msgs = handler.handle(event) self.assertEqual(len(msgs), 1)