File: test_base.py

package info (click to toggle)
pontos 25.8.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,744 kB
  • sloc: python: 44,602; makefile: 21; sh: 10; xml: 3
file content (218 lines) | stat: -rw-r--r-- 9,212 bytes parent folder | download | duplicates (2)
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
# SPDX-FileCopyrightText: 2022-2023 Greenbone AG
#
# SPDX-License-Identifier: GPL-3.0-or-later
#

# pylint: disable=line-too-long


import unittest

from pontos.github.api.teams import TeamPrivacy
from pontos.github.models.base import App, Permission, Team, User


class UserTestCase(unittest.TestCase):
    def test_from_dict(self):
        data = {
            "login": "greenbone",
            "id": 31986857,
            "node_id": "MDEyOk9yZ2FuaXphdGlvbjMxOTg2ODU3",
            "avatar_url": "https://avatars.githubusercontent.com/u/31986857?v=4",
            "gravatar_id": "",
            "url": "https://api.github.com/users/greenbone",
            "html_url": "https://github.com/greenbone",
            "followers_url": "https://api.github.com/users/greenbone/followers",
            "following_url": "https://api.github.com/users/greenbone/following{/other_user}",
            "gists_url": "https://api.github.com/users/greenbone/gists{/gist_id}",
            "starred_url": "https://api.github.com/users/greenbone/starred{/owner}{/repo}",
            "subscriptions_url": "https://api.github.com/users/greenbone/subscriptions",
            "organizations_url": "https://api.github.com/users/greenbone/orgs",
            "repos_url": "https://api.github.com/users/greenbone/repos",
            "events_url": "https://api.github.com/users/greenbone/events{/privacy}",
            "received_events_url": "https://api.github.com/users/greenbone/received_events",
            "type": "Organization",
            "site_admin": False,
        }

        user = User.from_dict(data)

        self.assertEqual(user.login, "greenbone")
        self.assertEqual(user.id, 31986857)
        self.assertEqual(user.node_id, "MDEyOk9yZ2FuaXphdGlvbjMxOTg2ODU3")
        self.assertEqual(user.gravatar_id, "")
        self.assertEqual(user.url, "https://api.github.com/users/greenbone")
        self.assertEqual(user.html_url, "https://github.com/greenbone")
        self.assertEqual(
            user.followers_url,
            "https://api.github.com/users/greenbone/followers",
        )
        self.assertEqual(
            user.following_url,
            "https://api.github.com/users/greenbone/following{/other_user}",
        )
        self.assertEqual(
            user.gists_url,
            "https://api.github.com/users/greenbone/gists{/gist_id}",
        )
        self.assertEqual(
            user.starred_url,
            "https://api.github.com/users/greenbone/starred{/owner}{/repo}",
        )
        self.assertEqual(
            user.subscriptions_url,
            "https://api.github.com/users/greenbone/subscriptions",
        )
        self.assertEqual(
            user.organizations_url,
            "https://api.github.com/users/greenbone/orgs",
        )
        self.assertEqual(
            user.repos_url, "https://api.github.com/users/greenbone/repos"
        )
        self.assertEqual(
            user.events_url,
            "https://api.github.com/users/greenbone/events{/privacy}",
        )
        self.assertEqual(
            user.received_events_url,
            "https://api.github.com/users/greenbone/received_events",
        )
        self.assertEqual(user.type, "Organization")
        self.assertFalse(user.site_admin)


class TeamTestCase(unittest.TestCase):
    def test_from_dict(self):
        data = {
            "name": "python-gvm-maintainers",
            "id": 3764115,
            "node_id": "MDQ6VGVhbTM3NjQxMTU=",
            "slug": "python-gvm-maintainers",
            "description": "Maintainers of python code at GVM",
            "privacy": "closed",
            "url": "https://api.github.com/organizations/31986857/team/3764115",
            "html_url": "https://github.com/orgs/greenbone/teams/python-gvm-maintainers",
            "members_url": "https://api.github.com/organizations/31986857/team/3764115/members{/member}",
            "repositories_url": "https://api.github.com/organizations/31986857/team/3764115/repos",
            "permission": "pull",
            "parent": None,
        }

        team = Team.from_dict(data)

        self.assertEqual(team.name, "python-gvm-maintainers")
        self.assertEqual(team.id, 3764115)
        self.assertEqual(team.node_id, "MDQ6VGVhbTM3NjQxMTU=")
        self.assertEqual(team.slug, "python-gvm-maintainers")
        self.assertEqual(team.description, "Maintainers of python code at GVM")
        self.assertEqual(team.privacy, TeamPrivacy.CLOSED)
        self.assertEqual(
            team.url,
            "https://api.github.com/organizations/31986857/team/3764115",
        )
        self.assertEqual(
            team.html_url,
            "https://github.com/orgs/greenbone/teams/python-gvm-maintainers",
        )
        self.assertEqual(
            team.members_url,
            "https://api.github.com/organizations/31986857/team/3764115/members{/member}",
        )
        self.assertEqual(
            team.repositories_url,
            "https://api.github.com/organizations/31986857/team/3764115/repos",
        )
        self.assertEqual(team.permission, Permission.PULL)
        self.assertIsNone(team.parent)


