def test_update_nonexistent(self): """ Assert BodhiException is raised if the update doesn't exist. """ with pytest.raises(BodhiException) as exc: work_on_bugs_main('foo', []) assert str(exc.value) == "Couldn't find alias foo in DB"
def test_bug_not_in_database(self, modified): """Test that a bug is automatically created if not present in database.""" update = models.Build.query.filter_by( nvr='bodhi-2.0-1.fc17').one().update bug = models.Bug.query.filter_by(bug_id=123456).first() assert bug is None work_on_bugs_main(update.alias, [ 123456, ]) bug = models.Bug.query.filter_by(bug_id=123456).one() update = models.Build.query.filter_by( nvr='bodhi-2.0-1.fc17').one().update assert bug in update.bugs assert modified.assert_called_once
def test_work_on_bugs_exception(self, warning): """ Assert that work_on_bugs logs a warning when an exception is raised. """ update = models.Build.query.filter_by( nvr='bodhi-2.0-1.fc17').one().update bugs = models.Bug.query.all() bug_ids = [bug.bug_id for bug in bugs] with patch( 'bodhi.server.tasks.work_on_bugs.bug_module.bugtracker.getbug', side_effect=RuntimeError("oh no!")): with pytest.raises(ExternalCallException): work_on_bugs_main(update.alias, bug_ids) warning.assert_called_once_with( 'Error occurred during updating single bug', exc_info=True)
def test_security_bug_sets_update_to_security(self): """Assert that associating a security bug with an Update changes the Update to security.""" update = models.Build.query.filter_by( nvr='bodhi-2.0-1.fc17').one().update # The update should start out in a non-security state so we know that work_on_bugs() changed # it. assert update.type == models.UpdateType.bugfix bug = models.Bug.query.first() # Set this bug to security, so that the update gets switched to security. bug.security = True self.db.flush() bugs = models.Bug.query.all() bug_ids = [bug.bug_id for bug in bugs] work_on_bugs_main(update.alias, bug_ids) assert update.type == models.UpdateType.security
def test_bug_not_associated_to_update(self, modified): """Test that a bug is added to the update if not already associated.""" bug = models.Bug(bug_id=123456) self.db.add(bug) self.db.commit() update = models.Build.query.filter_by( nvr='bodhi-2.0-1.fc17').one().update work_on_bugs_main(update.alias, [ 123456, ]) bug = models.Bug.query.filter_by(bug_id=123456).one() update = models.Build.query.filter_by( nvr='bodhi-2.0-1.fc17').one().update assert bug in update.bugs assert modified.assert_called_once