Skip to content

Commit 2020bcc

Browse files
committed
api module test coverage
1 parent 0774c30 commit 2020bcc

6 files changed

Lines changed: 963 additions & 330 deletions
Lines changed: 142 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,145 @@
1-
"""
2-
Ibutsu API
1+
"""Tests for AdminProjectManagementApi."""
32

4-
A system to store and query test results
5-
6-
The version of the OpenAPI document: 2.8.3
7-
Generated by OpenAPI Generator (https://openapi-generator.tech)
8-
9-
Do not edit the class manually.
10-
"""
11-
12-
import unittest
3+
from uuid import uuid4
134

145
from ibutsu_client.api.admin_project_management_api import AdminProjectManagementApi
15-
16-
17-
class TestAdminProjectManagementApi(unittest.TestCase):
18-
"""AdminProjectManagementApi unit test stubs"""
19-
20-
def setUp(self) -> None:
21-
self.api = AdminProjectManagementApi()
22-
23-
def tearDown(self) -> None:
24-
pass
25-
26-
def test_admin_add_project(self) -> None:
27-
"""Test case for admin_add_project
28-
29-
Administration endpoint to manually add a project. Only accessible to superadmins.
30-
"""
31-
32-
def test_admin_delete_project(self) -> None:
33-
"""Test case for admin_delete_project
34-
35-
Administration endpoint to delete a project. Only accessible to superadmins.
36-
"""
37-
38-
def test_admin_get_project(self) -> None:
39-
"""Test case for admin_get_project
40-
41-
Administration endpoint to return a project. Only accessible to superadmins.
42-
"""
43-
44-
def test_admin_get_project_list(self) -> None:
45-
"""Test case for admin_get_project_list
46-
47-
Administration endpoint to return a list of projects. Only accessible to superadmins.
48-
"""
49-
50-
def test_admin_update_project(self) -> None:
51-
"""Test case for admin_update_project
52-
53-
Administration endpoint to update a project. Only accessible to superadmins.
54-
"""
55-
56-
57-
if __name__ == "__main__":
58-
unittest.main()
6+
from ibutsu_client.models.project import Project
7+
from ibutsu_client.models.project_list import ProjectList
8+
9+
10+
class TestAdminProjectManagementApi:
11+
"""AdminProjectManagementApi Tests"""
12+
13+
def test_admin_add_project(self, mock_api_client, mock_rest_response):
14+
"""Test case for admin_add_project"""
15+
api = AdminProjectManagementApi(api_client=mock_api_client)
16+
project_id = uuid4()
17+
project_data = {
18+
"id": str(project_id),
19+
"name": "New Project",
20+
"title": "New Project Title",
21+
}
22+
23+
# Mock the API response
24+
mock_response = mock_rest_response(data=project_data, status=201)
25+
mock_api_client.call_api.return_value = mock_response
26+
27+
# Call the API
28+
new_project = Project(name="New Project", title="New Project Title")
29+
response = api.admin_add_project(project=new_project)
30+
31+
# Verify result
32+
assert isinstance(response, Project)
33+
assert str(response.id) == str(project_id)
34+
assert response.name == "New Project"
35+
36+
# Verify call
37+
mock_api_client.call_api.assert_called_once()
38+
args, _ = mock_api_client.call_api.call_args
39+
assert args[0] == "POST"
40+
assert args[1].endswith("/admin/project")
41+
42+
def test_admin_delete_project(self, mock_api_client, mock_rest_response):
43+
"""Test case for admin_delete_project"""
44+
api = AdminProjectManagementApi(api_client=mock_api_client)
45+
project_id = uuid4()
46+
47+
# Mock the API response
48+
mock_response = mock_rest_response(status=200)
49+
mock_api_client.call_api.return_value = mock_response
50+
51+
# Call the API
52+
api.admin_delete_project(id=project_id)
53+
54+
# Verify call
55+
mock_api_client.call_api.assert_called_once()
56+
args, _ = mock_api_client.call_api.call_args
57+
assert args[0] == "DELETE"
58+
assert args[1].endswith(f"/admin/project/{project_id}")
59+
60+
def test_admin_get_project(self, mock_api_client, mock_rest_response):
61+
"""Test case for admin_get_project"""
62+
api = AdminProjectManagementApi(api_client=mock_api_client)
63+
project_id = uuid4()
64+
project_data = {
65+
"id": str(project_id),
66+
"name": "My Project",
67+
}
68+
69+
# Mock the API response
70+
mock_response = mock_rest_response(data=project_data, status=200)
71+
mock_api_client.call_api.return_value = mock_response
72+
73+
# Call the API
74+
response = api.admin_get_project(id=project_id)
75+
76+
# Verify result
77+
assert isinstance(response, Project)
78+
assert str(response.id) == str(project_id)
79+
assert response.name == "My Project"
80+
81+
# Verify call
82+
mock_api_client.call_api.assert_called_once()
83+
args, _ = mock_api_client.call_api.call_args
84+
assert args[0] == "GET"
85+
assert args[1].endswith(f"/admin/project/{project_id}")
86+
87+
def test_admin_get_project_list(self, mock_api_client, mock_rest_response):
88+
"""Test case for admin_get_project_list"""
89+
api = AdminProjectManagementApi(api_client=mock_api_client)
90+
91+
project_list_data = {
92+
"projects": [
93+
{"id": str(uuid4()), "name": "Project 1"},
94+
{"id": str(uuid4()), "name": "Project 2"},
95+
],
96+
"pagination": {"page": 1, "pageSize": 25, "totalItems": 2, "totalPages": 1},
97+
}
98+
99+
# Mock the API response
100+
mock_response = mock_rest_response(data=project_list_data, status=200)
101+
mock_api_client.call_api.return_value = mock_response
102+
103+
# Call the API
104+
response = api.admin_get_project_list(page=1, page_size=25)
105+
106+
# Verify result
107+
assert isinstance(response, ProjectList)
108+
assert len(response.projects) == 2
109+
assert response.projects[0].name == "Project 1"
110+
111+
# Verify call
112+
mock_api_client.call_api.assert_called_once()
113+
args, _ = mock_api_client.call_api.call_args
114+
assert args[0] == "GET"
115+
assert "/admin/project" in args[1]
116+
assert "page=1" in args[1]
117+
assert "pageSize=25" in args[1]
118+
119+
def test_admin_update_project(self, mock_api_client, mock_rest_response):
120+
"""Test case for admin_update_project"""
121+
api = AdminProjectManagementApi(api_client=mock_api_client)
122+
project_id = uuid4()
123+
project_data = {
124+
"id": str(project_id),
125+
"name": "Updated Project",
126+
}
127+
128+
# Mock the API response
129+
mock_response = mock_rest_response(data=project_data, status=200)
130+
mock_api_client.call_api.return_value = mock_response
131+
132+
# Call the API
133+
update_project = Project(name="Updated Project")
134+
response = api.admin_update_project(id=project_id, project=update_project)
135+
136+
# Verify result
137+
assert isinstance(response, Project)
138+
assert str(response.id) == str(project_id)
139+
assert response.name == "Updated Project"
140+
141+
# Verify call
142+
mock_api_client.call_api.assert_called_once()
143+
args, _ = mock_api_client.call_api.call_args
144+
assert args[0] == "PUT"
145+
assert args[1].endswith(f"/admin/project/{project_id}")

0 commit comments

Comments
 (0)