Skip to content

Commit 0ab434d

Browse files
committed
test(projects): add unit tests for projects
1 parent ca98d88 commit 0ab434d

File tree

1 file changed

+71
-9
lines changed

1 file changed

+71
-9
lines changed

tests/unit/objects/test_projects.py

Lines changed: 71 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515
from gitlab.v4.objects.projects import ProjectStorage
1616

1717
project_content = {"name": "name", "id": 1}
18+
project_for_user_1_content = {
19+
"name": "name",
20+
"id": 1,
21+
"owner": {"id": 1, "username": "owner_username", "name": "owner_name"},
22+
}
1823
languages_content = {
1924
"python": 80.00,
2025
"ruby": 99.99,
@@ -30,6 +35,12 @@
3035
"id": 1,
3136
},
3237
]
38+
forked_from_1_content = {
39+
"name": "name",
40+
"id": 2,
41+
"forks_count": 0,
42+
"forked_from_project": {"id": 1, "name": "name", "forks_count": 1},
43+
}
3344
import_content = {
3445
"id": 1,
3546
"name": "project",
@@ -50,6 +61,45 @@ def resp_get_project():
5061
yield rsps
5162

5263

64+
@pytest.fixture
65+
def resp_post_project():
66+
with responses.RequestsMock() as rsps:
67+
rsps.add(
68+
method=responses.POST,
69+
url="http://localhost/api/v4/projects",
70+
json=project_content,
71+
content_type="application/json",
72+
status=201,
73+
)
74+
yield rsps
75+
76+
77+
@pytest.fixture
78+
def resp_post_project_user():
79+
with responses.RequestsMock() as rsps:
80+
rsps.add(
81+
method=responses.POST,
82+
url="http://localhost/api/v4/projects/user/1",
83+
json=project_for_user_1_content,
84+
content_type="application/json",
85+
status=201,
86+
)
87+
yield rsps
88+
89+
90+
@pytest.fixture
91+
def resp_post_fork_project():
92+
with responses.RequestsMock() as rsps:
93+
rsps.add(
94+
method=responses.POST,
95+
url="http://localhost/api/v4/projects/1/fork",
96+
json=forked_from_1_content,
97+
content_type="application/json",
98+
status=201,
99+
)
100+
yield rsps
101+
102+
53103
@pytest.fixture
54104
def resp_get_project_storage():
55105
with responses.RequestsMock() as rsps:
@@ -220,24 +270,36 @@ def test_list_project_users(project, resp_list_users):
220270
assert user.state == "active"
221271

222272

223-
@pytest.mark.skip(reason="missing test")
224-
def test_create_project(gl):
225-
pass
273+
def test_create_project(gl, resp_post_project):
274+
project = gl.projects.create({"name": "name"})
275+
assert project.id == 1
276+
assert project.name == "name"
226277

227278

228-
@pytest.mark.skip(reason="missing test")
229-
def test_create_user_project(gl):
230-
pass
279+
def test_create_user_project(user, resp_post_project_user):
280+
user_project = user.projects.create({"name": "name"})
281+
assert user_project.id == 1
282+
assert user_project.name == "name"
283+
assert user_project.owner
284+
assert user_project.owner.get("id") == user.id
285+
assert user_project.owner.get("name") == "owner_name"
286+
assert user_project.owner.get("username") == "owner_username"
231287

232288

233289
@pytest.mark.skip(reason="missing test")
234290
def test_update_project(gl):
235291
pass
236292

237293

238-
@pytest.mark.skip(reason="missing test")
239-
def test_fork_project(gl):
240-
pass
294+
def test_fork_project(project, resp_post_fork_project):
295+
fork = project.forks.create({})
296+
assert fork.id == 2
297+
assert fork.name == "name"
298+
assert fork.forks_count == 0
299+
assert fork.forked_from_project
300+
assert fork.forked_from_project.get("id") == project.id
301+
assert fork.forked_from_project.get("name") == "name"
302+
assert fork.forked_from_project.get("forks_count") == 1
241303

242304

243305
def test_list_project_forks(project, resp_list_forks):

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy