From 20f07bf739b7d837d840a8a3dc8a33edbdcf4644 Mon Sep 17 00:00:00 2001 From: anar Date: Oct 26 2017 21:02:16 +0000 Subject: [PATCH 1/2] Implemented more accurate version of pagure_pr widget's should_invalidate() method --- diff --git a/hubs/widgets/pagure_pr/__init__.py b/hubs/widgets/pagure_pr/__init__.py index 4dc5562..f990f3b 100644 --- a/hubs/widgets/pagure_pr/__init__.py +++ b/hubs/widgets/pagure_pr/__init__.py @@ -72,9 +72,8 @@ class GetPRs(CachedFunction): ) def should_invalidate(self, message): - category = message["topic"].split('.')[3] - if category != "pagure": - # TODO -- this could be honed in more to just PRs + if (".pagure.pull-request.new" not in message["topic"] + or ".pagure.pull-request.closed" not in message["topic"]): return False try: project = message['msg']['project']['name'] From f852fb282e7217aaa224ec8f78289be75d9d2e70 Mon Sep 17 00:00:00 2001 From: anar Date: Oct 30 2017 07:54:36 +0000 Subject: [PATCH 2/2] Added pagure_pr unit test --- diff --git a/hubs/tests/widgets/test_pagure_pr.py b/hubs/tests/widgets/test_pagure_pr.py new file mode 100644 index 0000000..540a10e --- /dev/null +++ b/hubs/tests/widgets/test_pagure_pr.py @@ -0,0 +1,54 @@ +from __future__ import unicode_literals + +from . import WidgetTest + + +class TestPagurePr(WidgetTest): + + plugin = "pagure_pr" + initial_widget_config = { + "repo": "fedora-hubs", + } + + def populate(self): + super(TestPagurePr, self).populate() + self._add_widget_under_test() + + def _get_should_invalidate_result(self, msg): + func = self.widget.module.get_cached_functions()['GetPRs'] + return func(self.widget).should_invalidate(msg) + + def test_should_invalidate_wrong_topic(self): + msg = {'topic': 'hubs.widget.update.WRONG.TOPIC'} + self.assertFalse(self._get_should_invalidate_result(msg)) + + def test_should_invalidate_good_match(self): + msg = { + 'topic': 'tests.pagure.pull-request.new', + 'msg': { + "project": { + "name": "fedora-hubs", + }, + }, + } + self.assertTrue(self._get_should_invalidate_result(msg)) + msg = { + 'topic': 'tests.pagure.pull-request.closed', + 'msg': { + "project": { + "name": "fedora-hubs", + }, + }, + } + self.assertTrue(self._get_should_invalidate_result(msg)) + + def test_should_invalidate_wrong_repo(self): + msg = { + 'topic': 'tests.pagure.pull-request.new', + 'msg': { + "project": { + "name": "not-fedora-hubs", + }, + }, + } + self.assertFalse(self._get_should_invalidate_result(msg)) diff --git a/hubs/widgets/pagure_pr/__init__.py b/hubs/widgets/pagure_pr/__init__.py index f990f3b..6eee830 100644 --- a/hubs/widgets/pagure_pr/__init__.py +++ b/hubs/widgets/pagure_pr/__init__.py @@ -73,7 +73,7 @@ class GetPRs(CachedFunction): def should_invalidate(self, message): if (".pagure.pull-request.new" not in message["topic"] - or ".pagure.pull-request.closed" not in message["topic"]): + and ".pagure.pull-request.closed" not in message["topic"]): return False try: project = message['msg']['project']['name']