示例#1
0
文件: httpurl.py 项目: cyberj/pulsar
 def test_Cookie(self):
     http = self.client()
     # First set the cookies
     r = make_async(http.get(self.httpbin('cookies', 'set', 'bla', 'foo')))
     yield r
     r = r.result
     self.assertEqual(r.status_code, 200)
     self.assertTrue(r.history)
     self.assertTrue(r.history[0].headers['set-cookie'])
     # Now check if I get them
     r = make_async(http.get(self.httpbin('cookies')))
     yield r
     r = r.result
     self.assertEqual(r.status_code, 200)
     result = r.content_json()
     self.assertTrue(result['cookies'])
     self.assertEqual(result['cookies']['bla'],'foo')
     # Try without saving cookies
     http = self.client(store_cookies=False)
     r = make_async(http.get(self.httpbin('cookies', 'set', 'bla', 'foo')))
     yield r
     r = r.result
     self.assertEqual(r.status_code, 200)
     self.assertTrue(r.history)
     self.assertTrue(r.history[0].headers['set-cookie'])
     r = make_async(http.get(self.httpbin('cookies')))
     yield r
     r = r.result
     self.assertEqual(r.status_code, 200)
     result = r.content_json()
     self.assertFalse(result['cookies'])
示例#2
0
文件: httpurl.py 项目: cyberj/pulsar
 def test_digest_authentication(self):
     http = self.client()
     r = make_async(http.get(self.httpbin('digest-auth/auth/bla/foo')))
     yield r
     r = r.result
     self.assertEqual(r.status_code, 401)
     http.add_digest_authentication('bla', 'foo')
     r = make_async(http.get(self.httpbin('digest-auth/auth/bla/foo')))
     yield r
     r = r.result
     self.assertEqual(r.status_code, 200)
示例#3
0
文件: deferred.py 项目: cyberj/pulsar
 def testDeferredErrorbackInGenerator(self):
     d = Deferred()
     ioloop = IOLoop()
     # Add a callback which returns a deferred
     rd = Cbk()
     d.add_callback(lambda r : rd.add(r))
     d.add_callback(lambda r : r + ('second',))
     def _gen():
         yield d
     a = make_async(_gen())
     result = d.callback('ciao')
     self.assertTrue(d.called)
     self.assertEqual(d.paused, 1)
     # The generator has added its consume callback
     self.assertEqual(len(d._callbacks), 2)
     self.assertEqual(len(rd._callbacks), 1)
     #
     self.assertEqual(rd.r, ('ciao',))
     self.assertFalse(a.called)
     #
     # set Error back
     rd.set_error()
     self.assertFalse(d.paused)
     self.assertTrue(a.called)
     self.assertTrue(is_failure(d.result))
示例#4
0
文件: httpurl.py 项目: cyberj/pulsar
 def test_expect(self):
     http = self.client()
     data = (('bla', 'foo'), ('unz', 'whatz'),
             ('numero', '1'), ('numero', '2'))
     bdata = urlencode(data)
     r = make_async(http.post(self.httpbin('post'), data=b'',
                              headers=[('expect','100-continue'),
                                       ('Content-length', str(len(bdata)))]))
     yield r
     response = r.result
     self.assertEqual(response.status_code, 100)
     r = make_async(response.write(bdata))
     yield r
     response = r.result
     self.assertEqual(response.status_code, 200)
     self.assertEqual(response.connection, None)
示例#5
0
文件: httpurl.py 项目: cyberj/pulsar
 def testRedirect(self):
     http = self.client()
     r = make_async(http.get(self.httpbin('redirect', '1')))
     yield r
     r = r.result
     self.assertEqual(r.status_code, 200)
     history = r.request.history
     self.assertEqual(len(history), 1)
     self.assertTrue(history[0].url.endswith('/redirect/1'))
示例#6
0
文件: httpurl.py 项目: cyberj/pulsar
 def testResponseHeaders(self):
     http = self.client()
     r = make_async(http.get(self.httpbin('response-headers')))
     yield r
     r = r.result
     self.assertEqual(r.status_code, 200)
     result = r.content_json()
     self.assertEqual(result['Transfer-Encoding'], 'chunked')
     parser = r.parser
     self.assertTrue(parser.is_chunked())
示例#7
0
文件: httpurl.py 项目: cyberj/pulsar
 def test_404_get(self):
     '''Not Found 404'''
     http = self.client()
     r = make_async(http.get(self.httpbin('status', '404')))
     yield r
     r = r.result
     self.assertEqual(r.status_code, 404)
     self.assertEqual(r.response, 'Not Found')
     self.assertTrue(r.content)
     self.assertRaises(httpurl.HTTPError, r.raise_for_status)
