Ejemplo n.º 1
0
 def testGETArgs(self):
     r = Responses()
     rest = restlib.RestService('http://www.example.com')
     rest.conn = MockHTTPConnection(r)
     for k, v in r.ARGS.iteritems():
         responseObj = rest.request_get("/has/args", args=eval(k))
         self.assertEquals(responseObj, v)
Ejemplo n.º 2
0
 def testPOST(self):
     r = Responses()
     rest = restlib.RestService('http://www.example.com')
     rest.conn = MockHTTPConnection(r)
     for k, v in r.POST.iteritems():
         responseObj = rest.request_post(k, body = v[2], args = v[3])
         self.assertEquals(responseObj, v[1])
Ejemplo n.º 3
0
 def testGET(self):
     r = Responses()
     rest = restlib.RestService('http://www.example.com')
     rest.conn = MockHTTPConnection(r)       
     for k, v in r.GET.iteritems():
         responseObj = rest.request_get(k)
         self.assertEquals(responseObj, v[1])
Ejemplo n.º 4
0
 def testGETQuery(self):
     """Ensure that GET works when given a query."""
     rest = restlib.RestService('www.reddit.com')
     resource = '/user/sure_ill_draw_that/.json'
     responseObjControversial = rest.request_get(resource,
                                                 {'sort': 'controversial'})
     responseObjTop = rest.request_get(resource, {'sort': 'top'})
     self.assertNotEqual(responseObjControversial, responseObjTop,
                         'controversial should not equal top!')
Ejemplo n.º 5
0
 def testDoNotUseSSLByParam(self):
     rest = restlib.RestService('http://www.example.com', secure=False)
     self.assertFalse(isinstance(rest.conn, httplib.HTTPSConnection), "No SSL by param uses HTTPSConnection")
Ejemplo n.º 6
0
 def testUseSSLByParam(self):
     rest = restlib.RestService('https://www.example.com', secure=True)
     self.assertTrue(isinstance(rest.conn, httplib.HTTPSConnection), "SSL by param does not use HTTPSConnection")
Ejemplo n.º 7
0
 def testNotFoundNoJSONResponse(self):
     r = Responses()
     rest = restlib.RestService('http://www.example.com')
     rest.conn = MockHTTPConnection(r)
     self.assertRaises(restlib.HTTPException, rest.request, '/file_not_found_no_json', verb="GET_TEST")
Ejemplo n.º 8
0
 def testNoJSON(self):
     r = Responses()
     rest = restlib.RestService('http://www.example.com')
     rest.conn = MockHTTPConnection(r) 
     self.assertRaises(restlib.JSONException, rest.request, "/noJSON", verb="GET_TEST")
Ejemplo n.º 9
0
 def testForbiddenPOST(self):
     r = Responses()
     rest = restlib.RestService('http://www.example.com')
     rest.conn = MockHTTPConnection(r)
     self.assertRaises(restlib.HTTPException, rest.request_post, '/403') 
Ejemplo n.º 10
0
 def testNotFoundPOST(self):
     r = Responses()
     rest = restlib.RestService('http://www.example.com')
     rest.conn = MockHTTPConnection(r)
     self.assertRaises(restlib.HTTPException, rest.request_post, '/file_not_found')
Ejemplo n.º 11
0
 def testBadRequest(self):
     r = Responses()
     rest = restlib.RestService('http://www.example.com')
     rest.conn = MockHTTPConnection(r)
     self.assertRaises(restlib.HTTPException, rest.request_get, '/400')
Ejemplo n.º 12
0
 def testGETNonRooted(self):
     """Ensure that GET works even without a rooted resource."""
     rest = restlib.RestService('www.reddit.com')
     responseObj = rest.request_get('user/sure_ill_draw_that/.json')
Ejemplo n.º 13
0
 def testGETTrailingSlash(self):
     """Ensure that GET works with a trailing slash."""
     rest = restlib.RestService('www.reddit.com/')
     responseObj = rest.request_get('/user/sure_illasdfdfs_draw_that/.json')
Ejemplo n.º 14
0
 def testGETWithScheme(self):
     """Ensure that GET works when used with a protocol."""
     rest = restlib.RestService('http://www.reddit.com')
     responseObj = rest.request_get('/user/sure_ill_draw_that/.json')