Skip to content

Commit f338500

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

File tree

1 file changed

+78
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)