Skip to content

Commit

Permalink
Merge pull request #1557 from tardyp/changefilter_properties
Browse files Browse the repository at this point in the history
Changefilter properties
  • Loading branch information
Mikhail Sobolev committed Feb 26, 2015
2 parents 1989f8f + 0f04679 commit ca73251
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 16 deletions.
2 changes: 1 addition & 1 deletion master/buildbot/changes/filter.py
Expand Up @@ -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:
Expand Down
34 changes: 34 additions & 0 deletions 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
23 changes: 13 additions & 10 deletions master/buildbot/test/unit/test_changes_filter.py
Expand Up @@ -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):
Expand Down Expand Up @@ -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()
Expand All @@ -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()
8 changes: 3 additions & 5 deletions master/buildbot/test/unit/test_changes_gerritchangesource.py
Expand Up @@ -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 <justin.case@example.com>",
gerritchangesource._gerrit_user_to_author({
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit ca73251

Please sign in to comment.