@@ -1245,14 +1245,34 @@ def testDispatch(self):
12451245 self .assertEqual (status , 'ok' )
12461246
12471247 # TEST #9
1248- # GET: test that version can be set with
1249- # ; version=z or application/vnd.x.y-vz+json
1248+ # GET: test that version can be set with accept:
1249+ # ... ; version=z
1250+ # or
1251+ # application/vnd.x.y-vz+json
1252+ # or
1253+ # @apiver
12501254 # simulate: /rest/data/issue
1255+ form = cgi .FieldStorage ()
1256+ form .list = [
1257+ cgi .MiniFieldStorage ('@apiver' , 'L' ),
1258+ ]
1259+ headers = {"accept" : "application/json; notversion=z" }
1260+ self .headers = headers
1261+ self .server .client .request .headers .get = self .get_header
1262+ results = self .server .dispatch ('GET' ,
1263+ "/rest/data/issue/1" , form )
1264+ print (results )
1265+ json_dict = json .loads (b2s (results ))
1266+ self .assertEqual (json_dict ['error' ]['status' ], 400 )
1267+ self .assertEqual (json_dict ['error' ]['msg' ],
1268+ "Unrecognized version: L. See /rest without "
1269+ "specifying version for supported versions." )
1270+
12511271 headers = {"accept" : "application/json; version=z" }
12521272 self .headers = headers
12531273 self .server .client .request .headers .get = self .get_header
12541274 results = self .server .dispatch ('GET' ,
1255- "/rest/data/issue/1" , self . empty_form )
1275+ "/rest/data/issue/1" , form )
12561276 print (results )
12571277 json_dict = json .loads (b2s (results ))
12581278 self .assertEqual (json_dict ['error' ]['status' ], 400 )
@@ -1288,6 +1308,65 @@ def testDispatch(self):
12881308 "Unrecognized version: a. See /rest without "
12891309 "specifying version for supported versions." )
12901310
1311+ # TEST #10
1312+ # check /rest and /rest/summary and /rest/notthere
1313+ expected_rest = {
1314+ "data" : {
1315+ "supported_versions" : [
1316+ 1
1317+ ],
1318+ "default_version" : 1 ,
1319+ "links" : [
1320+ {
1321+ "rel" : "summary" ,
1322+ "uri" : "http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/summary"
1323+ },
1324+ {
1325+ "rel" : "self" ,
1326+ "uri" : "http://tracker.example/cgi-bin/roundup.cgi/bugs/rest"
1327+ },
1328+ {
1329+ "rel" : "data" ,
1330+ "uri" : "http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data"
1331+ }
1332+ ]
1333+ }
1334+ }
1335+
1336+ self .headers = {}
1337+ results = self .server .dispatch ('GET' ,
1338+ "/rest" , self .empty_form )
1339+ print (results )
1340+ self .assertEqual (self .server .client .response_code , 200 )
1341+ results_dict = json .loads (b2s (results ))
1342+ self .assertEqual (results_dict , expected_rest )
1343+
1344+
1345+ results = self .server .dispatch ('GET' ,
1346+ "/rest/" , self .empty_form )
1347+ print (results )
1348+ self .assertEqual (self .server .client .response_code , 200 )
1349+ results_dict = json .loads (b2s (results ))
1350+ self .assertEqual (results_dict , expected_rest )
1351+
1352+ results = self .server .dispatch ('GET' ,
1353+ "/rest/summary" , self .empty_form )
1354+ print (results )
1355+ self .assertEqual (self .server .client .response_code , 200 )
1356+
1357+ results = self .server .dispatch ('GET' ,
1358+ "/rest/summary/" , self .empty_form )
1359+ print (results )
1360+ self .assertEqual (self .server .client .response_code , 200 )
1361+
1362+ results = self .server .dispatch ('GET' ,
1363+ "/rest/notthere" , self .empty_form )
1364+ self .assertEqual (self .server .client .response_code , 404 )
1365+
1366+ results = self .server .dispatch ('GET' ,
1367+ "/rest/notthere/" , self .empty_form )
1368+ self .assertEqual (self .server .client .response_code , 404 )
1369+
12911370 del (self .headers )
12921371
12931372 def testPostPOE (self ):
0 commit comments