From 27bbf857c2d46a49800bc5d4ed4c1e1143db8169 Mon Sep 17 00:00:00 2001 From: anar Date: Nov 02 2017 18:55:39 +0000 Subject: Unit test for github_pr widget's should_invalidate() --- diff --git a/hubs/tests/widgets/test_github_pr.py b/hubs/tests/widgets/test_github_pr.py new file mode 100644 index 0000000..ea175b0 --- /dev/null +++ b/hubs/tests/widgets/test_github_pr.py @@ -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))