16
16
# You should have received a copy of the GNU Lesser General Public License
17
17
# along with this program. If not, see <http://www.gnu.org/licenses/>.
18
18
19
+ import json
19
20
import os
20
21
import pickle
21
22
import tempfile
22
- import json
23
23
import unittest
24
24
25
+ import requests
25
26
from httmock import HTTMock # noqa
26
27
from httmock import response # noqa
27
28
from httmock import urlmatch # noqa
28
- import requests
29
29
30
30
import gitlab
31
31
from gitlab import * # noqa
32
32
from gitlab .v4 .objects import * # noqa
33
33
34
-
35
34
valid_config = b"""[global]
36
35
default = one
37
36
ssl_verify = true
@@ -58,86 +57,6 @@ def test_dict(self):
58
57
self .assertEqual (expected , gitlab ._sanitize (source ))
59
58
60
59
61
- class TestGitlabList (unittest .TestCase ):
62
- def setUp (self ):
63
- self .gl = Gitlab (
64
- "http://localhost" , private_token = "private_token" , api_version = 4
65
- )
66
-
67
- def test_build_list (self ):
68
- @urlmatch (scheme = "http" , netloc = "localhost" , path = "/api/v4/tests" , method = "get" )
69
- def resp_1 (url , request ):
70
- headers = {
71
- "content-type" : "application/json" ,
72
- "X-Page" : 1 ,
73
- "X-Next-Page" : 2 ,
74
- "X-Per-Page" : 1 ,
75
- "X-Total-Pages" : 2 ,
76
- "X-Total" : 2 ,
77
- "Link" : (
78
- "<http://localhost/api/v4/tests?per_page=1&page=2>;" ' rel="next"'
79
- ),
80
- }
81
- content = '[{"a": "b"}]'
82
- return response (200 , content , headers , None , 5 , request )
83
-
84
- @urlmatch (
85
- scheme = "http" ,
86
- netloc = "localhost" ,
87
- path = "/api/v4/tests" ,
88
- method = "get" ,
89
- query = r".*page=2" ,
90
- )
91
- def resp_2 (url , request ):
92
- headers = {
93
- "content-type" : "application/json" ,
94
- "X-Page" : 2 ,
95
- "X-Next-Page" : 2 ,
96
- "X-Per-Page" : 1 ,
97
- "X-Total-Pages" : 2 ,
98
- "X-Total" : 2 ,
99
- }
100
- content = '[{"c": "d"}]'
101
- return response (200 , content , headers , None , 5 , request )
102
-
103
- with HTTMock (resp_1 ):
104
- obj = self .gl .http_list ("/tests" , as_list = False )
105
- self .assertEqual (len (obj ), 2 )
106
- self .assertEqual (
107
- obj ._next_url , "http://localhost/api/v4/tests?per_page=1&page=2"
108
- )
109
- self .assertEqual (obj .current_page , 1 )
110
- self .assertEqual (obj .prev_page , None )
111
- self .assertEqual (obj .next_page , 2 )
112
- self .assertEqual (obj .per_page , 1 )
113
- self .assertEqual (obj .total_pages , 2 )
114
- self .assertEqual (obj .total , 2 )
115
-
116
- with HTTMock (resp_2 ):
117
- l = list (obj )
118
- self .assertEqual (len (l ), 2 )
119
- self .assertEqual (l [0 ]["a" ], "b" )
120
- self .assertEqual (l [1 ]["c" ], "d" )
121
-
122
- def test_all_omitted_when_as_list (self ):
123
- @urlmatch (scheme = "http" , netloc = "localhost" , path = "/api/v4/tests" , method = "get" )
124
- def resp (url , request ):
125
- headers = {
126
- "content-type" : "application/json" ,
127
- "X-Page" : 2 ,
128
- "X-Next-Page" : 2 ,
129
- "X-Per-Page" : 1 ,
130
- "X-Total-Pages" : 2 ,
131
- "X-Total" : 2 ,
132
- }
133
- content = '[{"c": "d"}]'
134
- return response (200 , content , headers , None , 5 , request )
135
-
136
- with HTTMock (resp ):
137
- result = self .gl .http_list ("/tests" , as_list = False , all = True )
138
- self .assertIsInstance (result , GitlabList )
139
-
140
-
141
60
class TestGitlabHttpMethods (unittest .TestCase ):
142
61
def setUp (self ):
143
62
self .gl = Gitlab (
0 commit comments