/ tests / Persistence.py
Persistence.py
 1  ############################ Copyrights and license ############################
 2  #                                                                              #
 3  # Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net>                 #
 4  # Copyright 2014 Vincent Jacques <vincent@vincent-jacques.net>                 #
 5  # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com>          #
 6  # Copyright 2017 Hugo <hugovk@users.noreply.github.com>                        #
 7  # Copyright 2018 sfdye <tsfdye@gmail.com>                                      #
 8  #                                                                              #
 9  # This file is part of PyGithub.                                               #
10  # http://pygithub.readthedocs.io/                                              #
11  #                                                                              #
12  # PyGithub is free software: you can redistribute it and/or modify it under    #
13  # the terms of the GNU Lesser General Public License as published by the Free  #
14  # Software Foundation, either version 3 of the License, or (at your option)    #
15  # any later version.                                                           #
16  #                                                                              #
17  # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY  #
18  # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS    #
19  # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more #
20  # details.                                                                     #
21  #                                                                              #
22  # You should have received a copy of the GNU Lesser General Public License     #
23  # along with PyGithub. If not, see <http://www.gnu.org/licenses/>.             #
24  #                                                                              #
25  ################################################################################
26  
27  from io import BytesIO as IO
28  
29  import github
30  
31  from . import Framework
32  
33  
34  class Persistence(Framework.TestCase):
35      def setUp(self):
36          super().setUp()
37          self.repo = self.g.get_repo("akfish/PyGithub")
38  
39          self.dumpedRepo = IO()
40          self.g.dump(self.repo, self.dumpedRepo)
41          self.dumpedRepo.seek(0)
42  
43      def tearDown(self):
44          self.dumpedRepo.close()
45          super().tearDown()
46  
47      def testLoad(self):
48          loadedRepo = self.g.load(self.dumpedRepo)
49          self.assertTrue(isinstance(loadedRepo, github.Repository.Repository))
50          self.assertTrue(loadedRepo._requester is self.repo._requester)
51          self.assertTrue(loadedRepo.owner._requester is self.repo._requester)
52          self.assertEqual(loadedRepo.name, "PyGithub")
53          self.assertEqual(loadedRepo.url, "https://api.github.com/repos/akfish/PyGithub")
54  
55      def testLoadAndUpdate(self):
56          loadedRepo = self.g.load(self.dumpedRepo)
57          self.assertTrue(loadedRepo.update())