Installation.py
1 ############################ Copyrights and license ############################ 2 # # 3 # Copyright 2023 Enrico Minack <github@enrico.minack.dev> # 4 # # 5 # This file is part of PyGithub. # 6 # http://pygithub.readthedocs.io/ # 7 # # 8 # PyGithub is free software: you can redistribute it and/or modify it under # 9 # the terms of the GNU Lesser General Public License as published by the Free # 10 # Software Foundation, either version 3 of the License, or (at your option) # 11 # any later version. # 12 # # 13 # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY # 14 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # 15 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more # 16 # details. # 17 # # 18 # You should have received a copy of the GNU Lesser General Public License # 19 # along with PyGithub. If not, see <http://www.gnu.org/licenses/>. # 20 # # 21 ################################################################################ 22 23 from urllib3.exceptions import InsecureRequestWarning 24 25 import github 26 from github import Consts 27 from github.Auth import AppAuth, AppInstallationAuth 28 29 from . import Framework, GithubIntegration 30 31 32 class Installation(Framework.BasicTestCase): 33 def setUp(self): 34 super().setUp() 35 app_id = 36541767 36 private_key = GithubIntegration.PRIVATE_KEY 37 self.auth = AppAuth(app_id, private_key) 38 self.integration = github.GithubIntegration(auth=self.auth) 39 self.installations = list(self.integration.get_installations()) 40 41 def testGetRepos(self): 42 self.assertEqual(len(self.installations), 1) 43 installation = self.installations[0] 44 45 repos = list(installation.get_repos()) 46 self.assertEqual(len(repos), 2) 47 self.assertListEqual([repo.full_name for repo in repos], ["EnricoMi/sandbox", "EnricoMi/python"]) 48 49 def testGetGithubForInstallation(self): 50 # with verify=False, urllib3.connectionpool rightly may issue an InsecureRequestWarning 51 # we ignore InsecureRequestWarning from urllib3.connectionpool 52 with self.ignoreWarning(category=InsecureRequestWarning, module="urllib3.connectionpool"): 53 kwargs = dict( 54 auth=AppAuth(319953, GithubIntegration.PRIVATE_KEY), 55 # http protocol used to deviate from default base url, recording data might require https 56 base_url="http://api.github.com", 57 timeout=Consts.DEFAULT_TIMEOUT + 10, 58 user_agent="PyGithub/Python-Test", 59 per_page=Consts.DEFAULT_PER_PAGE + 10, 60 verify=False, 61 retry=3, 62 pool_size=10, 63 seconds_between_requests=100, 64 seconds_between_writes=1000, 65 ) 66 67 # assert kwargs consists of ALL requester constructor arguments 68 self.assertEqual(kwargs.keys(), github.Requester.Requester.__init__.__annotations__.keys()) 69 70 self.integration = github.GithubIntegration(**kwargs) 71 installations = list(self.integration.get_installations()) 72 installation = installations[0] 73 74 g = installation.get_github_for_installation() 75 76 self.assertIsInstance(g._Github__requester.auth, AppInstallationAuth) 77 78 actual = g._Github__requester.kwargs 79 kwargs.update(auth=str(AppInstallationAuth)) 80 actual.update(auth=str(type(actual["auth"]))) 81 self.assertDictEqual(kwargs, actual) 82 83 repo = g.get_repo("PyGithub/PyGithub") 84 self.assertEqual(repo.full_name, "PyGithub/PyGithub")