-
Notifications
You must be signed in to change notification settings - Fork 395
/
test_orgs_team.py
137 lines (101 loc) · 4.52 KB
/
test_orgs_team.py
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
import pytest
from . import helper
from github3 import GitHubError
from github3.orgs import Team
url_for = helper.create_url_helper("https://api.github.com/teams/1")
get_team_example_data = helper.create_example_data_helper("orgs_team_example")
class TestTeam(helper.UnitHelper):
described_class = Team
example_data = get_team_example_data()
def test_add_repository(self):
"""Show that one can add a repository to an organization team."""
self.instance.add_repository("name-of-repo")
self.put_called_with(url_for("repos/name-of-repo"), data={})
self.instance.add_repository("name-of-repo", permission="push")
self.put_called_with(
url_for("repos/name-of-repo"), data={"permission": "push"}
)
def test_delete(self):
"""Show that a user can delete an organization team."""
self.instance.delete()
self.session.delete.assert_called_once_with(url_for())
def test_edit(self):
"""Show that a user can edit a team."""
self.instance.edit("name", "admin", 1234)
self.patch_called_with(
url_for(),
data={
"name": "name",
"permission": "admin",
"parent_team_id": 1234,
},
)
def test_has_repository(self):
"""Show that a user can check if a team has access to a repository."""
self.instance.has_repository("org/repo")
self.session.get.assert_called_once_with(url_for("repos/org/repo"))
def test_remove_repository(self):
"""Show that a user can remove a repository from a team."""
self.instance.remove_repository("repo")
self.session.delete.assert_called_once_with(url_for("/repos/repo"))
class TestTeamRequiresAuth(helper.UnitRequiresAuthenticationHelper):
described_class = Team
example_data = get_team_example_data()
def test_add_repository_requires_auth(self):
"""Show that adding a repo to a team requires authentication."""
with pytest.raises(GitHubError):
self.instance.add_repository("repo")
def test_delete_requires_auth(self):
"""Show that deleteing a team requires authentication."""
with pytest.raises(GitHubError):
self.instance.delete()
def test_edit_requires_auth(self):
"""Show that editing a team requires authentication."""
with pytest.raises(GitHubError):
self.instance.edit("name")
def test_has_repository_requires_auth(self):
"""Show that checking a team's access to a repo needs auth."""
with pytest.raises(GitHubError):
self.instance.has_repository("org/repo")
def test_remove_repository_requires_auth(self):
"""Show that removing a repo from a team requires authentication."""
with pytest.raises(GitHubError):
self.instance.remove_repository("repo")
class TestTeamIterator(helper.UnitIteratorHelper):
described_class = Team
example_data = get_team_example_data()
def test_members(self):
"""Show that one can iterate over all members of a Team."""
i = self.instance.members()
self.get_next(i)
self.session.get.assert_called_once_with(
url_for("members"), params={"per_page": 100}, headers={}
)
def test_members_roles(self):
"""Show that one can iterate of all maintainers of a Team."""
i = self.instance.members(role="maintainer")
self.get_next(i)
self.session.get.assert_called_once_with(
url_for("members"),
params={"per_page": 100, "role": "maintainer"},
headers={"Accept": "application/vnd.github.ironman-preview+json"},
)
def test_members_excludes_fake_roles(self):
"""Show that one cannot pass a bogus role to the API."""
i = self.instance.members(role="bogus-role")
self.get_next(i)
self.session.get.assert_called_once_with(
url_for("members"), params={"per_page": 100}, headers={}
)
def test_members_requires_auth(self):
"""Show that one needs to authenticate to get team members."""
self.session.has_auth.return_value = False
with pytest.raises(GitHubError):
self.instance.members()
def test_repositories(self):
"""Show that one can iterate over an organization's repositories."""
i = self.instance.repositories()
self.get_next(i)
self.session.get.assert_called_once_with(
url_for("repos"), params={"per_page": 100}, headers={}
)