#425 Unit test for github_pr widget's should_invalidate()
Merged 6 years ago by abompard. Opened 6 years ago by anar.
anar/fedora-hubs UnitTests  into  develop

@@ -0,0 +1,64 @@ 

+ from __future__ import unicode_literals

+ 

+ from . import WidgetTest

+ 

+ 

+ class TestGithubPr(WidgetTest):

+ 

+     plugin = "github_pr"

+     initial_widget_config = {

+         "organization": "fedora-infra",

+         "display_number": 1,

+     }

+ 

+     def populate(self):

+         super(TestGithubPr, 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': 'org.fedoraproject.tests.github.pull_request.closed',

+             'msg': {

+                 'repository': {

+                                 'owner': {

+                                         'login': 'fedora-infra',

+                                 }

+                 },

+                 'display_number': 1,

+             }

+         }

+         self.assertTrue(self._get_should_invalidate_result(msg))

+         msg = {

+             'topic': 'org.fedoraproject.tests.github.pull_request.closed',

+             'msg': {

+                 'repository': {

+                                 'owner': {

+                                         'name': 'fedora-infra',

+                                 }

+                 },

+                 'display_number': 1,

+             }

+         }

+         self.assertTrue(self._get_should_invalidate_result(msg))

+ 

+     def test_should_invalidate_wrong_org(self):

+         msg = {

+             'topic': 'org.fedoraproject.tests.github.pull_request.closed',

+             'msg': {

+                 'repository': {

+                                 'owner': {

+                                         'login': 'not-fedora-infra',

+                                 }

+                 },

+                 'display_number': 1,

+             }

+         }

+         self.assertFalse(self._get_should_invalidate_result(msg))

Pull-Request has been merged by abompard

6 years ago
Metadata