File: test_branch.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 (659 lines) | stat: -rw-r--r-- 31,254 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
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
# 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 Permission
from pontos.github.models.branch import (
    BranchProtection,
    RequiredPullRequestReviews,
    RequiredStatusChecks,
    Restrictions,
)


class RestrictionsTestCase(unittest.TestCase):
    def test_from_dict(self):
        data = {
            "url": "https://api.github.com/repos/foo/bar/branches/branch_protection/protection/restrictions",
            "users_url": "https://api.github.com/repos/foo/bar/branches/branch_protection/protection/restrictions/users",
            "teams_url": "https://api.github.com/repos/foo/bar/branches/branch_protection/protection/restrictions/teams",
            "apps_url": "https://api.github.com/repos/foo/bar/branches/branch_protection/protection/restrictions/apps",
            "users": [
                {
                    "login": "greenbonebot",
                    "id": 123,
                    "node_id": "MDQ6VXNlcjg1MjU0NjY2",
                    "avatar_url": "https://avatars.githubusercontent.com/u/85254666?v=4",
                    "gravatar_id": "",
                    "url": "https://api.github.com/users/greenbonebot",
                    "html_url": "https://github.com/greenbonebot",
                    "followers_url": "https://api.github.com/users/greenbonebot/followers",
                    "following_url": "https://api.github.com/users/greenbonebot/following{/other_user}",
                    "gists_url": "https://api.github.com/users/greenbonebot/gists{/gist_id}",
                    "starred_url": "https://api.github.com/users/greenbonebot/starred{/owner}{/repo}",
                    "subscriptions_url": "https://api.github.com/users/greenbonebot/subscriptions",
                    "organizations_url": "https://api.github.com/users/greenbonebot/orgs",
                    "repos_url": "https://api.github.com/users/greenbonebot/repos",
                    "events_url": "https://api.github.com/users/greenbonebot/events{/privacy}",
                    "received_events_url": "https://api.github.com/users/greenbonebot/received_events",
                    "type": "User",
                    "site_admin": False,
                }
            ],
            "teams": [],
            "apps": [],
        }

        restrictions = Restrictions.from_dict(data)
        self.assertEqual(
            restrictions.url,
            "https://api.github.com/repos/foo/bar/branches/branch_protection/protection/restrictions",
        )
        self.assertEqual(
            restrictions.users_url,
            "https://api.github.com/repos/foo/bar/branches/branch_protection/protection/restrictions/users",
        )
        self.assertEqual(
            restrictions.teams_url,
            "https://api.github.com/repos/foo/bar/branches/branch_protection/protection/restrictions/teams",
        )
        self.assertEqual(
            restrictions.apps_url,
            "https://api.github.com/repos/foo/bar/branches/branch_protection/protection/restrictions/apps",
        )
        user = restrictions.users[0]
        self.assertEqual(len(restrictions.users), 1)
        self.assertEqual(user.login, "greenbonebot")
        self.assertEqual(user.node_id, "MDQ6VXNlcjg1MjU0NjY2")
        self.assertEqual(
            user.avatar_url,
            "https://avatars.githubusercontent.com/u/85254666?v=4",
        )
        self.assertEqual(user.gravatar_id, "")
        self.assertEqual(user.url, "https://api.github.com/users/greenbonebot")
        self.assertEqual(user.html_url, "https://github.com/greenbonebot")
        self.assertEqual(
            user.followers_url,
            "https://api.github.com/users/greenbonebot/followers",
        )
        self.assertEqual(
            user.following_url,
            "https://api.github.com/users/greenbonebot/following{/other_user}",
        )
        self.assertEqual(
            user.gists_url,
            "https://api.github.com/users/greenbonebot/gists{/gist_id}",
        )
        self.assertEqual(
            user.starred_url,
            "https://api.github.com/users/greenbonebot/starred{/owner}{/repo}",
        )
        self.assertEqual(
            user.subscriptions_url,
            "https://api.github.com/users/greenbonebot/subscriptions",
        )
        self.assertEqual(
            user.organizations_url,
            "https://api.github.com/users/greenbonebot/orgs",
        )
        self.assertEqual(
            user.repos_url, "https://api.github.com/users/greenbonebot/repos"
        )
        self.assertEqual(
            user.events_url,
            "https://api.github.com/users/greenbonebot/events{/privacy}",
        )
        self.assertEqual(
            user.received_events_url,
            "https://api.github.com/users/greenbonebot/received_events",
        )
        self.assertEqual(user.type, "User")
        self.assertEqual(user.site_admin, False)
        self.assertEqual(restrictions.teams, [])
        self.assertEqual(restrictions.apps, [])


