FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python-gitlab/tests/unit/objects/test_invitations.py at main · sisp/python-gitlab · GitHub
sisp
python-gitlab
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
python-gitlab
/
tests
/
unit
/
objects
/
test_invitations.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
152 lines (118 loc) · 4.58 KB
Breadcrumbs
python-gitlab
/
tests
/
unit
/
objects
/
test_invitations.py
Copy path
File metadata and controls
152 lines (118 loc) · 4.58 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
"""
GitLab API: https://docs.gitlab.com/ce/api/invitations.html
"""
import
re
import
pytest
import
responses
from
gitlab
.
exceptions
import
GitlabInvitationError
create_content
=
{
"email"
:
"email@example.com"
,
"access_level"
:
30
}
success_content
=
{
"status"
:
"success"
}
error_content
=
{
"status"
:
"error"
,
"message"
: {
"test@example.com"
:
"Invite email has already been taken"
,
"test2@example.com"
:
"User already exists in source"
,
"test_username"
:
"Access level is not included in the list"
,
},
}
invitations_content
=
[
{
"id"
:
1
,
"invite_email"
:
"member@example.org"
,
"created_at"
:
"2020-10-22T14:13:35Z"
,
"access_level"
:
30
,
"expires_at"
:
"2020-11-22T14:13:35Z"
,
"user_name"
:
"Raymond Smith"
,
"created_by_name"
:
"Administrator"
,
}
]
invitation_content
=
{
"expires_at"
:
"2012-10-22T14:13:35Z"
,
"access_level"
:
40
}
@
pytest
.
fixture
def
resp_invitations_list
():
with
responses
.
RequestsMock
()
as
rsps
:
rsps
.
add
(
method
=
responses
.
GET
,
url
=
re
.
compile
(
r"http://localhost/api/v4/(groups|projects)/1/invitations"
),
json
=
invitations_content
,
content_type
=
"application/json"
,
status
=
200
,
)
yield
rsps
@
pytest
.
fixture
def
resp_invitation_create
():
with
responses
.
RequestsMock
()
as
rsps
:
rsps
.
add
(
method
=
responses
.
POST
,
url
=
re
.
compile
(
r"http://localhost/api/v4/(groups|projects)/1/invitations"
),
json
=
success_content
,
content_type
=
"application/json"
,
status
=
200
,
)
yield
rsps
@
pytest
.
fixture
def
resp_invitation_create_error
():
with
responses
.
RequestsMock
()
as
rsps
:
rsps
.
add
(
method
=
responses
.
POST
,
url
=
re
.
compile
(
r"http://localhost/api/v4/(groups|projects)/1/invitations"
),
json
=
error_content
,
content_type
=
"application/json"
,
status
=
200
,
)
yield
rsps
@
pytest
.
fixture
def
resp_invitation_update
():
with
responses
.
RequestsMock
()
as
rsps
:
pattern
=
re
.
compile
(
r"http://localhost/api/v4/(groups|projects)/1/invitations/email%40example.com"
)
rsps
.
add
(
method
=
responses
.
PUT
,
url
=
pattern
,
json
=
invitation_content
,
content_type
=
"application/json"
,
status
=
200
,
)
yield
rsps
@
pytest
.
fixture
def
resp_invitation_delete
():
with
responses
.
RequestsMock
()
as
rsps
:
pattern
=
re
.
compile
(
r"http://localhost/api/v4/(groups|projects)/1/invitations/email%40example.com"
)
rsps
.
add
(
method
=
responses
.
DELETE
,
url
=
pattern
,
status
=
204
)
yield
rsps
def
test_list_group_invitations
(
group
,
resp_invitations_list
):
invitations
=
group
.
invitations
.
list
()
assert
invitations
[
0
].
invite_email
==
"member@example.org"
def
test_create_group_invitation
(
group
,
resp_invitation_create
):
invitation
=
group
.
invitations
.
create
(
create_content
)
assert
invitation
.
status
==
"success"
def
test_update_group_invitation
(
group
,
resp_invitation_update
):
invitation
=
group
.
invitations
.
get
(
"email@example.com"
,
lazy
=
True
)
invitation
.
access_level
=
30
invitation
.
save
()
def
test_delete_group_invitation
(
group
,
resp_invitation_delete
):
invitation
=
group
.
invitations
.
get
(
"email@example.com"
,
lazy
=
True
)
invitation
.
delete
()
group
.
invitations
.
delete
(
"email@example.com"
)
def
test_list_project_invitations
(
project
,
resp_invitations_list
):
invitations
=
project
.
invitations
.
list
()
assert
invitations
[
0
].
invite_email
==
"member@example.org"
def
test_create_project_invitation
(
project
,
resp_invitation_create
):
invitation
=
project
.
invitations
.
create
(
create_content
)
assert
invitation
.
status
==
"success"
def
test_update_project_invitation
(
project
,
resp_invitation_update
):
invitation
=
project
.
invitations
.
get
(
"email@example.com"
,
lazy
=
True
)
invitation
.
access_level
=
30
invitation
.
save
()
def
test_delete_project_invitation
(
project
,
resp_invitation_delete
):
invitation
=
project
.
invitations
.
get
(
"email@example.com"
,
lazy
=
True
)
invitation
.
delete
()
project
.
invitations
.
delete
(
"email@example.com"
)
def
test_create_group_invitation_raises
(
group
,
resp_invitation_create_error
):
with
pytest
.
raises
(
GitlabInvitationError
,
match
=
"User already exists"
):
group
.
invitations
.
create
(
create_content
)
def
test_create_project_invitation_raises
(
project
,
resp_invitation_create_error
):
with
pytest
.
raises
(
GitlabInvitationError
,
match
=
"User already exists"
):
project
.
invitations
.
create
(
create_content
)
Back
|
FazBrowse Home
|
New Git URL