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)
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])
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])
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!')
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")
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")
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")
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")
def testForbiddenPOST(self): r = Responses() rest = restlib.RestService('http://www.example.com') rest.conn = MockHTTPConnection(r) self.assertRaises(restlib.HTTPException, rest.request_post, '/403')
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')
def testBadRequest(self): r = Responses() rest = restlib.RestService('http://www.example.com') rest.conn = MockHTTPConnection(r) self.assertRaises(restlib.HTTPException, rest.request_get, '/400')
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')
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')
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')