class RequiredStatusChecksTestCase(unittest.TestCase):
    def test_from_dict(self):
        data = {
            "url": "https://api.github.com/repos/foo/bar/branches/branch_protection/protection/required_status_checks",
            "strict": True,
            "checks": [
                {"context": "unittests", "app_id": 123},
                {"context": "linting"},
            ],
        }

        checks = RequiredStatusChecks.from_dict(data)

        self.assertEqual(
            checks.url,
            "https://api.github.com/repos/foo/bar/branches/branch_protection/protection/required_status_checks",
        )
        self.assertTrue(checks.strict)
        self.assertEqual(len(checks.checks), 2)
        self.assertEqual(checks.checks[0].context, "unittests")
        self.assertEqual(checks.checks[0].app_id, 123)
        self.assertEqual(checks.checks[1].context, "linting")
        self.assertIsNone(checks.checks[1].app_id)


class RequiredPullRequestReviewsTestCase(unittest.TestCase):
    def test_from_dict(self):
        data = {
            "url": "https://api.github.com/repos/foo/bar/branches/branch_protection/protection/required_pull_request_reviews",
            "dismiss_stale_reviews": True,
            "require_code_owner_reviews": True,
            "require_last_push_approval": True,
            "required_approving_review_count": 1,
            "dismissal_restrictions": {
                "url": "https://api.github.com/repos/foo/bar/branches/branch_protection/protection/dismissal_restrictions",
                "users_url": "https://api.github.com/repos/foo/bar/branches/branch_protection/protection/dismissal_restrictions/users",
                "teams_url": "https://api.github.com/repos/foo/bar/branches/branch_protection/protection/dismissal_restrictions/teams",
                "users": [
                    {
                        "login": "greenbonebot",
                        "id": 123,
                        "node_id": "MDQ6VXNlcjg1MjU0NjY2",
                        "avatar_url": "https://avatars.githubusercontent.com/u/85254666?v=4",
                        "gravatar_id": "",
                        "url": "https://api.github.com/users/greenbonebot",
                        "html_url": "https://github.com/greenbonebot",
                        "followers_url": "https://api.github.com/users/greenbonebot/followers",
                        "following_url": "https://api.github.com/users/greenbonebot/following{/other_user}",
                        "gists_url": "https://api.github.com/users/greenbonebot/gists{/gist_id}",
                        "starred_url": "https://api.github.com/users/greenbonebot/starred{/owner}{/repo}",
                        "subscriptions_url": "https://api.github.com/users/greenbonebot/subscriptions",
                        "organizations_url": "https://api.github.com/users/greenbonebot/orgs",
                        "repos_url": "https://api.github.com/users/greenbonebot/repos",
                        "events_url": "https://api.github.com/users/greenbonebot/events{/privacy}",
                        "received_events_url": "https://api.github.com/users/greenbonebot/received_events",
                        "type": "User",
                        "site_admin": False,
                    }
                ],
                "teams": [
                    {
                        "name": "devops",
                        "id": 123,
                        "node_id": "T_kwDOAegUqc4AUtL1",
                        "slug": "devops",
                        "description": "Team responsible for DevOps",
                        "privacy": "closed",
                        "url": "https://api.github.com/organizations/321/team/123",
                        "html_url": "https://github.com/orgs/foo/teams/devops",
                        "members_url": "https://api.github.com/organizations/321/team/123/members{/member}",
                        "repositories_url": "https://api.github.com/organizations/321/team/123/repos",
                        "permission": "pull",
                        "parent": None,
                    }
                ],
                "apps": [],
            },
        }

        reviews = RequiredPullRequestReviews.from_dict(data)

        self.assertEqual(
            reviews.url,
            "https://api.github.com/repos/foo/bar/branches/branch_protection/protection/required_pull_request_reviews",
        )
        self.assertTrue(reviews.dismiss_stale_reviews)
        self.assertTrue(reviews.require_code_owner_reviews)
        self.assertTrue(reviews.require_last_push_approval)
        self.assertEqual(
            reviews.required_approving_review_count,
            1,
        )
        dismissal_restrictions = reviews.dismissal_restrictions
        self.assertEqual(
            dismissal_restrictions.url,
            "https://api.github.com/repos/foo/bar/branches/branch_protection/protection/dismissal_restrictions",
        )
        self.assertEqual(
            dismissal_restrictions.users_url,
            "https://api.github.com/repos/foo/bar/branches/branch_protection/protection/dismissal_restrictions/users",
        )
        self.assertEqual(
            dismissal_restrictions.teams_url,
            "https://api.github.com/repos/foo/bar/branches/branch_protection/protection/dismissal_restrictions/teams",
        )
        self.assertEqual(dismissal_restrictions.apps, [])
        user = dismissal_restrictions.users[0]
        self.assertEqual(len(dismissal_restrictions.users), 1)
        self.assertEqual(user.login, "greenbonebot")
        self.assertEqual(user.node_id, "MDQ6VXNlcjg1MjU0NjY2")
        self.assertEqual(
            user.avatar_url,
            "https://avatars.githubusercontent.com/u/85254666?v=4",
        )
        self.assertEqual(user.gravatar_id, "")
        self.assertEqual(user.url, "https://api.github.com/users/greenbonebot")
        self.assertEqual(user.html_url, "https://github.com/greenbonebot")
        self.assertEqual(
            user.followers_url,
            "https://api.github.com/users/greenbonebot/followers",
        )
        self.assertEqual(
            user.following_url,
            "https://api.github.com/users/greenbonebot/following{/other_user}",
        )
        self.assertEqual(
            user.gists_url,
            "https://api.github.com/users/greenbonebot/gists{/gist_id}",
        )
        self.assertEqual(
            user.starred_url,
            "https://api.github.com/users/greenbonebot/starred{/owner}{/repo}",
        )
        self.assertEqual(
            user.subscriptions_url,
            "https://api.github.com/users/greenbonebot/subscriptions",
        )
        self.assertEqual(
            user.organizations_url,
            "https://api.github.com/users/greenbonebot/orgs",
        )
        self.assertEqual(
            user.repos_url, "https://api.github.com/users/greenbonebot/repos"
        )
        self.assertEqual(
            user.events_url,
            "https://api.github.com/users/greenbonebot/events{/privacy}",
        )
        self.assertEqual(
            user.received_events_url,
            "https://api.github.com/users/greenbonebot/received_events",
        )
        self.assertEqual(user.type, "User")
        self.assertEqual(user.site_admin, False)
        self.assertEqual(len(dismissal_restrictions.teams), 1)
        team = dismissal_restrictions.teams[0]
        self.assertEqual(team.name, "devops")
        self.assertEqual(team.id, 123)
        self.assertEqual(team.node_id, "T_kwDOAegUqc4AUtL1")
        self.assertEqual(team.slug, "devops")
        self.assertEqual(team.description, "Team responsible for DevOps")
        self.assertEqual(team.permission, Permission.PULL)
        self.assertEqual(team.privacy, TeamPrivacy.CLOSED)
        self.assertEqual(
            team.url, "https://api.github.com/organizations/321/team/123"
        )
        self.assertEqual(
            team.html_url, "https://github.com/orgs/foo/teams/devops"
        )
        self.assertEqual(
            team.members_url,
            "https://api.github.com/organizations/321/team/123/members{/member}",
        )
        self.assertEqual(
            team.repositories_url,
            "https://api.github.com/organizations/321/team/123/repos",
        )
        self.assertIsNone(team.parent)


class BranchProtectionTestCase(unittest.TestCase):
    def test_from_dict_minimal(self):
        data = {
            "url": "https://api.github.com/repos/foo/bar/branches/branch_protection/protection",
            "required_signatures": {
                "url": "https://api.github.com/repos/foo/bar/branches/branch_protection/protection/required_signatures",
                "enabled": False,
            },
            "enforce_admins": {
                "url": "https://api.github.com/repos/foo/bar/branches/branch_protection/protection/enforce_admins",
                "enabled": False,
            },
            "required_linear_history": {"enabled": False},
            "allow_force_pushes": {"enabled": False},
            "allow_deletions": {"enabled": False},
            "block_creations": {"enabled": False},
            "required_conversation_resolution": {"enabled": False},
            "lock_branch": {"enabled": True},
            "allow_fork_syncing": {"enabled": False},
        }

        protection = BranchProtection.from_dict(data)

        self.assertEqual(
            protection.url,
            "https://api.github.com/repos/foo/bar/branches/branch_protection/protection",
        )
        self.assertEqual(
            protection.required_signatures.url,
            "https://api.github.com/repos/foo/bar/branches/branch_protection/protection/required_signatures",
        )
        self.assertFalse(protection.required_signatures.enabled)
        self.assertEqual(
            protection.enforce_admins.url,
            "https://api.github.com/repos/foo/bar/branches/branch_protection/protection/enforce_admins",
        )
        self.assertFalse(protection.enforce_admins.enabled)
        self.assertFalse(protection.required_linear_history.enabled)
        self.assertFalse(protection.allow_force_pushes.enabled)
        self.assertFalse(protection.allow_deletions.enabled)
        self.assertFalse(protection.block_creations.enabled)
        self.assertFalse(protection.required_conversation_resolution.enabled)
        self.assertTrue(protection.lock_branch.enabled)
        self.assertFalse(protection.allow_fork_syncing.enabled)

        self.assertIsNone(protection.required_status_checks)
        self.assertIsNone(protection.required_pull_request_reviews)
        self.assertIsNone(protection.restrictions)

    def test_from_dict(self):
        data = {
            "url": "https://api.github.com/repos/foo/bar/branches/branch_protection/protection",
            "required_status_checks": {
                "url": "https://api.github.com/repos/foo/bar/branches/branch_protection/protection/required_status_checks",
                "strict": True,
                "checks": [],
            },
            "restrictions": {
                "url": "https://api.github.com/repos/foo/bar/branches/branch_protection/protection/restrictions",
                "users_url": "https://api.github.com/repos/foo/bar/branches/branch_protection/protection/restrictions/users",
                "teams_url": "https://api.github.com/repos/foo/bar/branches/branch_protection/protection/restrictions/teams",
                "apps_url": "https://api.github.com/repos/foo/bar/branches/branch_protection/protection/restrictions/apps",
                "users": [
                    {
                        "login": "greenbonebot",
                        "id": 123,
                        "node_id": "MDQ6VXNlcjg1MjU0NjY2",
                        "avatar_url": "https://avatars.githubusercontent.com/u/85254666?v=4",
                        "gravatar_id": "",
                        "url": "https://api.github.com/users/greenbonebot",
                        "html_url": "https://github.com/greenbonebot",
                        "followers_url": "https://api.github.com/users/greenbonebot/followers",
                        "following_url": "https://api.github.com/users/greenbonebot/following{/other_user}",
                        "gists_url": "https://api.github.com/users/greenbonebot/gists{/gist_id}",
                        "starred_url": "https://api.github.com/users/greenbonebot/starred{/owner}{/repo}",
                        "subscriptions_url": "https://api.github.com/users/greenbonebot/subscriptions",
                        "organizations_url": "https://api.github.com/users/greenbonebot/orgs",
                        "repos_url": "https://api.github.com/users/greenbonebot/repos",
                        "events_url": "https://api.github.com/users/greenbonebot/events{/privacy}",
                        "received_events_url": "https://api.github.com/users/greenbonebot/received_events",
                        "type": "User",
                        "site_admin": False,
                    }
                ],
                "teams": [],
                "apps": [],
            },
            "required_pull_request_reviews": {
                "url": "https://api.github.com/repos/foo/bar/branches/branch_protection/protection/required_pull_request_reviews",
                "dismiss_stale_reviews": True,
                "require_code_owner_reviews": True,
                "require_last_push_approval": True,
                "required_approving_review_count": 1,
                "dismissal_restrictions": {
                    "url": "https://api.github.com/repos/foo/bar/branches/branch_protection/protection/dismissal_restrictions",
                    "users_url": "https://api.github.com/repos/foo/bar/branches/branch_protection/protection/dismissal_restrictions/users",
                    "teams_url": "https://api.github.com/repos/foo/bar/branches/branch_protection/protection/dismissal_restrictions/teams",
                    "users": [
                        {
                            "login": "greenbonebot",
                            "id": 123,
                            "node_id": "MDQ6VXNlcjg1MjU0NjY2",
                            "avatar_url": "https://avatars.githubusercontent.com/u/85254666?v=4",
                            "gravatar_id": "",
                            "url": "https://api.github.com/users/greenbonebot",
                            "html_url": "https://github.com/greenbonebot",
                            "followers_url": "https://api.github.com/users/greenbonebot/followers",
                            "following_url": "https://api.github.com/users/greenbonebot/following{/other_user}",
                            "gists_url": "https://api.github.com/users/greenbonebot/gists{/gist_id}",
                            "starred_url": "https://api.github.com/users/greenbonebot/starred{/owner}{/repo}",
                            "subscriptions_url": "https://api.github.com/users/greenbonebot/subscriptions",
                            "organizations_url": "https://api.github.com/users/greenbonebot/orgs",
                            "repos_url": "https://api.github.com/users/greenbonebot/repos",
                            "events_url": "https://api.github.com/users/greenbonebot/events{/privacy}",
                            "received_events_url": "https://api.github.com/users/greenbonebot/received_events",
                            "type": "User",
                            "site_admin": False,
                        }
                    ],
                    "teams": [
                        {
                            "name": "devops",
                            "id": 123,
                            "node_id": "T_kwDOAegUqc4AUtL1",
                            "slug": "devops",
                            "description": "Team responsible for DevOps",
                            "privacy": "closed",
                            "url": "https://api.github.com/organizations/321/team/123",
                            "html_url": "https://github.com/orgs/foo/teams/devops",
                            "members_url": "https://api.github.com/organizations/321/team/123/members{/member}",
                            "repositories_url": "https://api.github.com/organizations/321/team/123/repos",
                            "permission": "pull",
                            "parent": None,
                        }
                    ],
                    "apps": [],
                },
            },
            "required_signatures": {
                "url": "https://api.github.com/repos/foo/bar/branches/branch_protection/protection/required_signatures",
                "enabled": True,
            },
            "enforce_admins": {
                "url": "https://api.github.com/repos/foo/bar/branches/branch_protection/protection/enforce_admins",
                "enabled": True,
            },
            "required_linear_history": {"enabled": True},
            "allow_force_pushes": {"enabled": False},
            "allow_deletions": {"enabled": False},
            "block_creations": {"enabled": True},
            "required_conversation_resolution": {"enabled": True},
            "lock_branch": {"enabled": True},
            "allow_fork_syncing": {"enabled": False},
        }

        protection = BranchProtection.from_dict(data)

        self.assertEqual(
            protection.url,
            "https://api.github.com/repos/foo/bar/branches/branch_protection/protection",
        )
        self.assertEqual(
            protection.required_signatures.url,
            "https://api.github.com/repos/foo/bar/branches/branch_protection/protection/required_signatures",
        )
        self.assertTrue(protection.required_signatures.enabled)
        self.assertEqual(
            protection.enforce_admins.url,
            "https://api.github.com/repos/foo/bar/branches/branch_protection/protection/enforce_admins",
        )
        self.assertTrue(protection.enforce_admins.enabled)
        self.assertTrue(protection.required_linear_history.enabled)
        self.assertFalse(protection.allow_force_pushes.enabled)
        self.assertFalse(protection.allow_deletions.enabled)
        self.assertTrue(protection.block_creations.enabled)
        self.assertTrue(protection.required_conversation_resolution.enabled)
        self.assertTrue(protection.lock_branch.enabled)
        self.assertFalse(protection.allow_fork_syncing.enabled)

        self.assertEqual(
            protection.required_status_checks.url,
            "https://api.github.com/repos/foo/bar/branches/branch_protection/protection/required_status_checks",
        )
        self.assertTrue(protection.required_status_checks.strict)
        self.assertEqual(protection.required_status_checks.checks, [])

        self.assertEqual(
            protection.required_pull_request_reviews.url,
            "https://api.github.com/repos/foo/bar/branches/branch_protection/protection/required_pull_request_reviews",
        )
        self.assertTrue(
            protection.required_pull_request_reviews.dismiss_stale_reviews
        )
        self.assertTrue(
            protection.required_pull_request_reviews.require_code_owner_reviews
        )
        self.assertTrue(
            protection.required_pull_request_reviews.require_last_push_approval
        )
        self.assertEqual(
            protection.required_pull_request_reviews.required_approving_review_count,
            1,
        )
        dismissal_restrictions = (
            protection.required_pull_request_reviews.dismissal_restrictions
        )
        self.assertEqual(
            dismissal_restrictions.url,
            "https://api.github.com/repos/foo/bar/branches/branch_protection/protection/dismissal_restrictions",
        )
        self.assertEqual(
            dismissal_restrictions.users_url,
            "https://api.github.com/repos/foo/bar/branches/branch_protection/protection/dismissal_restrictions/users",
        )
        self.assertEqual(
            dismissal_restrictions.teams_url,
            "https://api.github.com/repos/foo/bar/branches/branch_protection/protection/dismissal_restrictions/teams",
        )
        self.assertEqual(dismissal_restrictions.apps, [])
        user = dismissal_restrictions.users[0]
        self.assertEqual(len(dismissal_restrictions.users), 1)
        self.assertEqual(user.login, "greenbonebot")
        self.assertEqual(user.node_id, "MDQ6VXNlcjg1MjU0NjY2")
        self.assertEqual(
            user.avatar_url,
            "https://avatars.githubusercontent.com/u/85254666?v=4",
        )
        self.assertEqual(user.gravatar_id, "")
        self.assertEqual(user.url, "https://api.github.com/users/greenbonebot")
        self.assertEqual(user.html_url, "https://github.com/greenbonebot")
        self.assertEqual(
            user.followers_url,
            "https://api.github.com/users/greenbonebot/followers",
        )
        self.assertEqual(
            user.following_url,
            "https://api.github.com/users/greenbonebot/following{/other_user}",
        )
        self.assertEqual(
            user.gists_url,
            "https://api.github.com/users/greenbonebot/gists{/gist_id}",
        )
        self.assertEqual(
            user.starred_url,
            "https://api.github.com/users/greenbonebot/starred{/owner}{/repo}",
        )
        self.assertEqual(
            user.subscriptions_url,
            "https://api.github.com/users/greenbonebot/subscriptions",
        )
        self.assertEqual(
            user.organizations_url,
            "https://api.github.com/users/greenbonebot/orgs",
        )
        self.assertEqual(
            user.repos_url, "https://api.github.com/users/greenbonebot/repos"
        )
        self.assertEqual(
            user.events_url,
            "https://api.github.com/users/greenbonebot/events{/privacy}",
        )
        self.assertEqual(
            user.received_events_url,
            "https://api.github.com/users/greenbonebot/received_events",
        )
        self.assertEqual(user.type, "User")
        self.assertEqual(user.site_admin, False)
        self.assertEqual(len(dismissal_restrictions.teams), 1)
        team = dismissal_restrictions.teams[0]
        self.assertEqual(team.name, "devops")
        self.assertEqual(team.id, 123)
        self.assertEqual(team.node_id, "T_kwDOAegUqc4AUtL1")
        self.assertEqual(team.slug, "devops")
        self.assertEqual(team.description, "Team responsible for DevOps")
        self.assertEqual(team.permission, Permission.PULL)
        self.assertEqual(team.privacy, TeamPrivacy.CLOSED)
        self.assertEqual(
            team.url, "https://api.github.com/organizations/321/team/123"
        )
        self.assertEqual(
            team.html_url, "https://github.com/orgs/foo/teams/devops"
        )
        self.assertEqual(
            team.members_url,
            "https://api.github.com/organizations/321/team/123/members{/member}",
        )
        self.assertEqual(
            team.repositories_url,
            "https://api.github.com/organizations/321/team/123/repos",
        )
        self.assertIsNone(team.parent)

        self.assertEqual(
            protection.restrictions.url,
            "https://api.github.com/repos/foo/bar/branches/branch_protection/protection/restrictions",
        )
        self.assertEqual(
            protection.restrictions.users_url,
            "https://api.github.com/repos/foo/bar/branches/branch_protection/protection/restrictions/users",
        )
        self.assertEqual(
            protection.restrictions.teams_url,
            "https://api.github.com/repos/foo/bar/branches/branch_protection/protection/restrictions/teams",
        )
        self.assertEqual(
            protection.restrictions.apps_url,
            "https://api.github.com/repos/foo/bar/branches/branch_protection/protection/restrictions/apps",
        )
        user = protection.restrictions.users[0]
        self.assertEqual(len(protection.restrictions.users), 1)
        self.assertEqual(user.login, "greenbonebot")
        self.assertEqual(user.node_id, "MDQ6VXNlcjg1MjU0NjY2")
        self.assertEqual(
            user.avatar_url,
            "https://avatars.githubusercontent.com/u/85254666?v=4",
        )
        self.assertEqual(user.gravatar_id, "")
        self.assertEqual(user.url, "https://api.github.com/users/greenbonebot")
        self.assertEqual(user.html_url, "https://github.com/greenbonebot")
        self.assertEqual(
            user.followers_url,
            "https://api.github.com/users/greenbonebot/followers",
        )
        self.assertEqual(
            user.following_url,
            "https://api.github.com/users/greenbonebot/following{/other_user}",
        )
        self.assertEqual(
            user.gists_url,
            "https://api.github.com/users/greenbonebot/gists{/gist_id}",
        )
        self.assertEqual(
            user.starred_url,
            "https://api.github.com/users/greenbonebot/starred{/owner}{/repo}",
        )
        self.assertEqual(
            user.subscriptions_url,
            "https://api.github.com/users/greenbonebot/subscriptions",
        )
        self.assertEqual(
            user.organizations_url,
            "https://api.github.com/users/greenbonebot/orgs",
        )
        self.assertEqual(
            user.repos_url, "https://api.github.com/users/greenbonebot/repos"
        )
        self.assertEqual(
            user.events_url,
            "https://api.github.com/users/greenbonebot/events{/privacy}",
        )
        self.assertEqual(
            user.received_events_url,
            "https://api.github.com/users/greenbonebot/received_events",
        )
        self.assertEqual(user.type, "User")
        self.assertEqual(user.site_admin, False)
        self.assertEqual(protection.restrictions.teams, [])
        self.assertEqual(protection.restrictions.apps, [])