55import pytest
66import responses
77
8- from gitlab .v4 .objects import Project
8+ from gitlab .v4 .objects import (
9+ Project ,
10+ ProjectFork ,
11+ ProjectUser ,
12+ StarredProject ,
13+ UserProject ,
14+ )
915
1016project_content = {"name" :"name" ,"id" :1 }
17+ languages_content = {
18+ "python" :80.00 ,
19+ "ruby" :99.99 ,
20+ "CoffeeScript" :0.01 ,
21+ }
22+ user_content = {
23+ "name" :"first" ,
24+ "id" :1 ,
25+ "state" :"active" ,
26+ }
27+ forks_content = [
28+ {
29+ "id" :1 ,
30+ },
31+ {
32+ "id" :"python-gitlab%2Fpython-gitlab" ,
33+ },
34+ ]
1135import_content = {
1236"id" :1 ,
1337"name" :"project" ,
@@ -28,6 +52,106 @@ def resp_get_project():
2852yield rsps
2953
3054
55+ @pytest .fixture
56+ def resp_user_projects ():
57+ with responses .RequestsMock ()as rsps :
58+ rsps .add (
59+ method = responses .GET ,
60+ url = "http://localhost/api/v4/users/1" ,
61+ json = user_content ,
62+ content_type = "application/json" ,
63+ status = 200 ,
64+ )
65+ rsps .add (
66+ method = responses .GET ,
67+ url = "http://localhost/api/v4/users/1/projects" ,
68+ json = [project_content ],
69+ content_type = "application/json" ,
70+ status = 200 ,
71+ )
72+ yield rsps
73+
74+
75+ @pytest .fixture
76+ def resp_starred_projects ():
77+ with responses .RequestsMock ()as rsps :
78+ rsps .add (
79+ method = responses .GET ,
80+ url = "http://localhost/api/v4/users/1" ,
81+ json = user_content ,
82+ content_type = "application/json" ,
83+ status = 200 ,
84+ )
85+ rsps .add (
86+ method = responses .GET ,
87+ url = "http://localhost/api/v4/users/1/starred_projects" ,
88+ json = [project_content ],
89+ content_type = "application/json" ,
90+ status = 200 ,
91+ )
92+ yield rsps
93+
94+
95+ @pytest .fixture
96+ def resp_list_users ():
97+ with responses .RequestsMock ()as rsps :
98+ rsps .add (
99+ method = responses .GET ,
100+ url = "http://localhost/api/v4/projects/1" ,
101+ json = project_content ,
102+ content_type = "application/json" ,
103+ status = 200 ,
104+ )
105+ rsps .add (
106+ method = responses .GET ,
107+ url = "http://localhost/api/v4/projects/1/users" ,
108+ json = [user_content ],
109+ content_type = "application/json" ,
110+ status = 200 ,
111+ )
112+ yield rsps
113+
114+
115+ @pytest .fixture
116+ def resp_list_forks ():
117+ with responses .RequestsMock ()as rsps :
118+ rsps .add (
119+ method = responses .GET ,
120+ url = "http://localhost/api/v4/projects/1" ,
121+ json = project_content ,
122+ content_type = "application/json" ,
123+ status = 200 ,
124+ )
125+ rsps .add (
126+ method = responses .GET ,
127+ url = "http://localhost/api/v4/projects/1/forks" ,
128+ json = forks_content ,
129+ content_type = "application/json" ,
130+ status = 200 ,
131+ )
132+ yield rsps
133+
134+
135+ @pytest .fixture
136+ def resp_list_languages ():
137+ with responses .RequestsMock ()as rsps :
138+ rsps .add (
139+ method = responses .GET ,
140+ url = "http://localhost/api/v4/projects/1" ,
141+ json = project_content ,
142+ content_type = "application/json" ,
143+ status = 200 ,
144+ )
145+ rsps .add (
146+ method = responses .GET ,
147+ url = "http://localhost/api/v4/projects/1/languages" ,
148+ json = languages_content ,
149+ content_type = "application/json" ,
150+ status = 200 ,
151+ )
152+ yield rsps
153+
154+
31155@pytest .fixture
32156def resp_list_projects ():
33157with responses .RequestsMock ()as rsps :
@@ -98,19 +222,26 @@ def test_import_bitbucket_server(gl, resp_import_bitbucket_server):
98222assert res ["import_status" ]== "scheduled"
99223
100224
101- @pytest .mark .skip (reason = "missing test" )
102- def test_list_user_projects (gl ):
103- pass
225+ def test_list_user_projects (gl ,resp_user_projects ):
226+ user_project = gl .users .get (1 ).projects .list ()[0 ]
227+ assert isinstance (user_project ,UserProject )
228+ assert user_project .name == "name"
229+ assert user_project .id == 1
104230
105231
106- @pytest .mark .skip (reason = "missing test" )
107- def test_list_user_starred_projects (gl ):
108- pass
232+ def test_list_user_starred_projects (gl ,resp_starred_projects ):
233+ starred_projects = gl .users .get (1 ).starred_projects .list ()[0 ]
234+ assert isinstance (starred_projects ,StarredProject )
235+ assert starred_projects .name == "name"
236+ assert starred_projects .id == 1
109237
110238
111- @pytest .mark .skip (reason = "missing test" )
112- def test_list_project_users (gl ):
113- pass
239+ def test_list_project_users (gl ,resp_list_users ):
240+ user = gl .projects .get (1 ).users .list ()[0 ]
241+ assert isinstance (user ,ProjectUser )
242+ assert user .id == 1
243+ assert user .name == "first"
244+ assert user .state == "active"
114245
115246
116247@pytest .mark .skip (reason = "missing test" )
@@ -133,9 +264,11 @@ def test_fork_project(gl):
133264pass
134265
135266
136- @pytest .mark .skip (reason = "missing test" )
137- def test_list_project_forks (gl ):
138- pass
267+ def test_list_project_forks (gl ,resp_list_forks ):
268+ forks = gl .projects .get (1 ).forks .list ()
269+ assert isinstance (forks [0 ],ProjectFork )
270+ assert forks [0 ].id == 1
271+ assert forks [1 ].id == "python-gitlab%2Fpython-gitlab"
139272
140273
141274@pytest .mark .skip (reason = "missing test" )
@@ -153,9 +286,13 @@ def test_list_project_starrers(gl):
153286pass
154287
155288
156- @pytest .mark .skip (reason = "missing test" )
157- def test_get_project_languages (gl ):
158- pass
289+ def test_get_project_languages (gl ,resp_list_languages ):
290+ python = gl .projects .get (1 ).languages ().get ("python" )
291+ ruby = gl .projects .get (1 ).languages ().get ("ruby" )
292+ coffee_script = gl .projects .get (1 ).languages ().get ("CoffeeScript" )
293+ assert python == 80.00
294+ assert ruby == 99.99
295+ assert coffee_script == 00.01
159296
160297
161298@pytest .mark .skip (reason = "missing test" )