/ tests / ExposeAllAttributes.py
ExposeAllAttributes.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 2018 sfdye <tsfdye@gmail.com>                                      #
  7  #                                                                              #
  8  # This file is part of PyGithub.                                               #
  9  # http://pygithub.readthedocs.io/                                              #
 10  #                                                                              #
 11  # PyGithub is free software: you can redistribute it and/or modify it under    #
 12  # the terms of the GNU Lesser General Public License as published by the Free  #
 13  # Software Foundation, either version 3 of the License, or (at your option)    #
 14  # any later version.                                                           #
 15  #                                                                              #
 16  # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY  #
 17  # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS    #
 18  # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more #
 19  # details.                                                                     #
 20  #                                                                              #
 21  # You should have received a copy of the GNU Lesser General Public License     #
 22  # along with PyGithub. If not, see <http://www.gnu.org/licenses/>.             #
 23  #                                                                              #
 24  ################################################################################
 25  
 26  from . import Framework
 27  
 28  
 29  class ExposeAllAttributes(Framework.TestCase):
 30      def testAllClasses(self):
 31          authenticatedUser = self.g.get_user()
 32          namedUser = self.g.get_user("nvie")
 33          repository = authenticatedUser.get_repo("PyGithub")
 34          organization = self.g.get_organization("BeaverSoftware")
 35          plan = authenticatedUser.plan
 36          branch = repository.get_branch("master")
 37          commit = repository.get_commit("1292bf0e22c796e91cc3d6e24b544aece8c21f2a")
 38          commitStats = commit.stats
 39          commitStatus = commit.get_statuses()[0]
 40          milestone = repository.get_milestone(17)
 41          gist = self.g.get_gist("149016")
 42          gistComment = gist.get_comment(4565)
 43          gistFile = gist.files[".gitignore"]
 44          gistHistoryState = gist.history[0]
 45          gitCommit = repository.get_git_commit("be37b8a7f3a68631c32672dcd84d9eba27438ee6")
 46          gitAuthor = gitCommit.author
 47          gitTree = repository.get_git_tree("6f7c2d8c66d78863f7b91792deaead619799a1ce")
 48          gitTreeElement = gitTree.tree[0]
 49          gitBlob = repository.get_git_blob("681fb61f1761743a02f5c790f1c762cbfe8cfad1")
 50          gitRef = repository.get_git_ref("tags/v1.17.0")
 51          gitObject = gitRef.object
 52          issue = repository.get_issue(188)
 53          issueComment = issue.get_comment(22686536)
 54          issueEvent = issue.get_events()[0]
 55          issuePullRequest = issue.pull_request
 56          gitignoreTemplate = self.g.get_gitignore_template("Python")
 57          team = organization.get_team(141487)
 58          label = repository.get_label("Bug")
 59          pullRequest = repository.get_pull(31)
 60          pullRequestComment = pullRequest.get_review_comment(1580134)
 61          pullRequestPart = pullRequest.base
 62          file = pullRequest.get_files()[0]
 63          commitComment = repository.get_comment(3630301)
 64          rateLimit = self.g.get_rate_limit()
 65          hook = repository.get_hooks()[0]
 66          hookResponse = hook.last_response
 67          hookDescription = self.g.get_hooks()[0]
 68          comparison = repository.compare("master", "develop")
 69          contentFile = repository.get_contents("README.rst")
 70          permissions = repository.permissions
 71          event = repository.get_events()[0]
 72          notification = authenticatedUser.get_notification("8406712")
 73          notificationSubject = notification.subject
 74  
 75          missingAttributes = self.gatherMissingAttributes(
 76              [
 77                  authenticatedUser,
 78                  # authorization,  # Security issue if put as-is in ReplayData
 79                  # authorizationApplication,  # Security issue if put as-is in ReplayData
 80                  branch,
 81                  commit,
 82                  commitComment,
 83                  commitStats,
 84                  commitStatus,
 85                  comparison,
 86                  contentFile,
 87                  # download,  # Deprecated: https://github.com/blog/1302-goodbye-uploads
 88                  event,
 89                  file,
 90                  gist,
 91                  gistComment,
 92                  gistFile,
 93                  gistHistoryState,
 94                  gitAuthor,
 95                  gitBlob,
 96                  gitCommit,
 97                  gitignoreTemplate,
 98                  gitObject,
 99                  gitRef,
100                  # gitTag,
101                  gitTree,
102                  gitTreeElement,
103                  hook,
104                  hookDescription,
105                  hookResponse,
106                  issue,
107                  issueComment,
108                  issueEvent,
109                  issuePullRequest,
110                  label,
111                  milestone,
112                  namedUser,
113                  notification,
114                  notificationSubject,
115                  organization,
116                  permissions,
117                  plan,
118                  pullRequest,
119                  pullRequestComment,
120                  # pullRequestMergeStatus,  # Only obtained when merging a pull request through the API
121                  pullRequestPart,
122                  rateLimit,
123                  repository,
124                  # repositoryKey,  # Security issue if put as-is in ReplayData
125                  # tag,
126                  team,
127                  # userKey,  # Security issue if put as-is in ReplayData
128              ]
129          )
130  
131          for className, attributesMissingInClass in sorted(missingAttributes.items()):
132              for attrName, value in sorted(attributesMissingInClass.items()):
133                  print(className, attrName, "->", repr(value))
134  
135          self.assertEqual(sum(len(attrs) for attrs in missingAttributes.values()), 0)
136  
137      def findMissingAttributes(self, obj):
138          if hasattr(obj, "update"):
139              obj.update()
140          className = obj.__class__.__name__
141          missingAttributes = {}
142          for attribute in obj.raw_data:
143              if attribute != "_links":
144                  if not hasattr(obj, attribute):
145                      missingAttributes[attribute] = obj.raw_data[attribute]
146          return (className, missingAttributes)
147  
148      def gatherMissingAttributes(self, objs):
149          allMissingAttributes = dict()
150  
151          for obj in objs:
152              className, attributesMissingInClass = self.findMissingAttributes(obj)
153              if len(attributesMissingInClass) > 0:
154                  if className not in allMissingAttributes:
155                      allMissingAttributes[className] = dict()
156                  allMissingAttributes[className].update(attributesMissingInClass)
157  
158          return allMissingAttributes