| |
@@ -120,20 +120,6 @@
|
| |
# User does not exist, no feed instance should have been created.
|
| |
mock_notifications.assert_not_called()
|
| |
|
| |
- @patch("hubs.feed.fedmsg.meta.msg2usernames")
|
| |
- def test_get_hubs_for_msg(self, msg2usernames):
|
| |
- ralph = User.query.get("ralph")
|
| |
- infra = Hub.query.get("infra")
|
| |
- test_hub = Hub(name="testhub")
|
| |
- self.session.add(test_hub)
|
| |
- self.session.add(Association(hub=test_hub, user=ralph, role="member"))
|
| |
- self.session.add(Association(hub=infra, user=ralph, role="owner"))
|
| |
- msg2usernames.return_value = ["unknown_user", "ralph"]
|
| |
- self.assertListEqual(
|
| |
- sorted(get_hubs_for_msg({"msg_id": "testmsg"})),
|
| |
- ["infra", "ralph", "testhub"]
|
| |
- )
|
| |
-
|
| |
def test_add_dom_id(self):
|
| |
msg = {
|
| |
"msg_ids": {
|
| |
@@ -168,3 +154,204 @@
|
| |
result["markup_subjective"],
|
| |
"""your ticket was commented by <a href="/decause/">decause</a>"""
|
| |
)
|
| |
+
|
| |
+
|
| |
+ class GetHubsForMsgTestCase(APPTest):
|
| |
+
|
| |
+ # See: http://fedora-fedmsg.readthedocs.io/en/latest/topics.html
|
| |
+
|
| |
+ def setUp(self):
|
| |
+ super(GetHubsForMsgTestCase, self).setUp()
|
| |
+ self.msg2usernames_patcher = patch(
|
| |
+ "hubs.feed.fedmsg.meta.msg2usernames")
|
| |
+ self.msg2usernames = self.msg2usernames_patcher.start()
|
| |
+ self.msg2usernames.return_value = []
|
| |
+ self.dummy_msg = {"msg_id": "testmsg", "topic": "testtopic"}
|
| |
+
|
| |
+ def tearDown(self):
|
| |
+ self.msg2usernames_patcher.stop()
|
| |
+ super(GetHubsForMsgTestCase, self).tearDown()
|
| |
+
|
| |
+ def test_unknown_user(self):
|
| |
+ self.msg2usernames.return_value = ["unknown_user"]
|
| |
+ self.assertListEqual(get_hubs_for_msg(self.dummy_msg), [])
|
| |
+
|
| |
+ def test_user_hub_owner(self):
|
| |
+ self.msg2usernames.return_value = ["ralph"]
|
| |
+ self.assertListEqual(
|
| |
+ get_hubs_for_msg(self.dummy_msg), ["ralph"])
|
| |
+
|
| |
+ def test_group_hub_owner(self):
|
| |
+ # Don't send a message to a group hub just because the user is the
|
| |
+ # owner.
|
| |
+ ralph = User.query.get("ralph")
|
| |
+ infra = Hub.query.get("infra")
|
| |
+ self.session.add(Association(hub=infra, user=ralph, role="owner"))
|
| |
+ self.msg2usernames.return_value = ["ralph"]
|
| |
+ self.assertListEqual(
|
| |
+ get_hubs_for_msg(self.dummy_msg), ["ralph"])
|
| |
+
|
| |
+ def test_group_hub_member(self):
|
| |
+ ralph = User.query.get("ralph")
|
| |
+ test_hub = Hub(name="testhub", user_hub=False)
|
| |
+ self.session.add(test_hub)
|
| |
+ self.session.add(Association(hub=test_hub, user=ralph, role="member"))
|
| |
+ self.msg2usernames.return_value = ["ralph"]
|
| |
+ self.assertListEqual(
|
| |
+ get_hubs_for_msg(self.dummy_msg), ["ralph"])
|
| |
+
|
| |
+ def test_group_hub_irc(self):
|
| |
+ test_hub = Hub(name="testhub", user_hub=False)
|
| |
+ self.session.add(test_hub)
|
| |
+ test_hub.config["chat_network"] = "irc.freenode.net"
|
| |
+ test_hub.config["chat_channel"] = "testchannel"
|
| |
+ messages = [{
|
| |
+ "msg_id": "testmsg",
|
| |
+ "topic": "org.fedoraproject.prod.meetbot.meeting.start",
|
| |
+ "msg": {
|
| |
+ "channel": "testchannel",
|
| |
+ },
|
| |
+ }, {
|
| |
+ "msg_id": "testmsg",
|
| |
+ "topic": "org.fedoraproject.prod.meetbot.meeting.topic.update",
|
| |
+ "msg": {
|
| |
+ "channel": "testchannel",
|
| |
+ },
|
| |
+ }, {
|
| |
+ "msg_id": "testmsg",
|
| |
+ "topic": "org.fedoraproject.prod.meetbot.meeting.item.link",
|
| |
+ "msg": {
|
| |
+ "channel": "testchannel",
|
| |
+ },
|
| |
+ }, {
|
| |
+ "msg_id": "testmsg",
|
| |
+ "topic": "org.fedoraproject.prod.meetbot.meeting.item.help",
|
| |
+ "msg": {
|
| |
+ "channel": "testchannel",
|
| |
+ },
|
| |
+ }, {
|
| |
+ "msg_id": "testmsg",
|
| |
+ "topic": "org.fedoraproject.prod.meetbot.meeting.complete",
|
| |
+ "msg": {
|
| |
+ "channel": "testchannel",
|
| |
+ },
|
| |
+ }]
|
| |
+ for msg in messages:
|
| |
+ self.assertListEqual(get_hubs_for_msg(msg), ["testhub"])
|
| |
+
|
| |
+ def test_group_hub_mailinglist(self):
|
| |
+ test_hub = Hub(name="testhub", user_hub=False)
|
| |
+ self.session.add(test_hub)
|
| |
+ test_hub.config["mailing_list"] = "testlist@lists.fpo"
|
| |
+ msg = {
|
| |
+ "msg_id": "testmsg",
|
| |
+ "topic": "org.fedoraproject.prod.mailman.receive",
|
| |
+ "msg": {
|
| |
+ "mlist": {"list_name": "testlist"},
|
| |
+ },
|
| |
+ }
|
| |
+ self.assertListEqual(get_hubs_for_msg(msg), ["testhub"])
|
| |
+
|
| |
+ def test_group_hub_calendar(self):
|
| |
+ test_hub = Hub(name="testhub", user_hub=False)
|
| |
+ self.session.add(test_hub)
|
| |
+ test_hub.config["calendar"] = "testcal"
|
| |
+ topics = [
|
| |
+ "calendar.clear", "calendar.delete", "calendar.new",
|
| |
+ "calendar.update", "calendar.upload", "meeting.delete",
|
| |
+ "meeting.new", "meeting.reminder", "meeting.update",
|
| |
+ ]
|
| |
+ for topic in topics:
|
| |
+ msg = {
|
| |
+ "msg_id": "testmsg",
|
| |
+ "topic": "org.fedoraproject.prod.fedocal.{}".format(topic),
|
| |
+ "msg": {
|
| |
+ "calendar": {"calendar_name": "testcal"},
|
| |
+ },
|
| |
+ }
|
| |
+ self.assertListEqual(get_hubs_for_msg(msg), ["testhub"])
|
| |
+
|
| |
+ def test_group_hub_pagure(self):
|
| |
+ test_hub = Hub(name="testhub", user_hub=False)
|
| |
+ self.session.add(test_hub)
|
| |
+ projects_ok = [
|
| |
+ "testproject-1",
|
| |
+ "testproject-2",
|
| |
+ "namespace/testproject-3",
|
| |
+ ]
|
| |
+ projects_fail = [
|
| |
+ "testproject-3",
|
| |
+ "testproject-4",
|
| |
+ "namespace/testproject-1",
|
| |
+ ]
|
| |
+ test_hub.config["pagure"] = projects_ok
|
| |
+
|
| |
+ def _do_test_project(project, expected):
|
| |
+ msg = {
|
| |
+ "msg_id": "testmsg",
|
| |
+ "topic": "io.pagure.prod.pagure.commit.flag.added",
|
| |
+ "msg": {
|
| |
+ "repo": {"fullname": project},
|
| |
+ },
|
| |
+ }
|
| |
+ self.assertListEqual(get_hubs_for_msg(msg), expected)
|
| |
+ msg = {
|
| |
+ "msg_id": "testmsg",
|
| |
+ "topic": "io.pagure.prod.pagure.issue.assigned.added",
|
| |
+ "msg": {
|
| |
+ "project": {"fullname": project},
|
| |
+ },
|
| |
+ }
|
| |
+ self.assertListEqual(get_hubs_for_msg(msg), expected)
|
| |
+ msg = {
|
| |
+ "msg_id": "testmsg",
|
| |
+ "topic": "io.pagure.prod.pagure.pull-request.closed",
|
| |
+ "msg": {
|
| |
+ "pullrequest": {"project": {"fullname": project}},
|
| |
+ },
|
| |
+ }
|
| |
+ self.assertListEqual(get_hubs_for_msg(msg), expected)
|
| |
+ for project in projects_ok:
|
| |
+ _do_test_project(project, ["testhub"])
|
| |
+ for project in projects_fail:
|
| |
+ _do_test_project(project, [])
|
| |
+ # Handle new and/or differently formatted messages
|
| |
+ msg = {
|
| |
+ "msg_id": "testmsg",
|
| |
+ "topic": "io.pagure.prod.pagure.dummy",
|
| |
+ "msg": {},
|
| |
+ }
|
| |
+ self.assertListEqual(get_hubs_for_msg(msg), [])
|
| |
+
|
| |
+ def test_group_hub_github(self):
|
| |
+ test_hub = Hub(name="testhub", user_hub=False)
|
| |
+ self.session.add(test_hub)
|
| |
+ projects_ok = [
|
| |
+ "testgroup/testproject-1",
|
| |
+ "testgroup/testproject-2",
|
| |
+ ]
|
| |
+ projects_fail = [
|
| |
+ "testgroup/testproject-3",
|
| |
+ "othergroup/testproject-1",
|
| |
+ ]
|
| |
+ test_hub.config["github"] = projects_ok
|
| |
+
|
| |
+ def _do_test_project(project, expected):
|
| |
+ msg = {
|
| |
+ "msg_id": "testmsg",
|
| |
+ "topic": "org.fedoraproject.prod.github.commit_comment",
|
| |
+ "msg": {
|
| |
+ "repository": {"full_name": project},
|
| |
+ },
|
| |
+ }
|
| |
+ self.assertListEqual(get_hubs_for_msg(msg), expected)
|
| |
+ for project in projects_ok:
|
| |
+ _do_test_project(project, ["testhub"])
|
| |
+ for project in projects_fail:
|
| |
+ _do_test_project(project, [])
|
| |
+ msg = {
|
| |
+ "msg_id": "testmsg",
|
| |
+ "topic": "org.fedoraproject.prod.github.webhook",
|
| |
+ "msg": {},
|
| |
+ }
|
| |
+ self.assertListEqual(get_hubs_for_msg(msg), [])
|
| |
Fixes #488
Once again, it'll be easier to look at the commits one at a time.