/ tests / Migration.py
Migration.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 2015 Christopher Wilcox <git@crwilcox.com>                         #
  8  # Copyright 2015 Dan Vanderkam <danvdk@gmail.com>                              #
  9  # Copyright 2015 Enix Yu <enix223@163.com>                                     #
 10  # Copyright 2015 Kyle Hornberg <khornberg@users.noreply.github.com>            #
 11  # Copyright 2015 Uriel Corfa <uriel@corfa.fr>                                  #
 12  # Copyright 2016 @tmshn <tmshn@r.recruit.co.jp>                                #
 13  # Copyright 2016 Enix Yu <enix223@163.com>                                     #
 14  # Copyright 2016 Jannis Gebauer <ja.geb@me.com>                                #
 15  # Copyright 2016 Jimmy Zelinskie <jimmyzelinskie@gmail.com>                    #
 16  # Copyright 2016 Peter Buckley <dx-pbuckley@users.noreply.github.com>          #
 17  # Copyright 2018 Hayden Fuss <wifu1234@gmail.com>                              #
 18  # Copyright 2018 Iraquitan Cordeiro Filho <iraquitanfilho@gmail.com>           #
 19  # Copyright 2018 Jacopo Notarstefano <jacopo.notarstefano@gmail.com>           #
 20  # Copyright 2018 Maarten Fonville <mfonville@users.noreply.github.com>         #
 21  # Copyright 2018 Mateusz Loskot <mateusz@loskot.net>                           #
 22  # Copyright 2018 Raihaan <31362124+res0nance@users.noreply.github.com>         #
 23  # Copyright 2018 Shinichi TAMURA <shnch.tmr@gmail.com>                         #
 24  # Copyright 2018 Steve Kowalik <steven@wedontsleep.org>                        #
 25  # Copyright 2018 Victor Granic <vmg@boreal321.com>                             #
 26  # Copyright 2018 Wan Liuyang <tsfdye@gmail.com>                                #
 27  # Copyright 2018 Will Yardley <wyardley@users.noreply.github.com>              #
 28  # Copyright 2018 sfdye <tsfdye@gmail.com>                                      #
 29  #                                                                              #
 30  # This file is part of PyGithub.                                               #
 31  # http://pygithub.readthedocs.io/                                              #
 32  #                                                                              #
 33  # PyGithub is free software: you can redistribute it and/or modify it under    #
 34  # the terms of the GNU Lesser General Public License as published by the Free  #
 35  # Software Foundation, either version 3 of the License, or (at your option)    #
 36  # any later version.                                                           #
 37  #                                                                              #
 38  # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY  #
 39  # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS    #
 40  # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more #
 41  # details.                                                                     #
 42  #                                                                              #
 43  # You should have received a copy of the GNU Lesser General Public License     #
 44  # along with PyGithub. If not, see <http://www.gnu.org/licenses/>.             #
 45  #                                                                              #
 46  ################################################################################
 47  
 48  from datetime import datetime
 49  
 50  from dateutil.tz.tz import tzoffset
 51  
 52  import github
 53  
 54  from . import Framework
 55  
 56  
 57  class Migration(Framework.TestCase):
 58      def setUp(self):
 59          super().setUp()
 60          self.user = self.g.get_user()
 61          self.migration = self.user.get_migrations()[0]
 62  
 63      def testAttributes(self):
 64          self.assertEqual(self.migration.id, 25320)
 65          self.assertEqual(self.migration.owner.login, "singh811")
 66          self.assertEqual(self.migration.guid, "608bceae-b790-11e8-8b43-4e3cb0dd56cc")
 67          self.assertEqual(self.migration.state, "exported")
 68          self.assertEqual(self.migration.lock_repositories, False)
 69          self.assertEqual(self.migration.exclude_attachments, False)
 70          self.assertEqual(len(self.migration.repositories), 1)
 71          self.assertEqual(self.migration.repositories[0].name, "sample-repo")
 72          self.assertEqual(self.migration.url, "https://api.github.com/user/migrations/25320")
 73          self.assertEqual(
 74              self.migration.created_at,
 75              datetime(2018, 9, 14, 1, 35, 35, tzinfo=tzoffset(None, 19800)),
 76          )
 77          self.assertEqual(
 78              self.migration.updated_at,
 79              datetime(2018, 9, 14, 1, 35, 46, tzinfo=tzoffset(None, 19800)),
 80          )
 81          self.assertEqual(
 82              repr(self.migration),
 83              'Migration(url="https://api.github.com/user/migrations/25320", state="exported")',
 84          )
 85  
 86      def testGetArchiveUrlWhenNotExported(self):
 87          self.assertRaises(github.UnknownObjectException, lambda: self.migration.get_archive_url())
 88  
 89      def testGetStatus(self):
 90          self.assertEqual(self.migration.get_status(), "exported")
 91  
 92      def testGetArchiveUrlWhenExported(self):
 93          self.assertEqual(
 94              self.migration.get_archive_url(),
 95              "https://github-cloud.s3.amazonaws.com/migration/25320/24575?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAISTNZFOVBIJMK3TQ%2F20180913%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20180913T201100Z&X-Amz-Expires=300&X-Amz-Signature=a0aeb638facd0c78c1ed3ca86022eddbee91e5fe1bb48ee830f54b8b7b305026&X-Amz-SignedHeaders=host&actor_id=41840111&response-content-disposition=filename%3D608bceae-b790-11e8-8b43-4e3cb0dd56cc.tar.gz&response-content-type=application%2Fx-gzip",
 96          )
 97  
 98      def testDelete(self):
 99          self.assertEqual(self.migration.delete(), None)
100  
101      def testGetArchiveUrlWhenDeleted(self):
102          self.assertRaises(github.UnknownObjectException, lambda: self.migration.get_archive_url())
103  
104      def testUnlockRepo(self):
105          self.assertEqual(self.migration.unlock_repo("sample-repo"), None)