Select the full RepositoryBuild record
If we just return the ID, then peewee just fills in the other fields with defaults (such as UUID).
This commit is contained in:
parent
80b24494b5
commit
474fffd01f
2 changed files with 13 additions and 3 deletions
|
@ -175,11 +175,12 @@ def get_archivable_build():
|
|||
.alias('candidates'))
|
||||
|
||||
try:
|
||||
return (RepositoryBuild
|
||||
found_id = (RepositoryBuild
|
||||
.select(candidates.c.id)
|
||||
.from_(candidates)
|
||||
.order_by(db_random_func())
|
||||
.get())
|
||||
return RepositoryBuild.get(id=found_id)
|
||||
except RepositoryBuild.DoesNotExist:
|
||||
return None
|
||||
|
||||
|
|
|
@ -24,17 +24,26 @@ class TestSpecificQueries(unittest.TestCase):
|
|||
result = model.build.get_archivable_build()
|
||||
self.assertIsNone(result)
|
||||
|
||||
# Add a build that we know needs to be archived.
|
||||
# Add a build that cannot (yet) be archived.
|
||||
repo = model.repository.get_repository(ADMIN_ACCESS_USER, SIMPLE_REPO)
|
||||
token = model.token.create_access_token(repo, 'write')
|
||||
created = RepositoryBuild.create(repository=repo, access_token=token,
|
||||
phase=model.build.BUILD_PHASE.COMPLETE,
|
||||
phase=model.build.BUILD_PHASE.WAITING,
|
||||
logs_archived=False, job_config='{}',
|
||||
display_name='')
|
||||
|
||||
# Make sure there are no archivable logs.
|
||||
result = model.build.get_archivable_build()
|
||||
self.assertIsNone(result)
|
||||
|
||||
# Change the build to being complete.
|
||||
created.phase = model.build.BUILD_PHASE.COMPLETE
|
||||
created.save()
|
||||
|
||||
# Make sure we now find an archivable build.
|
||||
result = model.build.get_archivable_build()
|
||||
self.assertEquals(created.id, result.id)
|
||||
self.assertEquals(created.uuid, result.uuid)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
Reference in a new issue