File: test_organization.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 (444 lines) | stat: -rw-r--r-- 19,274 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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
# SPDX-FileCopyrightText: 2022-2023 Greenbone AG
#
# SPDX-License-Identifier: GPL-3.0-or-later
#

# pylint: disable=line-too-long, redefined-builtin
# ruff: noqa: E501

import unittest
from datetime import datetime, timezone

from pontos.github.models.organization import License, Repository


class LicenseTestCase(unittest.TestCase):
    def test_from_dict(self):
        data = {
            "key": "gpl-3.0",
            "name": "GNU General Public License v3.0",
            "spdx_id": "GPL-3.0",
            "url": "https://api.github.com/licenses/gpl-3.0",
            "node_id": "MDc6TGljZW5zZTk=",
        }

        license = License.from_dict(data)

        self.assertEqual(license.key, "gpl-3.0")
        self.assertEqual(license.name, "GNU General Public License v3.0")
        self.assertEqual(license.spdx_id, "GPL-3.0")
        self.assertEqual(license.url, "https://api.github.com/licenses/gpl-3.0")
        self.assertEqual(license.node_id, "MDc6TGljZW5zZTk=")


class RepositoryTestCase(unittest.TestCase):
    def test_from_dict(self):
        data = {
            "id": 103647077,
            "node_id": "MDEwOlJlcG9zaXRvcnkxMDM2NDcwNzc=",
            "name": "gvm-tools",
            "full_name": "greenbone/gvm-tools",
            "private": False,
            "owner": {
                "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,
            },
            "html_url": "https://github.com/greenbone/gvm-tools",
            "description": "Remote control your Greenbone Community Edition or Greenbone Enterprise Appliance",
            "fork": False,
            "url": "https://api.github.com/repos/greenbone/gvm-tools",
            "forks_url": "https://api.github.com/repos/greenbone/gvm-tools/forks",
            "keys_url": "https://api.github.com/repos/greenbone/gvm-tools/keys{/key_id}",
            "collaborators_url": "https://api.github.com/repos/greenbone/gvm-tools/collaborators{/collaborator}",
            "teams_url": "https://api.github.com/repos/greenbone/gvm-tools/teams",
            "hooks_url": "https://api.github.com/repos/greenbone/gvm-tools/hooks",
            "issue_events_url": "https://api.github.com/repos/greenbone/gvm-tools/issues/events{/number}",
            "events_url": "https://api.github.com/repos/greenbone/gvm-tools/events",
            "assignees_url": "https://api.github.com/repos/greenbone/gvm-tools/assignees{/user}",
            "branches_url": "https://api.github.com/repos/greenbone/gvm-tools/branches{/branch}",
            "tags_url": "https://api.github.com/repos/greenbone/gvm-tools/tags",
            "blobs_url": "https://api.github.com/repos/greenbone/gvm-tools/git/blobs{/sha}",
            "git_tags_url": "https://api.github.com/repos/greenbone/gvm-tools/git/tags{/sha}",
            "git_refs_url": "https://api.github.com/repos/greenbone/gvm-tools/git/refs{/sha}",
            "trees_url": "https://api.github.com/repos/greenbone/gvm-tools/git/trees{/sha}",
            "statuses_url": "https://api.github.com/repos/greenbone/gvm-tools/statuses/{sha}",
            "languages_url": "https://api.github.com/repos/greenbone/gvm-tools/languages",
            "stargazers_url": "https://api.github.com/repos/greenbone/gvm-tools/stargazers",
            "contributors_url": "https://api.github.com/repos/greenbone/gvm-tools/contributors",
            "subscribers_url": "https://api.github.com/repos/greenbone/gvm-tools/subscribers",
            "subscription_url": "https://api.github.com/repos/greenbone/gvm-tools/subscription",
            "commits_url": "https://api.github.com/repos/greenbone/gvm-tools/commits{/sha}",
            "git_commits_url": "https://api.github.com/repos/greenbone/gvm-tools/git/commits{/sha}",
            "comments_url": "https://api.github.com/repos/greenbone/gvm-tools/comments{/number}",
            "issue_comment_url": "https://api.github.com/repos/greenbone/gvm-tools/issues/comments{/number}",
            "contents_url": "https://api.github.com/repos/greenbone/gvm-tools/contents/{+path}",
            "compare_url": "https://api.github.com/repos/greenbone/gvm-tools/compare/{base}...{head}",
            "merges_url": "https://api.github.com/repos/greenbone/gvm-tools/merges",
            "archive_url": "https://api.github.com/repos/greenbone/gvm-tools/{archive_format}{/ref}",
            "downloads_url": "https://api.github.com/repos/greenbone/gvm-tools/downloads",
            "issues_url": "https://api.github.com/repos/greenbone/gvm-tools/issues{/number}",
            "pulls_url": "https://api.github.com/repos/greenbone/gvm-tools/pulls{/number}",
            "milestones_url": "https://api.github.com/repos/greenbone/gvm-tools/milestones{/number}",
            "notifications_url": "https://api.github.com/repos/greenbone/gvm-tools/notifications{?since,all,participating}",
            "labels_url": "https://api.github.com/repos/greenbone/gvm-tools/labels{/name}",
            "releases_url": "https://api.github.com/repos/greenbone/gvm-tools/releases{/id}",
            "deployments_url": "https://api.github.com/repos/greenbone/gvm-tools/deployments",
            "created_at": "2017-09-15T10:54:42Z",
            "updated_at": "2022-11-01T07:45:33Z",
            "pushed_at": "2022-11-07T09:21:30Z",
            "git_url": "git://github.com/greenbone/gvm-tools.git",
            "ssh_url": "git@github.com:greenbone/gvm-tools.git",
            "clone_url": "https://github.com/greenbone/gvm-tools.git",
            "svn_url": "https://github.com/greenbone/gvm-tools",
            "homepage": "https://greenbone.github.io/gvm-tools/",
            "size": 3461,
            "stargazers_count": 128,
            "watchers_count": 128,
            "language": "Python",
            "has_issues": True,
            "has_projects": False,
            "has_downloads": True,
            "has_wiki": True,
            "has_pages": True,
            "has_discussions": False,
            "forks_count": 74,
            "mirror_url": None,
            "archived": False,
            "disabled": False,
            "open_issues_count": 3,
            "license": {
                "key": "gpl-3.0",
                "name": "GNU General Public License v3.0",
                "spdx_id": "GPL-3.0",
                "url": "https://api.github.com/licenses/gpl-3.0",
                "node_id": "MDc6TGljZW5zZTk=",
            },
            "allow_forking": True,
            "is_template": False,
            "web_commit_signoff_required": False,
            "topics": [
                "gmp",
                "gmp-scripts",
                "greenbone",
                "greenbone-vulnerability-manager",
                "gvm",
                "gvm-cli",
                "gvm-pyshell",
                "gvm-script",
                "omp",
                "openvas",
                "openvas-cli",
                "osp",
                "python",
                "vulnerability",
                "vulnerability-assessment",
                "vulnerability-management",
            ],
            "visibility": "public",
            "forks": 74,
            "open_issues": 3,
            "watchers": 128,
            "default_branch": "main",
        }

        repo = Repository.from_dict(data)

        self.assertEqual(repo.id, 103647077)
        self.assertEqual(repo.node_id, "MDEwOlJlcG9zaXRvcnkxMDM2NDcwNzc=")
        self.assertEqual(repo.name, "gvm-tools")
        self.assertEqual(repo.full_name, "greenbone/gvm-tools")
        self.assertEqual(repo.private, False)
        self.assertEqual(repo.owner.login, "greenbone")
        self.assertEqual(repo.owner.id, 31986857)
        self.assertEqual(repo.owner.node_id, "MDEyOk9yZ2FuaXphdGlvbjMxOTg2ODU3")
        self.assertEqual(
            repo.owner.avatar_url,
            "https://avatars.githubusercontent.com/u/31986857?v=4",
        )
        self.assertEqual(repo.owner.gravatar_id, "")
        self.assertEqual(
            repo.owner.url, "https://api.github.com/users/greenbone"
        )
        self.assertEqual(repo.owner.html_url, "https://github.com/greenbone")
        self.assertEqual(
            repo.owner.followers_url,
            "https://api.github.com/users/greenbone/followers",
        )
        self.assertEqual(
            repo.owner.following_url,
            "https://api.github.com/users/greenbone/following{/other_user}",
        )
        self.assertEqual(
            repo.owner.gists_url,
            "https://api.github.com/users/greenbone/gists{/gist_id}",
        )
        self.assertEqual(
            repo.owner.starred_url,
            "https://api.github.com/users/greenbone/starred{/owner}{/repo}",
        )
        self.assertEqual(
            repo.owner.subscriptions_url,
            "https://api.github.com/users/greenbone/subscriptions",
        )
        self.assertEqual(
            repo.owner.organizations_url,
            "https://api.github.com/users/greenbone/orgs",
        )
        self.assertEqual(
            repo.owner.repos_url, "https://api.github.com/users/greenbone/repos"
        )
        self.assertEqual(
            repo.owner.events_url,
            "https://api.github.com/users/greenbone/events{/privacy}",
        )
        self.assertEqual(
            repo.owner.received_events_url,
            "https://api.github.com/users/greenbone/received_events",
        )
        self.assertEqual(repo.owner.type, "Organization")
        self.assertFalse(repo.owner.site_admin)
        self.assertEqual(
            repo.html_url, "https://github.com/greenbone/gvm-tools"
        )
        self.assertEqual(
            repo.description,
            "Remote control your Greenbone Community Edition or Greenbone Enterprise Appliance",
        )
        self.assertEqual(repo.fork, False)
        self.assertEqual(
            repo.url, "https://api.github.com/repos/greenbone/gvm-tools"
        )
        self.assertEqual(
            repo.forks_url,
            "https://api.github.com/repos/greenbone/gvm-tools/forks",
        )
        self.assertEqual(
            repo.keys_url,
            "https://api.github.com/repos/greenbone/gvm-tools/keys{/key_id}",
        )
        self.assertEqual(
            repo.collaborators_url,
            "https://api.github.com/repos/greenbone/gvm-tools/collaborators{/collaborator}",
        )
        self.assertEqual(
            repo.teams_url,
            "https://api.github.com/repos/greenbone/gvm-tools/teams",
        )
        self.assertEqual(
            repo.hooks_url,
            "https://api.github.com/repos/greenbone/gvm-tools/hooks",
        )
        self.assertEqual(
            repo.issue_events_url,
            "https://api.github.com/repos/greenbone/gvm-tools/issues/events{/number}",
        )
        self.assertEqual(
            repo.events_url,
            "https://api.github.com/repos/greenbone/gvm-tools/events",
        )
        self.assertEqual(
            repo.assignees_url,
            "https://api.github.com/repos/greenbone/gvm-tools/assignees{/user}",
        )
        self.assertEqual(
            repo.branches_url,
            "https://api.github.com/repos/greenbone/gvm-tools/branches{/branch}",
        )
        self.assertEqual(
            repo.tags_url,
            "https://api.github.com/repos/greenbone/gvm-tools/tags",
        )
        self.assertEqual(
            repo.blobs_url,
            "https://api.github.com/repos/greenbone/gvm-tools/git/blobs{/sha}",
        )
        self.assertEqual(
            repo.git_tags_url,
            "https://api.github.com/repos/greenbone/gvm-tools/git/tags{/sha}",
        )
        self.assertEqual(
            repo.git_refs_url,
            "https://api.github.com/repos/greenbone/gvm-tools/git/refs{/sha}",
        )
        self.assertEqual(
            repo.trees_url,
            "https://api.github.com/repos/greenbone/gvm-tools/git/trees{/sha}",
        )
        self.assertEqual(
            repo.statuses_url,
            "https://api.github.com/repos/greenbone/gvm-tools/statuses/{sha}",
        )
        self.assertEqual(
            repo.languages_url,
            "https://api.github.com/repos/greenbone/gvm-tools/languages",
        )
        self.assertEqual(
            repo.stargazers_url,
            "https://api.github.com/repos/greenbone/gvm-tools/stargazers",
        )
        self.assertEqual(
            repo.contributors_url,
            "https://api.github.com/repos/greenbone/gvm-tools/contributors",
        )
        self.assertEqual(
            repo.subscribers_url,
            "https://api.github.com/repos/greenbone/gvm-tools/subscribers",
        )
        self.assertEqual(
            repo.subscription_url,
            "https://api.github.com/repos/greenbone/gvm-tools/subscription",
        )
        self.assertEqual(
            repo.commits_url,
            "https://api.github.com/repos/greenbone/gvm-tools/commits{/sha}",
        )
        self.assertEqual(
            repo.git_commits_url,
            "https://api.github.com/repos/greenbone/gvm-tools/git/commits{/sha}",
        )
        self.assertEqual(
            repo.comments_url,
            "https://api.github.com/repos/greenbone/gvm-tools/comments{/number}",
        )
        self.assertEqual(
            repo.issue_comment_url,
            "https://api.github.com/repos/greenbone/gvm-tools/issues/comments{/number}",
        )
        self.assertEqual(
            repo.contents_url,
            "https://api.github.com/repos/greenbone/gvm-tools/contents/{+path}",
        )
        self.assertEqual(
            repo.compare_url,
            "https://api.github.com/repos/greenbone/gvm-tools/compare/{base}...{head}",
        )
        self.assertEqual(
            repo.merges_url,
            "https://api.github.com/repos/greenbone/gvm-tools/merges",
        )
        self.assertEqual(
            repo.archive_url,
            "https://api.github.com/repos/greenbone/gvm-tools/{archive_format}{/ref}",
        )
        self.assertEqual(
            repo.downloads_url,
            "https://api.github.com/repos/greenbone/gvm-tools/downloads",
        )
        self.assertEqual(
            repo.issues_url,
            "https://api.github.com/repos/greenbone/gvm-tools/issues{/number}",
        )
        self.assertEqual(
            repo.pulls_url,
            "https://api.github.com/repos/greenbone/gvm-tools/pulls{/number}",
        )
        self.assertEqual(
            repo.milestones_url,
            "https://api.github.com/repos/greenbone/gvm-tools/milestones{/number}",
        )
        self.assertEqual(
            repo.notifications_url,
            "https://api.github.com/repos/greenbone/gvm-tools/notifications{?since,all,participating}",
        )
        self.assertEqual(
            repo.labels_url,
            "https://api.github.com/repos/greenbone/gvm-tools/labels{/name}",
        )
        self.assertEqual(
            repo.releases_url,
            "https://api.github.com/repos/greenbone/gvm-tools/releases{/id}",
        )
        self.assertEqual(
            repo.deployments_url,
            "https://api.github.com/repos/greenbone/gvm-tools/deployments",
        )
        self.assertEqual(
            repo.created_at,
            datetime(2017, 9, 15, 10, 54, 42, tzinfo=timezone.utc),
        )
        self.assertEqual(
            repo.updated_at,
            datetime(2022, 11, 1, 7, 45, 33, tzinfo=timezone.utc),
        )
        self.assertEqual(
            repo.pushed_at,
            datetime(2022, 11, 7, 9, 21, 30, tzinfo=timezone.utc),
        )
        self.assertEqual(
            repo.git_url, "git://github.com/greenbone/gvm-tools.git"
        )
        self.assertEqual(repo.ssh_url, "git@github.com:greenbone/gvm-tools.git")
        self.assertEqual(
            repo.clone_url, "https://github.com/greenbone/gvm-tools.git"
        )
        self.assertEqual(repo.svn_url, "https://github.com/greenbone/gvm-tools")
        self.assertEqual(
            repo.homepage, "https://greenbone.github.io/gvm-tools/"
        )
        self.assertEqual(repo.size, 3461)
        self.assertEqual(repo.stargazers_count, 128)
        self.assertEqual(repo.watchers_count, 128)
        self.assertEqual(repo.language, "Python")
        self.assertEqual(repo.has_issues, True)
        self.assertEqual(repo.has_projects, False)
        self.assertEqual(repo.has_downloads, True)
        self.assertEqual(repo.has_wiki, True)
        self.assertEqual(repo.has_pages, True)
        self.assertEqual(repo.has_discussions, False)
        self.assertEqual(repo.forks_count, 74)
        self.assertEqual(repo.mirror_url, None)
        self.assertEqual(repo.archived, False)
        self.assertEqual(repo.disabled, False)
        self.assertEqual(repo.open_issues_count, 3)
        self.assertEqual(repo.license.key, "gpl-3.0")
        self.assertEqual(repo.license.name, "GNU General Public License v3.0")
        self.assertEqual(repo.license.spdx_id, "GPL-3.0")
        self.assertEqual(
            repo.license.url, "https://api.github.com/licenses/gpl-3.0"
        )
        self.assertEqual(repo.license.node_id, "MDc6TGljZW5zZTk=")
        self.assertTrue(repo.allow_forking)
        self.assertFalse(repo.is_template)
        self.assertFalse(repo.web_commit_signoff_required)
        self.assertEqual(
            repo.topics,
            [
                "gmp",
                "gmp-scripts",
                "greenbone",
                "greenbone-vulnerability-manager",
                "gvm",
                "gvm-cli",
                "gvm-pyshell",
                "gvm-script",
                "omp",
                "openvas",
                "openvas-cli",
                "osp",
                "python",
                "vulnerability",
                "vulnerability-assessment",
                "vulnerability-management",
            ],
        )
        self.assertEqual(repo.visibility, "public")
        self.assertEqual(repo.forks, 74)
        self.assertEqual(repo.open_issues, 3)
        self.assertEqual(repo.watchers, 128)
        self.assertEqual(repo.default_branch, "main")