From ca4320c1e0b3c549dcc8889ad56aec2ceb3928a3 Mon Sep 17 00:00:00 2001 From: Randy Barlow Date: Wed, 20 Dec 2017 15:32:04 -0500 Subject: [PATCH] bodhi-check-policies now also operates on pushed updates. fixes #2085 Signed-off-by: Randy Barlow --- bodhi/server/scripts/check_policies.py | 6 ++-- .../server/scripts/test_check_policies.py | 31 +++++++++++++++++++ 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/bodhi/server/scripts/check_policies.py b/bodhi/server/scripts/check_policies.py index 085fede325..15e78fc3c5 100644 --- a/bodhi/server/scripts/check_policies.py +++ b/bodhi/server/scripts/check_policies.py @@ -24,7 +24,6 @@ messages in the message bus yet. """ import click -from sqlalchemy.sql.expression import false from bodhi.server import config, initialize_db, models, Session from bodhi.server.util import greenwave_api_post @@ -37,9 +36,8 @@ def check(): initialize_db(config.config) session = Session() - updates = models.Update.query.filter(models.Update.pushed == false())\ - .filter(models.Update.status.in_( - [models.UpdateStatus.pending, models.UpdateStatus.testing])) + updates = models.Update.query.filter(models.Update.status.in_( + [models.UpdateStatus.pending, models.UpdateStatus.testing])) for update in updates: # We retrieve updates going to testing (status=pending) and updates # (status=testing) going to stable. diff --git a/bodhi/tests/server/scripts/test_check_policies.py b/bodhi/tests/server/scripts/test_check_policies.py index 6e5d1a9d9d..1da0fe631c 100644 --- a/bodhi/tests/server/scripts/test_check_policies.py +++ b/bodhi/tests/server/scripts/test_check_policies.py @@ -151,6 +151,37 @@ def test_no_policies_enforced(self): mock_greenwave.assert_called_once_with(config['greenwave_api_url'] + '/decision', expected_query) + @patch.dict(config, [('greenwave_api_url', 'http://domain.local')]) + def test_pushed_update(self): + """Assert that check() operates on pushed updates.""" + runner = testing.CliRunner() + update = self.db.query(models.Update).all()[0] + update.status = models.UpdateStatus.testing + update.pushed = True + self.db.commit() + with patch('bodhi.server.scripts.check_policies.greenwave_api_post') as mock_greenwave: + greenwave_response = { + 'policies_satisfied': False, + 'summary': 'it broke', + 'applicable_policies': ['bodhi-unrestricted'], + } + mock_greenwave.return_value = greenwave_response + + result = runner.invoke(check_policies.check, []) + + self.assertEqual(result.exit_code, 0) + update = self.db.query(models.Update).filter(models.Update.id == update.id).one() + self.assertEqual(update.test_gating_status, models.TestGatingStatus.failed) + self.assertEqual(update.greenwave_summary_string, 'it broke') + expected_query = { + 'product_version': 'fedora-17', 'decision_context': 'bodhi_update_push_stable', + 'subject': [{'item': u'bodhi-2.0-1.fc17', 'type': 'koji_build'}, + {'original_spec_nvr': u'bodhi-2.0-1.fc17'}, + {'item': u'FEDORA-{}-a3bbe1a8f2'.format(datetime.datetime.utcnow().year), + 'type': 'bodhi_update'}]} + mock_greenwave.assert_called_once_with(config['greenwave_api_url'] + '/decision', + expected_query) + @patch.dict(config, [('greenwave_api_url', 'http://domain.local')]) def test_unrestricted_policy(self): """Assert correct behavior when an unrestricted policy is applied"""