File: ExposeAllAttributes.py

package info (click to toggle)
pygithub 1.26.0-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 20,432 kB
  • ctags: 1,780
  • sloc: python: 10,689; makefile: 6
file content (160 lines) | stat: -rw-r--r-- 7,016 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# -*- coding: utf-8 -*-

# ########################## Copyrights and license ############################
#                                                                              #
# Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net>                 #
#                                                                              #
# This file is part of PyGithub. http://jacquev6.github.com/PyGithub/          #
#                                                                              #
# PyGithub is free software: you can redistribute it and/or modify it under    #
# the terms of the GNU Lesser General Public License as published by the Free  #
# Software Foundation, either version 3 of the License, or (at your option)    #
# any later version.                                                           #
#                                                                              #
# PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY  #
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS    #
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more #
# details.                                                                     #
#                                                                              #
# You should have received a copy of the GNU Lesser General Public License     #
# along with PyGithub. If not, see <http://www.gnu.org/licenses/>.             #
#                                                                              #
# ##############################################################################

import Framework


class ExposeAllAttributes(Framework.TestCase):
    def testAllClasses(self):
        authenticatedUser = self.g.get_user()
        namedUser = self.g.get_user("nvie")
        repository = authenticatedUser.get_repo("PyGithub")
        organization = self.g.get_organization("BeaverSoftware")
        plan = authenticatedUser.plan
        branch = repository.get_branch("master")
        commit = repository.get_commit("1292bf0e22c796e91cc3d6e24b544aece8c21f2a")
        commitStats = commit.stats
        commitStatus = commit.get_statuses()[0]
        milestone = repository.get_milestone(17)
        gist = self.g.get_gist("149016")
        gistComment = gist.get_comment(4565)
        gistFile = gist.files[".gitignore"]
        gistHistoryState = gist.history[0]
        gitCommit = repository.get_git_commit("be37b8a7f3a68631c32672dcd84d9eba27438ee6")
        gitAuthor = gitCommit.author
        gitTree = repository.get_git_tree("6f7c2d8c66d78863f7b91792deaead619799a1ce")
        gitTreeElement = gitTree.tree[0]
        gitBlob = repository.get_git_blob("681fb61f1761743a02f5c790f1c762cbfe8cfad1")
        gitRef = repository.get_git_ref("tags/v1.17.0")
        gitObject = gitRef.object
        issue = repository.get_issue(188)
        issueComment = issue.get_comment(22686536)
        issueEvent = issue.get_events()[0]
        issuePullRequest = issue.pull_request
        gitignoreTemplate = self.g.get_gitignore_template("Python")
        team = organization.get_team(141487)
        label = repository.get_label("Bug")
        pullRequest = repository.get_pull(31)
        pullRequestComment = pullRequest.get_review_comment(1580134)
        pullRequestPart = pullRequest.base
        file = pullRequest.get_files()[0]
        commitComment = repository.get_comment(3630301)
        status = self.g.get_api_status()
        statusMessage = self.g.get_last_api_status_message()
        rateLimit = self.g.get_rate_limit()
        rate = rateLimit.rate
        hook = repository.get_hooks()[0]
        hookResponse = hook.last_response
        hookDescription = self.g.get_hooks()[0]
        comparison = repository.compare("master", "develop")
        contentFile = repository.get_file_contents("README.rst")
        permissions = repository.permissions
        event = repository.get_events()[0]
        notification = authenticatedUser.get_notification("8406712")
        notificationSubject = notification.subject

        missingAttributes = self.gatherMissingAttributes([
            authenticatedUser,
            # authorization,  # Security issue if put as-is in ReplayData
            # authorizationApplication,  # Security issue if put as-is in ReplayData
            branch,
            commit,
            commitComment,
            commitStats,
            commitStatus,
            comparison,
            contentFile,
            # download,  # Deprecated: https://github.com/blog/1302-goodbye-uploads
            event,
            file,
            gist,
            gistComment,
            gistFile,
            gistHistoryState,
            gitAuthor,
            gitBlob,
            gitCommit,
            gitignoreTemplate,
            gitObject,
            gitRef,
            # gitTag,
            gitTree,
            gitTreeElement,
            hook,
            hookDescription,
            hookResponse,
            issue,
            issueComment,
            issueEvent,
            issuePullRequest,
            label,
            milestone,
            namedUser,
            notification,
            notificationSubject,
            organization,
            permissions,
            plan,
            pullRequest,
            pullRequestComment,
            # pullRequestMergeStatus,  # Only obtained when merging a pull request through the API
            pullRequestPart,
            rate,
            rateLimit,
            repository,
            # repositoryKey,  # Security issue if put as-is in ReplayData
            status,
            statusMessage,
            # tag,
            team,
            # userKey,  # Security issue if put as-is in ReplayData
        ])

        for className, attributesMissingInClass in sorted(missingAttributes.iteritems()):
            for attrName, value in sorted(attributesMissingInClass.iteritems()):
                print className, attrName, "->", repr(value)

        self.assertEqual(sum(len(attrs) for attrs in missingAttributes.values()), 0)

    def findMissingAttributes(self, obj):
        if hasattr(obj, "update"):
            obj.update()
        className = obj.__class__.__name__
        missingAttributes = {}
        for attribute in obj.raw_data:
            if attribute != "_links":
                if not hasattr(obj, attribute):
                    missingAttributes[attribute] = obj.raw_data[attribute]
        return (className, missingAttributes)

    def gatherMissingAttributes(self, objs):
        allMissingAttributes = dict()

        for obj in objs:
            className, attributesMissingInClass = self.findMissingAttributes(obj)
            if len(attributesMissingInClass) > 0:
                if className not in allMissingAttributes:
                    allMissingAttributes[className] = dict()
                allMissingAttributes[className].update(attributesMissingInClass)

        return allMissingAttributes