/ tests / GithubApp.py
GithubApp.py
  1  ############################ Copyrights and license ############################
  2  #                                                                              #
  3  # Copyright 2020 Raju Subramanian <coder@mahesh.net>                           #
  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 datetime import datetime, timezone
 24  
 25  import github
 26  
 27  from . import Framework
 28  from .GithubIntegration import APP_ID, PRIVATE_KEY
 29  
 30  
 31  class GithubApp(Framework.TestCase):
 32      def setUp(self):
 33          super().setUp()
 34          self.app_slug = "github-actions"
 35  
 36      def testGetPublicApp(self):
 37          app = self.g.get_app(slug=self.app_slug)
 38          self.assertEqual(app.created_at, datetime(2018, 7, 30, 9, 30, 17, tzinfo=timezone.utc))
 39          self.assertEqual(app.description, "Automate your workflow from idea to production")
 40          self.assertListEqual(
 41              app.events,
 42              [
 43                  "check_run",
 44                  "check_suite",
 45                  "create",
 46                  "delete",
 47                  "deployment",
 48                  "deployment_status",
 49                  "fork",
 50                  "gollum",
 51                  "issues",
 52                  "issue_comment",
 53                  "label",
 54                  "milestone",
 55                  "page_build",
 56                  "project",
 57                  "project_card",
 58                  "project_column",
 59                  "public",
 60                  "pull_request",
 61                  "pull_request_review",
 62                  "pull_request_review_comment",
 63                  "push",
 64                  "registry_package",
 65                  "release",
 66                  "repository",
 67                  "repository_dispatch",
 68                  "status",
 69                  "watch",
 70                  "workflow_dispatch",
 71                  "workflow_run",
 72              ],
 73          )
 74          self.assertEqual(app.external_url, "https://help.github.com/en/actions")
 75          self.assertEqual(app.html_url, "https://github.com/apps/github-actions")
 76          self.assertEqual(app.id, 15368)
 77          self.assertEqual(app.name, "GitHub Actions")
 78          self.assertEqual(app.owner.login, "github")
 79          self.assertDictEqual(
 80              app.permissions,
 81              {
 82                  "actions": "write",
 83                  "checks": "write",
 84                  "contents": "write",
 85                  "deployments": "write",
 86                  "issues": "write",
 87                  "metadata": "read",
 88                  "packages": "write",
 89                  "pages": "write",
 90                  "pull_requests": "write",
 91                  "repository_hooks": "write",
 92                  "repository_projects": "write",
 93                  "security_events": "write",
 94                  "statuses": "write",
 95                  "vulnerability_alerts": "read",
 96              },
 97          )
 98          self.assertEqual(app.slug, "github-actions")
 99          self.assertEqual(app.updated_at, datetime(2019, 12, 10, 19, 4, 12, tzinfo=timezone.utc))
100          self.assertEqual(app.url, "/apps/github-actions")
101  
102      def testGetAuthenticatedApp(self):
103          auth = github.Auth.AppAuth(APP_ID, PRIVATE_KEY)
104          g = github.Github(auth=auth)
105  
106          with self.assertWarns(DeprecationWarning) as warning:
107              # httpretty has some deprecation warnings in Python 3.12
108              with self.ignoreWarning(category=DeprecationWarning, module="httpretty"):
109                  app = g.get_app()
110  
111              self.assertWarning(
112                  warning,
113                  "Argument slug is mandatory, calling this method without the slug argument is deprecated, "
114                  "please use github.GithubIntegration(auth=github.Auth.AppAuth(...)).get_app() instead",
115              )
116  
117          self.assertEqual(app.created_at, datetime(2020, 8, 1, 17, 23, 46, tzinfo=timezone.utc))
118          self.assertEqual(app.description, "Sample App to test PyGithub")
119          self.assertListEqual(
120              app.events,
121              ["check_run", "check_suite", "label", "member", "public"],
122          )
123          self.assertEqual(app.external_url, "https://pygithub.readthedocs.io")
124          self.assertEqual(app.html_url, "https://github.com/apps/pygithubtest")
125          self.assertEqual(app.id, 75269)
126          self.assertEqual(app.name, "PyGithubTest")
127          self.assertEqual(app.owner.login, "wrecker")
128          self.assertDictEqual(
129              app.permissions,
130              {
131                  "actions": "write",
132                  "checks": "write",
133                  "keys": "read",
134                  "members": "read",
135                  "metadata": "read",
136                  "packages": "read",
137                  "pages": "read",
138                  "repository_hooks": "write",
139                  "vulnerability_alerts": "read",
140                  "workflows": "write",
141              },
142          )
143          self.assertEqual(app.slug, "pygithubtest")
144          self.assertEqual(app.updated_at, datetime(2020, 8, 1, 17, 44, 31, tzinfo=timezone.utc))
145          self.assertEqual(app.url, "/apps/pygithubtest")