class AppTestCase(unittest.TestCase):
    def test_from_dict(self):
        data = {
            "id": 1,
            "slug": "octoapp",
            "node_id": "MDExOkludGVncmF0aW9uMQ==",
            "owner": {
                "login": "github",
                "id": 1,
                "node_id": "MDEyOk9yZ2FuaXphdGlvbjE=",
                "avatar_url": "https://github.com/images/error/octocat_happy.gif",
                "gravatar_id": "",
                "url": "https://api.github.com/orgs/github",
                "html_url": "https://github.com/github",
                "followers_url": "https://api.github.com/users/github/followers",
                "following_url": "https://api.github.com/users/github/following{/other_user}",
                "gists_url": "https://api.github.com/users/github/gists{/gist_id}",
                "starred_url": "https://api.github.com/users/github/starred{/owner}{/repo}",
                "subscriptions_url": "https://api.github.com/users/github/subscriptions",
                "organizations_url": "https://api.github.com/users/github/orgs",
                "repos_url": "https://api.github.com/orgs/github/repos",
                "events_url": "https://api.github.com/orgs/github/events",
                "received_events_url": "https://api.github.com/users/github/received_events",
                "type": "Organization",
                "site_admin": False,
            },
            "name": "Octocat App",
            "description": "",
            "external_url": "https://example.com",
            "html_url": "https://github.com/apps/octoapp",
            "created_at": "2017-07-08T16:18:44-04:00",
            "updated_at": "2017-07-08T16:18:44-04:00",
            "events": ["push", "pull_request"],
        }

        app = App.from_dict(data)

        self.assertEqual(app.id, 1)
        self.assertEqual(app.slug, "octoapp")
        self.assertEqual(app.node_id, "MDExOkludGVncmF0aW9uMQ==")
        self.assertEqual(app.owner.login, "github")
        self.assertEqual(app.owner.id, 1)
        self.assertEqual(app.owner.node_id, "MDEyOk9yZ2FuaXphdGlvbjE=")
        self.assertEqual(
            app.owner.avatar_url,
            "https://github.com/images/error/octocat_happy.gif",
        )
        self.assertEqual(app.owner.gravatar_id, "")
        self.assertEqual(app.owner.url, "https://api.github.com/orgs/github")
        self.assertEqual(app.owner.html_url, "https://github.com/github")
        self.assertEqual(
            app.owner.followers_url,
            "https://api.github.com/users/github/followers",
        )
        self.assertEqual(
            app.owner.following_url,
            "https://api.github.com/users/github/following{/other_user}",
        )
        self.assertEqual(
            app.owner.gists_url,
            "https://api.github.com/users/github/gists{/gist_id}",
        )
        self.assertEqual(
            app.owner.starred_url,
            "https://api.github.com/users/github/starred{/owner}{/repo}",
        )
        self.assertEqual(
            app.owner.subscriptions_url,
            "https://api.github.com/users/github/subscriptions",
        )
        self.assertEqual(
            app.owner.organizations_url,
            "https://api.github.com/users/github/orgs",
        )
        self.assertEqual(
            app.owner.repos_url, "https://api.github.com/orgs/github/repos"
        )
        self.assertEqual(
            app.owner.events_url, "https://api.github.com/orgs/github/events"
        )
        self.assertEqual(app.owner.type, "Organization")
        self.assertFalse(app.owner.site_admin)
        self.assertEqual(app.name, "Octocat App")
        self.assertEqual(app.description, "")
        self.assertEqual(app.external_url, "https://example.com")
        self.assertEqual(app.html_url, "https://github.com/apps/octoapp")
        self.assertEqual(app.created_at, "2017-07-08T16:18:44-04:00")
        self.assertEqual(app.updated_at, "2017-07-08T16:18:44-04:00")
        self.assertEqual(app.events, ["push", "pull_request"])