From 1cbc21d25851bf5652663a434d20a2c671c59e54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20=27sil2100=27=20Zemczak?= Date: Fri, 24 May 2019 16:18:34 +0200 Subject: [PATCH] SRU ADT regression: Fix state checking as now it again needs to include the info for distro and series. Add unit test. --- britney2/policies/sruadtregression.py | 2 +- tests/test_sruadtregression.py | 29 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/britney2/policies/sruadtregression.py b/britney2/policies/sruadtregression.py index fd23968..36b005d 100644 --- a/britney2/policies/sruadtregression.py +++ b/britney2/policies/sruadtregression.py @@ -71,7 +71,7 @@ class SRUADTRegressionPolicy(BasePolicy, Rest): distro_name = self.options.distribution series_name = self.options.series try: - if self.state[source_name] == version: + if self.state[distro_name][series_name][source_name] == version: # We already informed about the regression. return PolicyVerdict.PASS except KeyError: diff --git a/tests/test_sruadtregression.py b/tests/test_sruadtregression.py index 66af41c..254d7d8 100755 --- a/tests/test_sruadtregression.py +++ b/tests/test_sruadtregression.py @@ -256,6 +256,35 @@ class T(unittest.TestCase): lp.assert_not_called() smtp.sendmail.assert_not_called() + @patch('smtplib.SMTP') + @patch('britney2.policies.sruadtregression.SRUADTRegressionPolicy.bugs_from_changes', return_value={1, 2}) + @patch('britney2.policies.sruadtregression.SRUADTRegressionPolicy.query_lp_rest_api') + def test_no_comment_if_commented(self, lp, bugs_from_changes, smtp): + """Don't comment if package has been already commented on""" + with TemporaryDirectory() as tmpdir: + options = FakeOptions + options.unstable = tmpdir + pkg_mock = Mock() + pkg_mock.self_link = 'https://api.launchpad.net/1.0/ubuntu/+archive/primary/+sourcepub/9870565' + bugs_from_changes.return_value = {'entries': [pkg_mock]} + + previous_state = { + 'testbuntu': { + 'zazzy': { + 'testpackage': '55.0', + 'ignored': '0.1', + } + }, + } + pol = SRUADTRegressionPolicy(options, {}) + # Set a base state + pol.state = previous_state + status = pol.apply_policy_impl(None, None, 'testpackage', None, FakeSourceData, FakeExcuse) + self.assertEqual(status, PolicyVerdict.PASS) + bugs_from_changes.assert_not_called() + lp.assert_not_called() + smtp.sendmail.assert_not_called() + @patch('britney2.policies.sruadtregression.SRUADTRegressionPolicy.query_lp_rest_api') def test_initialize(self, lp): """Check state load, old package cleanup and LP login"""