/ tests / Hook.py
Hook.py
 1  ############################ Copyrights and license ############################
 2  #                                                                              #
 3  # Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net>                 #
 4  # Copyright 2012 Zearin <zearin@gonk.net>                                      #
 5  # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net>                 #
 6  # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net>                 #
 7  # Copyright 2016 Jannis Gebauer <ja.geb@me.com>                                #
 8  # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com>          #
 9  # Copyright 2017 Wan Liuyang <tsfdye@gmail.com>                                #
10  # Copyright 2018 sfdye <tsfdye@gmail.com>                                      #
11  #                                                                              #
12  # This file is part of PyGithub.                                               #
13  # http://pygithub.readthedocs.io/                                              #
14  #                                                                              #
15  # PyGithub is free software: you can redistribute it and/or modify it under    #
16  # the terms of the GNU Lesser General Public License as published by the Free  #
17  # Software Foundation, either version 3 of the License, or (at your option)    #
18  # any later version.                                                           #
19  #                                                                              #
20  # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY  #
21  # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS    #
22  # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more #
23  # details.                                                                     #
24  #                                                                              #
25  # You should have received a copy of the GNU Lesser General Public License     #
26  # along with PyGithub. If not, see <http://www.gnu.org/licenses/>.             #
27  #                                                                              #
28  ################################################################################
29  
30  from datetime import datetime, timezone
31  
32  from . import Framework
33  
34  
35  class Hook(Framework.TestCase):
36      def setUp(self):
37          super().setUp()
38          self.hook = self.g.get_user().get_repo("PyGithub").get_hook(257993)
39  
40      def testAttributes(self):
41          self.assertTrue(self.hook.active)  # WTF
42          self.assertEqual(self.hook.config, {"url": "http://foobar.com"})
43          self.assertEqual(
44              self.hook.created_at,
45              datetime(2012, 5, 19, 6, 1, 45, tzinfo=timezone.utc),
46          )
47          self.assertEqual(self.hook.events, ["push"])
48          self.assertEqual(self.hook.id, 257993)
49          self.assertEqual(self.hook.last_response.status, "ok")
50          self.assertEqual(self.hook.last_response.message, "OK")
51          self.assertEqual(self.hook.last_response.code, 200)
52          self.assertEqual(self.hook.name, "web")
53          self.assertEqual(
54              self.hook.updated_at,
55              datetime(2012, 5, 29, 18, 49, 47, tzinfo=timezone.utc),
56          )
57          self.assertEqual(self.hook.url, "https://api.github.com/repos/jacquev6/PyGithub/hooks/257993")
58          self.assertEqual(
59              self.hook.test_url,
60              "https://api.github.com/repos/jacquev6/PyGithub/hooks/257993/tests",
61          )
62          self.assertEqual(
63              self.hook.ping_url,
64              "https://api.github.com/repos/jacquev6/PyGithub/hooks/257993/pings",
65          )
66  
67          self.assertEqual(
68              repr(self.hook),
69              'Hook(url="https://api.github.com/repos/jacquev6/PyGithub/hooks/257993", id=257993)',
70          )
71          self.assertEqual(repr(self.hook.last_response), 'HookResponse(status="ok")')
72  
73      def testEditWithMinimalParameters(self):
74          self.hook.edit("web", {"url": "http://foobar.com/hook"})
75          self.assertEqual(self.hook.config, {"url": "http://foobar.com/hook"})
76          self.assertEqual(
77              self.hook.updated_at,
78              datetime(2012, 5, 19, 5, 8, 16, tzinfo=timezone.utc),
79          )
80  
81      def testDelete(self):
82          self.hook.delete()
83  
84      def testTest(self):
85          self.hook.test()  # This does not update attributes of hook
86  
87      def testPing(self):
88          self.hook.ping()  # This does not update attributes of hook
89  
90      def testEditWithAllParameters(self):
91          self.hook.edit("web", {"url": "http://foobar.com"}, events=["fork", "push"])
92          self.assertEqual(self.hook.events, ["fork", "push"])
93          self.hook.edit("web", {"url": "http://foobar.com"}, add_events=["push"])
94          self.assertEqual(self.hook.events, ["fork", "push"])
95          self.hook.edit("web", {"url": "http://foobar.com"}, remove_events=["fork"])
96          self.assertEqual(self.hook.events, ["push"])
97          self.hook.edit("web", {"url": "http://foobar.com"}, active=True)
98          self.assertTrue(self.hook.active)