示例#8
0
文件: httpurl.py 项目: cyberj/pulsar
 def test_400_get(self):
     '''Bad request 400'''
     http = self.client()
     r = make_async(http.get(self.httpbin('status', '400')))
     yield r
     r = r.result
     self.assertEqual(r.status_code, 400)
     self.assertEqual(r.response, 'Bad Request')
     self.assertTrue(r.content)
     self.assertRaises(httpurl.HTTPError, r.raise_for_status)
示例#9
0
文件: httpurl.py 项目: cyberj/pulsar
 def test_200_gzip(self):
     http = self.client()
     r = make_async(http.get(self.httpbin('gzip')))
     yield r
     r = r.result
     headers = r.headers
     self.assertEqual(r.status_code, 200)
     self.assertEqual(r.response, 'OK')
     content = r.content_json()
     self.assertTrue(content['gzipped'])
     self.assertTrue(r.headers['content-encoding'],'gzip')
示例#10
0
文件: httpurl.py 项目: cyberj/pulsar
 def test_200_get_data(self):
     http = self.client()
     r = make_async(http.get(self.httpbin('get',''), data={'bla':'foo'}))
     yield r
     r = r.result
     self.assertEqual(r.status_code, 200)
     self.assertEqual(r.response, 'OK')
     result = r.content_json()
     self.assertEqual(result['args'], {'bla':['foo']})
     self.assertEqual(r.url,
             self.httpbin(httpurl.iri_to_uri('get/',{'bla':'foo'})))
示例#11
0
文件: httpurl.py 项目: cyberj/pulsar
 def test_200_get(self):
     http = self.client()
     r = make_async(http.get(self.httpbin()))
     yield r
     r = r.result
     self.assertEqual(str(r), '200 OK')
     self.assertEqual(repr(r), 'HttpResponse(200 OK)')
     self.assertEqual(r.client, http)
     self.assertEqual(r.status_code, 200)
     self.assertEqual(r.response, 'OK')
     self.assertTrue(r.content)
     self.assertEqual(r.url, self.httpbin())
示例#12
0
 def on_connect(self, request):
     "Initialize the connection, authenticate and select a database"
     client = request.client.client
     cmnd = None
     if self.password:
         cmnd = self.request(client, 'AUTH', self.password,
                             release_connection=False).execute()\
                    .add_errback(lambda r: self.connection_error(r,
                                                     'Invalid Password'))
     if self.db:
         cmnd = make_async(cmnd)
         cmnd.add_callback(
             lambda r: self.request(client, 'SELECT', self.db,
                                    release_connection=False).execute(),
             lambda r: self.connection_error(r, 'Invalid Database'))
     return cmnd
示例#13
0
文件: deferred.py 项目: cyberj/pulsar
 def testDeferredCallbackInGenerator(self):
     d = Deferred()
     ioloop = IOLoop()
     # Add a callback which returns a deferred
     rd = Cbk()
     d.add_callback(lambda r : rd.add(r))
     d.add_callback(lambda r : r + ('second',))
     def _gen():
         yield d
     a = make_async(_gen())
     result = d.callback('ciao')
     self.assertTrue(d.called)
     self.assertEqual(d.paused,1)
     self.assertEqual(len(d._callbacks), 2)
     self.assertEqual(len(rd._callbacks), 1)
     #
     self.assertEqual(rd.r, ('ciao',))
     self.assertFalse(a.called)
     #
     # set callback
     rd.set_result('luca')
     self.assertTrue(a.called)
     self.assertFalse(d.paused)
     self.assertEqual(d.result,('ciao','luca','second'))
示例#14
0
文件: httpurl.py 项目: cyberj/pulsar
 def test_stream_response(self):
     http = self.client()
     r = make_async(http.get(self.httpbin('stream/3000/20')))
     yield r
     r = r.result
     self.assertEqual(r.status_code, 200)
示例#15
0
文件: httpurl.py 项目: cyberj/pulsar
 def testLargeResponse(self):
     http = self.client()
     r = make_async(http.get(self.httpbin('getsize/600000')))
     yield r
     r = r.result
     self.assertEqual(r.status_code, 200)
示例#16
0
文件: httpurl.py 项目: cyberj/pulsar
def request(r):
    return make_async(r).addBoth(request_callback)