# See the NOTICE for more information. from __future__ import with_statement import os from StringIO import StringIO import tempfile dirname = os.path.dirname(__file__) from restkit.parser import Parser from restkit.client import HttpConnection from restkit.resource import Resource from _server_test import HOST, PORT, run_server_test run_server_test() def data_source(fname): buf = StringIO() with open(fname) as handle: lines = [] for line in handle: line = line.rstrip("\n").replace("\\r\\n", "\r\n") buf.write(line) return buf class request(object): def __init__(self, name): self.fname = os.path.join(dirname, "requests", name) def __call__(self, func):
def setUp(self): run_server_test() self.transport = transport = HTTPLib2Transport() self.url = 'http://%s:%s' % (HOST, PORT) self.res = Resource(self.url, transport)
def bad_post(): result = self.res.post( '/json', payload=content, headers={'Content-Type': 'application/json'}) self.assertRaises(RequestError, bad_post) def testAuth(self): transport = HTTPLib2Transport() transport.add_credentials("test", "test") res = Resource(self.url, transport) result = res.get('/auth') self.assert_(res.response.status == 200) transport = HTTPLib2Transport() def niettest(): res = Resource(self.url, transport) result = res.get('/auth') self.assertRaises(Unauthorized, niettest) if __name__ == '__main__': from _server_test import run_server_test run_server_test() unittest.main()
def setUp(self): run_server_test() self.url = 'http://%s:%s' % (HOST, PORT) self.res = Resource(self.url, self.httptransport)