|
22 | 22 | importunittest
|
23 | 23 | exceptImportError:
|
24 | 24 | importunittest2asunittest
|
| 25 | +importjson |
25 | 26 |
|
26 | 27 | fromhttmockimportHTTMock# noqa
|
27 | 28 | fromhttmockimportresponse# noqa
|
@@ -178,6 +179,56 @@ def resp_cont(url, request):
|
178 | 179 | self.assertEqual(data.project_id,1)
|
179 | 180 | self.assertEqual(data.ref,"a")
|
180 | 181 |
|
| 182 | +deftest_list_next_link(self): |
| 183 | +@urlmatch(scheme="http",netloc="localhost", |
| 184 | +path='/api/v3/projects/1/repository/branches',method="get", |
| 185 | +query=r'per_page=1') |
| 186 | +defresp_one(url,request): |
| 187 | +""" |
| 188 | + First request: |
| 189 | + http://localhost/api/v3/projects/1/repository/branches?per_page=1 |
| 190 | + """ |
| 191 | +headers= { |
| 192 | +'content-type':'application/json', |
| 193 | +'link':'<http://localhost/api/v3/projects/1/repository/branc' \ |
| 194 | +'hes?page=2&per_page=0>; rel="next", <http://localhost/api/v3' \ |
| 195 | +'/projects/1/repository/branches?page=2&per_page=0>; rel="las' \ |
| 196 | +'t", <http://localhost/api/v3/projects/1/repository/branches?' \ |
| 197 | +'page=1&per_page=0>; rel="first"' |
| 198 | + } |
| 199 | +content= ('[{"branch_name": "otherbranch", ' |
| 200 | +'"project_id": 1, "ref": "b"}]').encode("utf-8") |
| 201 | +resp=response(200,content,headers,None,5,request) |
| 202 | +returnresp |
| 203 | + |
| 204 | +@urlmatch(scheme="http",netloc="localhost", |
| 205 | +path='/api/v3/projects/1/repository/branches',method="get", |
| 206 | +query=r'.*page=2.*') |
| 207 | +defresp_two(url,request): |
| 208 | +headers= { |
| 209 | +'content-type':'application/json', |
| 210 | +'link':'<http://localhost/api/v3/projects/1/repository/branc' \ |
| 211 | +'hes?page=1&per_page=0>; rel="prev", <http://localhost/api/v3' \ |
| 212 | +'/projects/1/repository/branches?page=2&per_page=0>; rel="las' \ |
| 213 | +'t", <http://localhost/api/v3/projects/1/repository/branches?' \ |
| 214 | +'page=1&per_page=0>; rel="first"' |
| 215 | + } |
| 216 | +content= ('[{"branch_name": "testbranch", ' |
| 217 | +'"project_id": 1, "ref": "a"}]').encode("utf-8") |
| 218 | +resp=response(200,content,headers,None,5,request) |
| 219 | +returnresp |
| 220 | + |
| 221 | +withHTTMock(resp_one,resp_two): |
| 222 | +data=self.gl.list(ProjectBranch,project_id=1, |
| 223 | +per_page=1) |
| 224 | +self.assertEqual(data[1].branch_name,"testbranch") |
| 225 | +self.assertEqual(data[1].project_id,1) |
| 226 | +self.assertEqual(data[1].ref,"a") |
| 227 | +self.assertEqual(data[0].branch_name,"otherbranch") |
| 228 | +self.assertEqual(data[0].project_id,1) |
| 229 | +self.assertEqual(data[0].ref,"b") |
| 230 | +self.assertEqual(len(data),2) |
| 231 | + |
181 | 232 | deftest_list_401(self):
|
182 | 233 | @urlmatch(scheme="http",netloc="localhost",
|
183 | 234 | path="/api/v3/projects/1/repository/branches",method="get")
|
|