SRU ADT regression: Fix state checking as now it again needs to include the info for distro and series. Add unit test.

master
Łukasz 'sil2100' Zemczak 5 years ago
parent 49e3d7e51c
commit 1cbc21d258

@ -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:

@ -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"""

Loading…
Cancel
Save