Add ability to cancel builds that are in the waiting state
This commit is contained in:
parent
ae8bb5fc13
commit
81ce4c771e
8 changed files with 489 additions and 257 deletions
|
@ -17,7 +17,8 @@ from endpoints.api.team import TeamMember, TeamMemberList, TeamMemberInvite, Org
|
|||
from endpoints.api.tag import RepositoryTagImages, RepositoryTag
|
||||
from endpoints.api.search import FindRepositories, EntitySearch
|
||||
from endpoints.api.image import RepositoryImage, RepositoryImageList
|
||||
from endpoints.api.build import RepositoryBuildStatus, RepositoryBuildLogs, RepositoryBuildList
|
||||
from endpoints.api.build import (RepositoryBuildStatus, RepositoryBuildLogs, RepositoryBuildList,
|
||||
RepositoryBuildResource)
|
||||
from endpoints.api.robot import (UserRobotList, OrgRobot, OrgRobotList, UserRobot,
|
||||
RegenerateUserRobot, RegenerateOrgRobot)
|
||||
from endpoints.api.trigger import (BuildTriggerActivate, BuildTriggerSources, BuildTriggerSubdirs,
|
||||
|
@ -1303,6 +1304,103 @@ class TestGetRepository(ApiTestCase):
|
|||
self.assertEquals(True, json['is_organization'])
|
||||
|
||||
|
||||
|
||||
class TestRepositoryBuildResource(ApiTestCase):
|
||||
def test_cancel_invalidbuild(self):
|
||||
self.login(ADMIN_ACCESS_USER)
|
||||
|
||||
self.deleteResponse(RepositoryBuildResource,
|
||||
params=dict(repository=ADMIN_ACCESS_USER + '/simple', build_uuid='invalid'),
|
||||
expected_code=404)
|
||||
|
||||
def test_cancel_waitingbuild(self):
|
||||
self.login(ADMIN_ACCESS_USER)
|
||||
|
||||
# Request a (fake) build.
|
||||
json = self.postJsonResponse(RepositoryBuildList,
|
||||
params=dict(repository=ADMIN_ACCESS_USER + '/simple'),
|
||||
data=dict(file_id='foobarbaz'),
|
||||
expected_code=201)
|
||||
|
||||
uuid = json['id']
|
||||
|
||||
# Check for the build.
|
||||
json = self.getJsonResponse(RepositoryBuildList,
|
||||
params=dict(repository=ADMIN_ACCESS_USER + '/simple'))
|
||||
|
||||
self.assertEquals(1, len(json['builds']))
|
||||
self.assertEquals(uuid, json['builds'][0]['id'])
|
||||
|
||||
# Cancel the build.
|
||||
self.deleteResponse(RepositoryBuildResource,
|
||||
params=dict(repository=ADMIN_ACCESS_USER + '/simple', build_uuid=uuid),
|
||||
expected_code=201)
|
||||
|
||||
# Check for the build.
|
||||
json = self.getJsonResponse(RepositoryBuildList,
|
||||
params=dict(repository=ADMIN_ACCESS_USER + '/simple'))
|
||||
|
||||
self.assertEquals(0, len(json['builds']))
|
||||
|
||||
|
||||
def test_attemptcancel_scheduledbuild(self):
|
||||
self.login(ADMIN_ACCESS_USER)
|
||||
|
||||
# Request a (fake) build.
|
||||
json = self.postJsonResponse(RepositoryBuildList,
|
||||
params=dict(repository=ADMIN_ACCESS_USER + '/simple'),
|
||||
data=dict(file_id='foobarbaz'),
|
||||
expected_code=201)
|
||||
|
||||
uuid = json['id']
|
||||
|
||||
# Check for the build.
|
||||
json = self.getJsonResponse(RepositoryBuildList,
|
||||
params=dict(repository=ADMIN_ACCESS_USER + '/simple'))
|
||||
|
||||
self.assertEquals(1, len(json['builds']))
|
||||
self.assertEquals(uuid, json['builds'][0]['id'])
|
||||
|
||||
# Set queue item to be picked up.
|
||||
qi = database.QueueItem.get(id=1)
|
||||
qi.available = False
|
||||
qi.save()
|
||||
|
||||
# Try to cancel the build.
|
||||
self.deleteResponse(RepositoryBuildResource,
|
||||
params=dict(repository=ADMIN_ACCESS_USER + '/simple', build_uuid=uuid),
|
||||
expected_code=400)
|
||||
|
||||
|
||||
def test_attemptcancel_workingbuild(self):
|
||||
self.login(ADMIN_ACCESS_USER)
|
||||
|
||||
# Request a (fake) build.
|
||||
json = self.postJsonResponse(RepositoryBuildList,
|
||||
params=dict(repository=ADMIN_ACCESS_USER + '/simple'),
|
||||
data=dict(file_id='foobarbaz'),
|
||||
expected_code=201)
|
||||
|
||||
uuid = json['id']
|
||||
|
||||
# Check for the build.
|
||||
json = self.getJsonResponse(RepositoryBuildList,
|
||||
params=dict(repository=ADMIN_ACCESS_USER + '/simple'))
|
||||
|
||||
self.assertEquals(1, len(json['builds']))
|
||||
self.assertEquals(uuid, json['builds'][0]['id'])
|
||||
|
||||
# Set the build to a different phase.
|
||||
rb = database.RepositoryBuild.get(uuid=uuid)
|
||||
rb.phase = database.BUILD_PHASE.BUILDING
|
||||
rb.save()
|
||||
|
||||
# Try to cancel the build.
|
||||
self.deleteResponse(RepositoryBuildResource,
|
||||
params=dict(repository=ADMIN_ACCESS_USER + '/simple', build_uuid=uuid),
|
||||
expected_code=400)
|
||||
|
||||
|
||||
class TestRepoBuilds(ApiTestCase):
|
||||
def test_getrepo_nobuilds(self):
|
||||
self.login(ADMIN_ACCESS_USER)
|
||||
|
|
Reference in a new issue