/ tests / RepositoryKey.py
RepositoryKey.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 Simon <spam@esemi.ru>                                         #
10  # Copyright 2018 Laurent Raufaste <analogue@glop.org>                          #
11  # Copyright 2018 Wan Liuyang <tsfdye@gmail.com>                                #
12  # Copyright 2018 sfdye <tsfdye@gmail.com>                                      #
13  #                                                                              #
14  # This file is part of PyGithub.                                               #
15  # http://pygithub.readthedocs.io/                                              #
16  #                                                                              #
17  # PyGithub is free software: you can redistribute it and/or modify it under    #
18  # the terms of the GNU Lesser General Public License as published by the Free  #
19  # Software Foundation, either version 3 of the License, or (at your option)    #
20  # any later version.                                                           #
21  #                                                                              #
22  # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY  #
23  # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS    #
24  # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more #
25  # details.                                                                     #
26  #                                                                              #
27  # You should have received a copy of the GNU Lesser General Public License     #
28  # along with PyGithub. If not, see <http://www.gnu.org/licenses/>.             #
29  #                                                                              #
30  ################################################################################
31  
32  from datetime import datetime, timezone
33  
34  from . import Framework
35  
36  
37  class RepositoryKey(Framework.TestCase):
38      def setUp(self):
39          super().setUp()
40          # When recording test, be sure to create a deploy key for yourself on
41          # Github and update it here.
42          self.key = self.g.get_user("lra").get_repo("mackup").get_key(21870881)
43  
44      def testAttributes(self):
45          self.assertEqual(self.key.id, 21870881)
46          self.assertEqual(
47              self.key.key,
48              "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDLOoLSVPwG1OSgVSeEXNbfIofYdxR5zs3u4PryhnamfFPYwi2vZW3ZxeI1oRcDh2VEdwGvlN5VUduKJNoOWMVzV2jSyR8CeDHH+I0soQCC7kfJVodU96HcPMzZ6MuVwSfD4BFGvKMXyCnBUqzo28BGHFwVQG8Ya9gL6/cTbuWywgM4xaJgMHv1OVcESXBtBkrqOneTJuOgeEmP0RfUnIAK/3/wbg9mfiBq7JV4cmWAg1xNE8GJoAbci59Tdx1dQgVuuqdQGk5jzNusOVneyMtGEB+p7UpPLJsGBW29rsMt7ITUbXM/kl9v11vPtWb+oOUThoFsDYmsWy7fGGP9YAFB",
49          )
50          self.assertEqual(self.key.title, "PyGithub Test Key")
51          self.assertEqual(self.key.url, "https://api.github.com/repos/lra/mackup/keys/21870881")
52          self.assertEqual(
53              self.key.created_at,
54              datetime(2017, 2, 22, 8, 16, 23, tzinfo=timezone.utc),
55          )
56          self.assertTrue(self.key.verified)
57          self.assertTrue(self.key.read_only)
58          self.assertEqual(repr(self.key), 'RepositoryKey(title="PyGithub Test Key", id=21870881)')
59  
60      def testDelete(self):
61          self.key.delete()