diff --git a/master/buildbot/changes/filter.py b/master/buildbot/changes/filter.py index 6cc9011756b..230478246ec 100644 --- a/master/buildbot/changes/filter.py +++ b/master/buildbot/changes/filter.py @@ -83,7 +83,7 @@ def filter_change(self, change): return False for chg_attr, (filt_list, filt_re, filt_fn) in self.checks.items(): if chg_attr.startswith("prop:"): - chg_val = change.properties.get(chg_attr.split(":", 1)[1], '') + chg_val = change.properties.getProperty(chg_attr.split(":", 1)[1], '') else: chg_val = getattr(change, chg_attr, '') if filt_list is not None and chg_val not in filt_list: diff --git a/master/buildbot/test/fake/change.py b/master/buildbot/test/fake/change.py new file mode 100644 index 00000000000..2add14573fa --- /dev/null +++ b/master/buildbot/test/fake/change.py @@ -0,0 +1,34 @@ +# This file is part of Buildbot. Buildbot 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, version 2. +# +# 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. +# +# Copyright Buildbot Team Members + +from buildbot.process.properties import Properties +from buildbot.test.fake.state import State + + +class Change(State): + + project = '' + repository = '' + branch = '' + category = '' + codebase = '' + properties = {} + + def __init__(self, **kw): + State.__init__(self, **kw) + # change.properties is a IProperties + props = Properties() + props.update(self.properties, "test") + self.properties = props diff --git a/master/buildbot/test/unit/test_changes_filter.py b/master/buildbot/test/unit/test_changes_filter.py index 789ea628e75..1226013425d 100644 --- a/master/buildbot/test/unit/test_changes_filter.py +++ b/master/buildbot/test/unit/test_changes_filter.py @@ -18,15 +18,7 @@ from twisted.trial import unittest from buildbot.changes import filter -from buildbot.test.fake.state import State - - -class Change(State): - project = '' - repository = '' - branch = '' - category = '' - codebase = '' +from buildbot.test.fake.change import Change class ChangeFilter(unittest.TestCase): @@ -112,7 +104,7 @@ def test_filter_change_combination(self): self.no(Change(project='p', repository='r', branch='b', category='x'), "three match -> False") self.no(Change(project='p', repository='r', branch='b', category='c', - codebase='x'), "four match -> False") + codebase='x'), "four match -> False") self.yes(Change(project='p', repository='r', branch='b', category='c', codebase='cb'), "all match -> True") self.check() @@ -129,3 +121,14 @@ def test_filter_change_combination_filter_fn(self): self.yes(Change(project='p', repository='r', branch='b', category='c', ff=True), "all match and fn returns True -> False") self.check() + + def test_filter_props(self): + self.setfilter() + self.filt.checks.update( + self.filt.createChecks( + ("ref-updated", None, None, "prop:event.type"), + )) + self.yes(Change(properties={'event.type': 'ref-updated'}), "matching property") + self.no(Change(properties={'event.type': 'patch-uploaded'}), "non matching property") + self.no(Change(properties={}), "no property") + self.check() diff --git a/master/buildbot/test/unit/test_changes_gerritchangesource.py b/master/buildbot/test/unit/test_changes_gerritchangesource.py index 291fcbcf26d..c6a86b8e8fc 100644 --- a/master/buildbot/test/unit/test_changes_gerritchangesource.py +++ b/master/buildbot/test/unit/test_changes_gerritchangesource.py @@ -16,12 +16,14 @@ import types from buildbot.changes import gerritchangesource +from buildbot.test.fake.change import Change from buildbot.test.util import changesource from buildbot.util import json from twisted.trial import unittest class TestGerritHelpers(unittest.TestCase): + def test_proper_json(self): self.assertEqual(u"Justin Case ", gerritchangesource._gerrit_user_to_author({ @@ -210,12 +212,8 @@ def check(_): class TestGerritChangeFilter(unittest.TestCase): def test_basic(self): - class Change(object): - - def __init__(self, chdict): - self.__dict__ = chdict - ch = Change(TestGerritChangeSource.expected_change) + ch = Change(**TestGerritChangeSource.expected_change) f = gerritchangesource.GerritChangeFilter( branch=["br"], eventtype=["patchset-created"]) self.assertTrue(f.filter_change(ch))