-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add script and tests for moving a batched request to a stable request
re #1157
- Loading branch information
1 parent
80b6fa5
commit 7c48a9f
Showing
8 changed files
with
201 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright © 2017 Caleigh Runge-Hottman | ||
# | ||
# This file is part of Bodhi. | ||
# | ||
# This program is free software; you can redistribute it and/or | ||
# modify it under the terms of the GNU General Public License | ||
# as published by the Free Software Foundation; either version 2 | ||
# of the License, or (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program; if not, write to the Free Software | ||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
"""This script is responsible for moving all updates with a batched request to a stable request.""" | ||
|
||
import sys | ||
|
||
import click | ||
|
||
from bodhi.server import config, models, Session, initialize_db | ||
|
||
|
||
@click.command() | ||
@click.version_option(message='%(version)s') | ||
def dequeue_stable(): | ||
"""Convert all batched requests to stable requests.""" | ||
initialize_db(config.config) | ||
db = Session() | ||
|
||
try: | ||
batched = db.query(models.Update).filter_by(request=models.UpdateRequest.batched).all() | ||
for update in batched: | ||
update.set_request(db, models.UpdateRequest.stable, u'bodhi') | ||
db.commit() | ||
|
||
except Exception as e: | ||
print(str(e)) | ||
db.rollback() | ||
Session.remove() | ||
sys.exit(1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright © 2017 Caleigh Runge-Hottman | ||
# | ||
# This file is part of Bodhi. | ||
# | ||
# This program is free software; you can redistribute it and/or | ||
# modify it under the terms of the GNU General Public License | ||
# as published by the Free Software Foundation; either version 2 | ||
# of the License, or (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program; if not, write to the Free Software | ||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
""" | ||
This module contains tests for the bodhi.server.scripts.dequeue_stable module. | ||
""" | ||
from datetime import datetime, timedelta | ||
|
||
from click import testing | ||
|
||
from bodhi.server import models | ||
from bodhi.server.scripts import dequeue_stable | ||
from bodhi.tests.server.base import BaseTestCase | ||
|
||
|
||
class TestDequeueStable(BaseTestCase): | ||
""" | ||
This class contains tests for the dequeue_stable() function. | ||
""" | ||
def test_dequeue_stable(self): | ||
""" | ||
Assert that dequeue_stable moves only the batched updates to stable. | ||
""" | ||
runner = testing.CliRunner() | ||
|
||
update = self.db.query(models.Update).all()[0] | ||
update.request = models.UpdateRequest.batched | ||
update.locked = False | ||
update.date_testing = datetime.utcnow() - timedelta(days=7) | ||
self.db.commit() | ||
|
||
result = runner.invoke(dequeue_stable.dequeue_stable, []) | ||
self.assertEqual(result.exit_code, 0) | ||
|
||
update = self.db.query(models.Update).all()[0] | ||
self.assertEqual(update.request, models.UpdateRequest.stable) | ||
|
||
def test_dequeue_stable_exception(self): | ||
""" | ||
Assert that a locked update triggers an exception, and doesn't move to stable. | ||
""" | ||
runner = testing.CliRunner() | ||
update = self.db.query(models.Update).all()[0] | ||
update.request = models.UpdateRequest.batched | ||
self.db.commit() | ||
|
||
result = runner.invoke(dequeue_stable.dequeue_stable, []) | ||
|
||
self.assertEqual(result.exit_code, 1) | ||
self.assertEqual(result.output, u"Can't change the request on a locked update\n") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters