Repository: fedora-infra/bodhi

Issue:
Waiving an update leaves its test_gating_status in a failed state
If a user waives failing tests on an update using the waive button, the update stays in a failed state until the next time the cron job runs. It would be more sensible to put it back into the "waiting on test results" state.


Discussion:
If we do #2370, this one should get solved as a side-effect.

Resolving patch:
diff --git a/bodhi/server/models.py b/bodhi/server/models.py
--- a/bodhi/server/models.py
+++ b/bodhi/server/models.py
@@ -2715,6 +2715,8 @@ def waive_test_results(self, username, comment=None, tests=None):
             bodhi.server.util.waiverdb_api_post(
                 '{}/waivers/'.format(config.get('waiverdb_api_url')), data)
 
+        self.test_gating_status = TestGatingStatus.waiting
+
     def add_tag(self, tag):
         """
         Add the given koji tag to all :class:`Builds <Build>` in this update.


Test patch:
diff --git a/bodhi/tests/server/services/test_updates.py b/bodhi/tests/server/services/test_updates.py
--- a/bodhi/tests/server/services/test_updates.py
+++ b/bodhi/tests/server/services/test_updates.py
@@ -5149,6 +5149,7 @@ def test_cannot_waive_test_results_on_locked_update(self, *args):
         nvr = u'bodhi-2.0-1.fc17'
 
         up = self.db.query(Update).filter_by(title=nvr).one()
+        up.test_gating_status = TestGatingStatus.failed
         up.locked = True
 
         post_data = dict(update=nvr,
@@ -5158,6 +5159,9 @@ def test_cannot_waive_test_results_on_locked_update(self, *args):
         self.assertEqual(res.json_body['status'], 'error')
         self.assertEqual(res.json_body[u'errors'][0][u'description'],
                          "Can't waive test results on a locked update")
+        up = self.db.query(Update).filter_by(title=nvr).one()
+        # The test gating status should not have been altered.
+        self.assertEqual(up.test_gating_status, TestGatingStatus.failed)
 
     def test_cannot_waive_test_results_when_test_gating_is_off(self, *args):
         """
@@ -5167,6 +5171,7 @@ def test_cannot_waive_test_results_when_test_gating_is_off(self, *args):
         nvr = u'bodhi-2.0-1.fc17'
 
         up = self.db.query(Update).filter_by(title=nvr).one()
+        up.test_gating_status = TestGatingStatus.failed
         up.locked = False
 
         post_data = dict(update=nvr,
@@ -5176,6 +5181,9 @@ def test_cannot_waive_test_results_when_test_gating_is_off(self, *args):
         self.assertEqual(res.json_body['status'], 'error')
         self.assertEqual(res.json_body[u'errors'][0][u'description'],
                          "Test gating is not enabled")
+        up = self.db.query(Update).filter_by(title=nvr).one()
+        # The test gating status should not have been altered.
+        self.assertEqual(up.test_gating_status, TestGatingStatus.failed)
 
     @mock.patch('bodhi.server.services.updates.Update.waive_test_results',
                 side_effect=IOError('IOError. oops!'))
@@ -5185,6 +5193,7 @@ def test_unexpected_exception(self, log_exception, waive_test_results, *args):
         nvr = u'bodhi-2.0-1.fc17'
 
         up = self.db.query(Update).filter_by(title=nvr).one()
+        up.test_gating_status = TestGatingStatus.failed
         up.locked = False
 
         post_data = dict(update=nvr, request='stable',
@@ -5195,6 +5204,9 @@ def test_unexpected_exception(self, log_exception, waive_test_results, *args):
         self.assertEqual(res.json_body['errors'][0]['description'],
                          u'IOError. oops!')
         log_exception.assert_called_once_with("Unhandled exception in waive_test_results")
+        up = self.db.query(Update).filter_by(title=nvr).one()
+        # The test gating status should not have been altered.
+        self.assertEqual(up.test_gating_status, TestGatingStatus.failed)
 
     @mock.patch.dict(config, [('test_gating.required', True)])
     @mock.patch('bodhi.server.util.waiverdb_api_post')
@@ -5255,6 +5267,10 @@ def test_waive_test_results_1_unsatisfied_requirement(
 
         self.assertEqual(list(res.json_body.keys()), ['update'])
         self.assertEqual(res.json_body['update'], up.__json__())
+        self.assertEqual(res.json_body['update']['test_gating_status'], 'waiting')
+        up = self.db.query(Update).filter_by(title=nvr).one()
+        # The test gating status should have been reset to waiting.
+        self.assertEqual(up.test_gating_status, TestGatingStatus.waiting)
 
     @mock.patch.dict(config, [('test_gating.required', True)])
     @mock.patch('bodhi.server.util.waiverdb_api_post')
@@ -5340,6 +5356,10 @@ def test_waive_test_results_2_unsatisfied_requirements(
 
         self.assertEqual(list(res.json_body.keys()), ['update'])
         self.assertEqual(res.json_body['update'], up.__json__())
+        self.assertEqual(res.json_body['update']['test_gating_status'], 'waiting')
+        up = self.db.query(Update).filter_by(title=nvr).one()
+        # The test gating status should have been reset to waiting.
+        self.assertEqual(up.test_gating_status, TestGatingStatus.waiting)
 
     @mock.patch.dict(config, [('test_gating.required', True)])
     @mock.patch('bodhi.server.util.waiverdb_api_post')
@@ -5413,6 +5433,10 @@ def test_waive_test_results_1_of_2_unsatisfied_requirements(
 
         self.assertEqual(list(res.json_body.keys()), ['update'])
         self.assertEqual(res.json_body['update'], up.__json__())
+        self.assertEqual(res.json_body['update']['test_gating_status'], 'waiting')
+        up = self.db.query(Update).filter_by(title=nvr).one()
+        # The test gating status should have been reset to waiting.
+        self.assertEqual(up.test_gating_status, TestGatingStatus.waiting)
 
     @mock.patch.dict(config, [('test_gating.required', True)])
     @mock.patch('bodhi.server.util.waiverdb_api_post')
@@ -5502,6 +5526,10 @@ def test_waive_test_results_2_of_2_unsatisfied_requirements(
 
         self.assertEqual(list(res.json_body.keys()), ['update'])
         self.assertEqual(res.json_body['update'], up.__json__())
+        self.assertEqual(res.json_body['update']['test_gating_status'], 'waiting')
+        up = self.db.query(Update).filter_by(title=nvr).one()
+        # The test gating status should have been updated to waiting.
+        self.assertEqual(up.test_gating_status, TestGatingStatus.waiting)
 
     @mock.patch.dict(config, [('test_gating.required', True)])
     @mock.patch('bodhi.server.util.waiverdb_api_post')
@@ -5575,6 +5603,10 @@ def test_waive_test_results_unfailing_tests(
 
         self.assertEqual(list(res.json_body.keys()), ['update'])
         self.assertEqual(res.json_body['update'], up.__json__())
+        self.assertEqual(res.json_body['update']['test_gating_status'], 'waiting')
+        up = self.db.query(Update).filter_by(title=nvr).one()
+        # The test gating status should not have been altered.
+        self.assertEqual(up.test_gating_status, TestGatingStatus.waiting)
 
 
 class TestGetTestResults(BaseTestCase):