def test_delete_expired_coprs(self, f_users, f_mock_chroots, f_coprs, f_builds, f_db): query = self.db.session.query(models.Copr) # nothing is deleted at the beginning assert len([c for c in query.all() if c.deleted]) == 0 # one is to be deleted in the future self.c1.delete_after_days = 2 # one is already to be deleted self.c2.delete_after = datetime.datetime.now() - datetime.timedelta( days=1) # and one is not to be temporary at all (c3) ComplexLogic.delete_expired_projects() self.db.session.commit() query = self.db.session.query(models.Copr) assert len(query.all()) == 3 # we only set deleted=true # some builds are not finished, nothing deleted yet assert len([c for c in query.all() if c.deleted]) == 0 b = self.db.session.query(models.Build).get(3) b.canceled = True ComplexLogic.delete_expired_projects() self.db.session.commit() # some builds are not finished, nothing deleted yet assert len([c for c in query.all() if c.deleted]) == 1 # test that build is deleted as well assert not self.db.session.query(models.Build).get(3)
def clean_expired_projects(): """ Clean all the expired temporary projects. This command is meant to be executed by cron. """ with db_session_scope(): ComplexLogic.delete_expired_projects()
def run(self): with db_session_scope(): ComplexLogic.delete_expired_projects()