26
26
27
27
from httmock import HTTMock # noqa
28
28
from httmock import response # noqa
29
- from httmock import remember_called , urlmatch # noqa
29
+ from httmock import urlmatch # noqa
30
30
import requests
31
31
32
32
import gitlab
@@ -57,7 +57,6 @@ def setUp(self):
57
57
def test_build_list (self ):
58
58
@urlmatch (scheme = 'http' , netloc = "localhost" , path = "/api/v4/tests" ,
59
59
method = "get" )
60
- @remember_called
61
60
def resp_1 (url , request ):
62
61
headers = {'content-type' : 'application/json' ,
63
62
'X-Page' : 1 ,
@@ -73,7 +72,6 @@ def resp_1(url, request):
73
72
74
73
@urlmatch (scheme = 'http' , netloc = "localhost" , path = "/api/v4/tests" ,
75
74
method = 'get' , query = r'.*page=2' )
76
- @remember_called
77
75
def resp_2 (url , request ):
78
76
headers = {'content-type' : 'application/json' ,
79
77
'X-Page' : 2 ,
@@ -84,7 +82,7 @@ def resp_2(url, request):
84
82
content = '[{"c": "d"}]'
85
83
return response (200 , content , headers , None , 5 , request )
86
84
87
- with HTTMock (resp_2 , resp_1 ):
85
+ with HTTMock (resp_1 ):
88
86
obj = self .gl .http_list ('/tests' , as_list = False )
89
87
self .assertEqual (len (obj ), 2 )
90
88
self .assertEqual (obj ._next_url ,
@@ -96,62 +94,11 @@ def resp_2(url, request):
96
94
self .assertEqual (obj .total_pages , 2 )
97
95
self .assertEqual (obj .total , 2 )
98
96
99
- l = list (obj )
100
- self .assertListEqual (l , [{"a" : "b" }])
101
- self .assertEqual (resp_1 .call ['count' ], 1 )
102
- self .assertFalse (resp_2 .call ['called' ])
103
-
104
- def test_build_list_all (self ):
105
- @urlmatch (scheme = 'http' , netloc = "localhost" , path = "/api/v4/tests" ,
106
- method = "get" )
107
- @remember_called
108
- def resp_1 (url , request ):
109
- headers = {'content-type' : 'application/json' ,
110
- 'X-Page' : 1 ,
111
- 'X-Next-Page' : 2 ,
112
- 'X-Per-Page' : 1 ,
113
- 'X-Total-Pages' : 2 ,
114
- 'X-Total' : 2 ,
115
- 'Link' : (
116
- '<http://localhost/api/v4/tests?per_page=1&page=2>;'
117
- ' rel="next"' )}
118
- content = '[{"a": "b"}]'
119
- return response (200 , content , headers , None , 5 , request )
120
-
121
- @urlmatch (scheme = 'http' , netloc = "localhost" , path = "/api/v4/tests" ,
122
- method = 'get' , query = r'.*page=2' )
123
- @remember_called
124
- def resp_2 (url , request ):
125
- headers = {'content-type' : 'application/json' ,
126
- 'X-Page' : 2 ,
127
- 'X-Next-Page' : 2 ,
128
- 'X-Per-Page' : 1 ,
129
- 'X-Total-Pages' : 2 ,
130
- 'X-Total' : 2 }
131
- content = '[{"c": "d"}]'
132
- return response (200 , content , headers , None , 5 , request )
133
-
134
- with HTTMock (resp_2 , resp_1 ):
135
- obj = self .gl .http_list ('/tests' , as_list = False , all = True )
136
- self .assertEqual (len (obj ), 2 )
137
- self .assertEqual (obj ._next_url ,
138
- 'http://localhost/api/v4/tests?per_page=1&page=2' )
139
- self .assertEqual (obj .current_page , 1 )
140
- self .assertEqual (obj .prev_page , None )
141
- self .assertEqual (obj .next_page , 2 )
142
- self .assertEqual (obj .per_page , 1 )
143
- self .assertEqual (obj .total_pages , 2 )
144
- self .assertEqual (obj .total , 2 )
145
- self .assertEqual (resp_1 .call ['count' ], 1 )
146
- self .assertFalse (resp_2 .call ['called' ])
147
- self .assertDictEqual (next (obj ), {"a" : "b" })
148
- self .assertEqual (resp_1 .call ['count' ], 1 )
149
- self .assertFalse (resp_2 .call ['called' ])
150
- self .assertDictEqual (next (obj ), {"c" : "d" })
151
- self .assertEqual (resp_1 .call ['count' ], 1 )
152
- self .assertEqual (resp_2 .call ['count' ], 1 )
153
- with self .assertRaises (StopIteration ):
154
- next (obj )
97
+ with HTTMock (resp_2 ):
98
+ l = list (obj )
99
+ self .assertEqual (len (l ), 2 )
100
+ self .assertEqual (l [0 ]['a' ], 'b' )
101
+ self .assertEqual (l [1 ]['c' ], 'd' )
155
102
156
103
157
104
class TestGitlabHttpMethods (unittest .TestCase ):
0 commit comments