FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python-gitlab/gitlab/tests/objects/test_users.py at master · icanka/python-gitlab · GitHub
icanka
python-gitlab
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
python-gitlab
/
gitlab
/
tests
/
objects
/
test_users.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
217 lines (185 loc) · 5.72 KB
Breadcrumbs
python-gitlab
/
gitlab
/
tests
/
objects
/
test_users.py
Copy path
File metadata and controls
217 lines (185 loc) · 5.72 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
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
"""
GitLab API: https://docs.gitlab.com/ce/api/users.html
"""
import
pytest
import
responses
from
gitlab
.
v4
.
objects
import
User
,
UserMembership
,
UserStatus
@
pytest
.
fixture
def
resp_get_user
():
content
=
{
"name"
:
"name"
,
"id"
:
1
,
"password"
:
"password"
,
"username"
:
"username"
,
"email"
:
"email"
,
}
with
responses
.
RequestsMock
()
as
rsps
:
rsps
.
add
(
method
=
responses
.
GET
,
url
=
"http://localhost/api/v4/users/1"
,
json
=
content
,
content_type
=
"application/json"
,
status
=
200
,
)
yield
rsps
@
pytest
.
fixture
def
resp_get_user_memberships
():
content
=
[
{
"source_id"
:
1
,
"source_name"
:
"Project one"
,
"source_type"
:
"Project"
,
"access_level"
:
"20"
,
},
{
"source_id"
:
3
,
"source_name"
:
"Group three"
,
"source_type"
:
"Namespace"
,
"access_level"
:
"20"
,
},
]
with
responses
.
RequestsMock
()
as
rsps
:
rsps
.
add
(
method
=
responses
.
GET
,
url
=
"http://localhost/api/v4/users/1/memberships"
,
json
=
content
,
content_type
=
"application/json"
,
status
=
200
,
)
yield
rsps
@
pytest
.
fixture
def
resp_activate
():
with
responses
.
RequestsMock
(
assert_all_requests_are_fired
=
False
)
as
rsps
:
rsps
.
add
(
method
=
responses
.
POST
,
url
=
"http://localhost/api/v4/users/1/activate"
,
json
=
{},
content_type
=
"application/json"
,
status
=
201
,
)
rsps
.
add
(
method
=
responses
.
POST
,
url
=
"http://localhost/api/v4/users/1/deactivate"
,
json
=
{},
content_type
=
"application/json"
,
status
=
201
,
)
yield
rsps
@
pytest
.
fixture
def
resp_get_user_status
():
content
=
{
"message"
:
"test"
,
"message_html"
:
"<h1>Message</h1>"
,
"emoji"
:
"thumbsup"
,
}
with
responses
.
RequestsMock
()
as
rsps
:
rsps
.
add
(
method
=
responses
.
GET
,
url
=
"http://localhost/api/v4/users/1/status"
,
json
=
content
,
content_type
=
"application/json"
,
status
=
200
,
)
yield
rsps
@
pytest
.
fixture
def
resp_delete_user_identity
(
no_content
):
with
responses
.
RequestsMock
()
as
rsps
:
rsps
.
add
(
method
=
responses
.
DELETE
,
url
=
"http://localhost/api/v4/users/1/identities/test_provider"
,
json
=
no_content
,
content_type
=
"application/json"
,
status
=
204
,
)
yield
rsps
@
pytest
.
fixture
def
resp_follow_unfollow
():
user
=
{
"id"
:
1
,
"username"
:
"john_smith"
,
"name"
:
"John Smith"
,
"state"
:
"active"
,
"avatar_url"
:
"http://localhost:3000/uploads/user/avatar/1/cd8.jpeg"
,
"web_url"
:
"http://localhost:3000/john_smith"
,
}
with
responses
.
RequestsMock
()
as
rsps
:
rsps
.
add
(
method
=
responses
.
POST
,
url
=
"http://localhost/api/v4/users/1/follow"
,
json
=
user
,
content_type
=
"application/json"
,
status
=
201
,
)
rsps
.
add
(
method
=
responses
.
POST
,
url
=
"http://localhost/api/v4/users/1/unfollow"
,
json
=
user
,
content_type
=
"application/json"
,
status
=
201
,
)
yield
rsps
@
pytest
.
fixture
def
resp_followers_following
():
content
=
[
{
"id"
:
2
,
"name"
:
"Lennie Donnelly"
,
"username"
:
"evette.kilback"
,
"state"
:
"active"
,
"avatar_url"
:
"https://www.gravatar.com/avatar/7955171a55ac4997ed81e5976287890a?s=80&d=identicon"
,
"web_url"
:
"http://127.0.0.1:3000/evette.kilback"
,
},
{
"id"
:
4
,
"name"
:
"Serena Bradtke"
,
"username"
:
"cammy"
,
"state"
:
"active"
,
"avatar_url"
:
"https://www.gravatar.com/avatar/a2daad869a7b60d3090b7b9bef4baf57?s=80&d=identicon"
,
"web_url"
:
"http://127.0.0.1:3000/cammy"
,
},
]
with
responses
.
RequestsMock
()
as
rsps
:
rsps
.
add
(
method
=
responses
.
GET
,
url
=
"http://localhost/api/v4/users/1/followers"
,
json
=
content
,
content_type
=
"application/json"
,
status
=
200
,
)
rsps
.
add
(
method
=
responses
.
GET
,
url
=
"http://localhost/api/v4/users/1/following"
,
json
=
content
,
content_type
=
"application/json"
,
status
=
200
,
)
yield
rsps
def
test_get_user
(
gl
,
resp_get_user
):
user
=
gl
.
users
.
get
(
1
)
assert
isinstance
(
user
,
User
)
assert
user
.
name
==
"name"
assert
user
.
id
==
1
def
test_user_memberships
(
user
,
resp_get_user_memberships
):
memberships
=
user
.
memberships
.
list
()
assert
isinstance
(
memberships
[
0
],
UserMembership
)
assert
memberships
[
0
].
source_type
==
"Project"
def
test_user_status
(
user
,
resp_get_user_status
):
status
=
user
.
status
.
get
()
assert
isinstance
(
status
,
UserStatus
)
assert
status
.
message
==
"test"
assert
status
.
emoji
==
"thumbsup"
def
test_user_activate_deactivate
(
user
,
resp_activate
):
user
.
activate
()
user
.
deactivate
()
def
test_delete_user_identity
(
user
,
resp_delete_user_identity
):
user
.
identityproviders
.
delete
(
"test_provider"
)
def
test_user_follow_unfollow
(
user
,
resp_follow_unfollow
):
user
.
follow
()
user
.
unfollow
()
def
test_list_followers
(
user
,
resp_followers_following
):
followers
=
user
.
followers_users
.
list
()
followings
=
user
.
following_users
.
list
()
assert
isinstance
(
followers
[
0
],
User
)
assert
followers
[
0
].
id
==
2
assert
isinstance
(
followings
[
0
],
User
)
assert
followings
[
1
].
id
==
4
Back
|
FazBrowse Home
|
New Git URL