#410 Addresses issue #353
Merged 6 years ago by abompard. Opened 6 years ago by anar.
anar/fedora-hubs PagurePr  into  develop

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

@@ -72,9 +72,8 @@ 

          )

  

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

+            and ".pagure.pull-request.closed" not in message["topic"]):

              return False

          try:

              project = message['msg']['project']['name']

Implemented more accurate version of pagure_pr widget's should_invalidate() method

1 new commit added

  • Added pagure_pr unit test
6 years ago

Pull-Request has been merged by abompard

6 years ago