/ tests / Authorization.py
Authorization.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 Peter Buckley <dx-pbuckley@users.noreply.github.com>          #
 8  # Copyright 2018 sfdye <tsfdye@gmail.com>                                      #
 9  #                                                                              #
10  # This file is part of PyGithub.                                               #
11  # http://pygithub.readthedocs.io/                                              #
12  #                                                                              #
13  # PyGithub is free software: you can redistribute it and/or modify it under    #
14  # the terms of the GNU Lesser General Public License as published by the Free  #
15  # Software Foundation, either version 3 of the License, or (at your option)    #
16  # any later version.                                                           #
17  #                                                                              #
18  # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY  #
19  # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS    #
20  # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more #
21  # details.                                                                     #
22  #                                                                              #
23  # You should have received a copy of the GNU Lesser General Public License     #
24  # along with PyGithub. If not, see <http://www.gnu.org/licenses/>.             #
25  #                                                                              #
26  ################################################################################
27  
28  from datetime import datetime, timezone
29  
30  from . import Framework
31  
32  
33  class Authorization(Framework.TestCase):
34      def setUp(self):
35          super().setUp()
36          self.authorization = self.g.get_user().get_authorization(372259)
37  
38      def testAttributes(self):
39          self.assertEqual(
40              self.authorization.app.url,
41              "http://developer.github.com/v3/oauth/#oauth-authorizations-api",
42          )
43          self.assertEqual(self.authorization.app.name, "GitHub API")
44          self.assertEqual(
45              self.authorization.created_at,
46              datetime(2012, 5, 22, 18, 3, 17, tzinfo=timezone.utc),
47          )
48          self.assertEqual(self.authorization.id, 372259)
49          self.assertEqual(self.authorization.note, None)
50          self.assertEqual(self.authorization.note_url, None)
51          self.assertEqual(self.authorization.scopes, [])
52          self.assertEqual(self.authorization.token, "82459c4500086f8f0cc67d2936c17d1e27ad1c33")
53          self.assertEqual(
54              self.authorization.updated_at,
55              datetime(2012, 5, 22, 18, 3, 17, tzinfo=timezone.utc),
56          )
57          self.assertEqual(self.authorization.url, "https://api.github.com/authorizations/372259")
58          self.assertEqual(repr(self.authorization), "Authorization(scopes=[])")
59          self.assertEqual(repr(self.authorization.app), 'AuthorizationApplication(name="GitHub API")')
60  
61      def testEdit(self):
62          self.authorization.edit()
63          self.assertEqual(self.authorization.scopes, [])
64          self.authorization.edit(scopes=["user"])
65          self.assertEqual(self.authorization.scopes, ["user"])
66          self.authorization.edit(add_scopes=["repo"])
67          self.assertEqual(self.authorization.scopes, ["user", "repo"])
68          self.authorization.edit(remove_scopes=["repo"])
69          self.assertEqual(self.authorization.scopes, ["user"])
70          self.assertEqual(self.authorization.note, None)
71          self.assertEqual(self.authorization.note_url, None)
72          self.authorization.edit(
73              note="Note created by PyGithub",
74              note_url="http://vincent-jacques.net/PyGithub",
75          )
76          self.assertEqual(self.authorization.note, "Note created by PyGithub")
77          self.assertEqual(self.authorization.note_url, "http://vincent-jacques.net/PyGithub")
78  
79      def testDelete(self):
80          self.authorization.delete()