8000 feat(unit): Add unit tests for service accounts · python-gitlab/python-gitlab@1f5309e · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1f5309e

Browse files
author
Rolf Offermanns
committed
feat(unit): Add unit tests for service accounts
1 parent 98c7f7b commit 1f5309e

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
"""
2+
GitLab API: https://docs.gitlab.com/ee/api/user_service_accounts.html
3+
"""
4+
5+
import pytest
6+
import responses
7+
8+
create_service_account_defaults_content = {
9+
"id": 57,
10+
"username": "service_account_6018816a18e515214e0c34c2b33523fc",
11+
"name": "Service account user",
12+
"email": "service_account_6018816a18e515214e0c34c2b33523fc@noreply.gitlab.example.com",
13+
}
14+
15+
16+
create_service_account_content = {
17+
"id": 42,
18+
"username": "my_service_account",
19+
"name": "My Service account user",
20+
"email": "servicebot@example.com",
21+
}
22+
23+
24+
@pytest.fixture
25+
def resp_create_service_account_defaults():
26+
with responses.RequestsMock() as rsps:
27+
rsps.add(
28+
method=responses.POST,
29+
url="http://localhost/api/v4/service_accounts",
30+
json=create_service_account_defaults_content,
31+
content_type="application/json",
32+
status=200,
33+
)
34+
35+
yield rsps
36+
37+
38+
@pytest.fixture
39+
def resp_create_service_account():
40+
with responses.RequestsMock() as rsps:
41+
rsps.add(
42+
method=responses.POST,
43+
url="http://localhost/api/v4/service_accounts",
44+
json=create_service_account_content,
45+
content_type="application/json",
46+
status=200,
47+
)
48+
49+
yield rsps
50+
51+
52+
def test_create_service_account_defaults(gl, resp_create_service_account_defaults):
53+
service_account = gl.service_accounts.create()
54+
assert service_account.id == 57
55+
assert (
56+
service_account.username == "service_account_6018816a18e515214e0c34c2b33523fc"
57+
)
58+
assert service_account.name == "Service account user"
59+
assert (
60+
service_account.email
61+
== "service_account_6018816a18e515214e0c34c2b33523fc@noreply.gitlab.example.com"
62+
)
63+
64+
65+
def test_create_service_account(gl, resp_create_service_account):
66+
service_account = gl.service_accounts.create(
67+
{
68+
"name": "My Service account user",
69+
"username": "my_service_account",
70+
"email": "servicebot@example.com",
71+
}
72+
)
73+
assert service_account.id == 42
74+
assert service_account.username == "my_service_account"
75+
assert service_account.name == "My Service account user"
76+
assert service_account.email == "servicebot@example.com"

0 commit comments

Comments
 (0)
0