diff --git a/pagure/hooks/default.py b/pagure/hooks/default.py index bc1a8df..023f9b9 100644 --- a/pagure/hooks/default.py +++ b/pagure/hooks/default.py @@ -125,7 +125,7 @@ def send_webhook_notifications(project, topic, msg): def send_action_notification( session, subject, action, project, repodir, user, refname, rev ): - """ Send out-going notifications about the branch that was just deleted. + """ Send out-going notifications about the branch/tag. """ email = pagure.lib.git.get_author_email(rev, repodir) name = pagure.lib.git.get_author(rev, repodir) @@ -145,8 +145,10 @@ def send_action_notification( ) if subject == "branch": msg["branch"] = refname + msg["rev"] = rev elif subject == "tag": msg["tag"] = refname + msg["rev"] = rev # Send blink notification to any 3rd party plugins, if there are any pagure.lib.notify.blinker_publish(topic, msg) diff --git a/tests/test_pagure_send_notification.py b/tests/test_pagure_send_notification.py new file mode 100644 index 0000000..40b7b76 --- /dev/null +++ b/tests/test_pagure_send_notification.py @@ -0,0 +1,72 @@ +# -*- coding: utf-8 -*- + +""" + (c) 2019 - Copyright Red Hat Inc + + Authors: + Fabien Boucher + +""" + +import unittest +import sys +import os + +sys.path.insert( + 0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..") +) + +import mock +import pygit2 + +import pagure.hooks.default +import tests + + +class PagureHooksDefault(tests.SimplePagureTest): + """ Tests for pagure.hooks.default """ + + def setUp(self): + """ Set up the environnment, ran before every tests. """ + super(PagureHooksDefault, self).setUp() + tests.create_projects(self.session) + self.projects = tests.create_projects_git( + os.path.join(self.path, "repos"), bare=True) + self.folder = os.path.join(self.path, "repos", "test.git") + + def init_test_repo(self): + tests.add_content_git_repo(self.projects[0]) + repo = pygit2.Repository(self.projects[0]) + sha = repo.references["refs/heads/master"].peel().hex + project = pagure.lib.query.get_authorized_project( + self.session, "test") + return project, sha + + @mock.patch("pagure.hooks.default.send_fedmsg_notifications") + def test_send_action_notification( + self, fedmsg): + project, sha = self.init_test_repo() + pagure.hooks.default.send_action_notification( + self.session, "tag", "bar", + project, self.folder, "pingou", "master", sha) + (_, args, kwargs) = fedmsg.mock_calls[0] + self.assertEqual(args[1], 'git.tag.bar') + self.assertEqual(args[2]['repo']['name'], 'test') + self.assertEqual(args[2]['rev'], sha) + + @mock.patch("pagure.hooks.default.send_fedmsg_notifications") + def test_send_notifications( + self, fedmsg): + project, sha = self.init_test_repo() + pagure.hooks.default.send_notifications( + self.session, project, self.folder, + "pingou", "master", [sha], False) + (_, args, kwargs) = fedmsg.mock_calls[0] + self.assertEqual(args[1], 'git.receive') + self.assertEqual(args[2]['repo']['name'], 'test') + self.assertEqual(args[2]['start_commit'], sha) + self.assertEqual(args[2]['forced'], False) + + +if __name__ == "__main__": + unittest.main(verbosity=2)