Skip to content

Commit

Permalink
Allow moving builds from unpushed updates to other updates
Browse files Browse the repository at this point in the history
Signed-off-by: Mattia Verga <mattia.verga@tiscali.it>
  • Loading branch information
mattiaverga committed Sep 24, 2023
1 parent 8ebd729 commit 477a0ac
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 6 deletions.
14 changes: 8 additions & 6 deletions bodhi-server/bodhi/server/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,19 +286,21 @@ def validate_builds(request, **kwargs):
for nvr in builds:
# Ensure it doesn't already exist in another update
build = request.db.query(Build).filter_by(nvr=nvr).first()
if build and build.update is not None and up.alias != build.update.alias:
if (build and build.update is not None and up.alias != build.update.alias
and build.update.status != UpdateStatus.unpushed):
request.errors.add('body', 'builds',
"Update for {} already exists".format(nvr))
return

return

for nvr in builds:
build = request.db.query(Build).filter_by(nvr=nvr).first()
if build and build.update is not None:
if build.update.status != UpdateStatus.unpushed:
request.errors.add('body', 'builds',
"Update for {} already exists".format(nvr))
return
if (build and build.update is not None
and build.update.status != UpdateStatus.unpushed):
request.errors.add('body', 'builds',
"Update for {} already exists".format(nvr))
return


@postschema_validator
Expand Down
70 changes: 70 additions & 0 deletions bodhi-server/tests/services/test_updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -5998,6 +5998,76 @@ def test_edit_testing_update_with_build_from_different_update(self, *args):
assert len(up.builds) == 1
assert up.builds[0].nvr == nvr1

@mock.patch('bodhi.server.services.updates.handle_side_and_related_tags_task', mock.Mock())
@mock.patch('bodhi.server.models.tag_update_builds_task', mock.Mock())
@mock.patch(**mock_valid_requirements)
def test_edit_testing_update_with_build_from_unpushed_update(self, *args):
"""
Allow to move a build from an unpushed update into another existing update
"""
# Create an update with a build that we will try and add to another update
nvr1 = 'bodhi-2.0.0-2.fc17'
args = self.get_update(nvr1)

with fml_testing.mock_sends(update_schemas.UpdateRequestTestingV1):
r = self.app.post_json('/updates/', args)

# Mark it as unpushed
upd = Update.get(r.json['alias'])
unpushed_alias = upd.alias
upd.status = UpdateStatus.unpushed
upd.request = None
# Clear pending messages
self.db.info['messages'] = []
self.db.commit()

# Create an update for a different build
nvr2 = 'koji-2.0.0-1.fc17'
args = self.get_update(nvr2)

with fml_testing.mock_sends(update_schemas.UpdateRequestTestingV1):
r = self.app.post_json('/updates/', args)

# Mark it as testing
upd = Update.get(r.json['alias'])
upd.status = UpdateStatus.testing
upd.request = None
# Clear pending messages
self.db.info['messages'] = []
self.db.commit()

# Edit the nvr2 update and add nvr1
args['edited'] = upd.alias
args['builds'] = '%s,%s' % (nvr1, nvr2)
with fml_testing.mock_sends(update_schemas.UpdateRequestTestingV1,
update_schemas.UpdateEditV2):
r = self.app.post_json('/updates/', args)
up = r.json_body
assert len(up['builds']) == 2
assert up['comments'][-1]['text'] == 'This update has been submitted for testing by guest. '
comment = textwrap.dedent("""
guest edited this update.
New build(s):
- bodhi-2.0.0-2.fc17
Karma has been reset.
""").strip()
assert_multiline_equal(up['comments'][-2]['text'], comment)

# The newer update should have both builds
up = Update.get(upd.alias)
assert up.status == UpdateStatus.pending
assert up.request == UpdateRequest.testing
assert len(up.builds) == 2

# The unpushed update should have no builds
unpushed_update = Update.get(unpushed_alias)
unpushed_update.title == unpushed_alias
assert unpushed_update.status == UpdateStatus.unpushed
assert len(unpushed_update.builds) == 0

@mock.patch('bodhi.server.services.updates.handle_side_and_related_tags_task', mock.Mock())
@mock.patch('bodhi.server.models.tag_update_builds_task', mock.Mock())
@mock.patch(**mock_valid_requirements)
Expand Down
1 change: 1 addition & 0 deletions news/5485.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Builds associated to unpushed updates can now be moved to other existing updates

0 comments on commit 477a0ac

Please sign in to comment.