Exemplo n.º 1
0
 def _proxy(self, method, url, data=None, headers=None):
     if data is not None:
         data = json.dumps(data)
     status, headers, body = get_url(url, method, data, headers)
     if body:
         try:
             body = json.loads(body)
         except Exception:
             logger.error("bad json body from sreg (%s): %s" %
                                                     (url, body))
             raise  # XXX
     return status, body
Exemplo n.º 2
0
 def _proxy(self, method, url, data=None, headers=None):
     if data is not None:
         data = json.dumps(data)
     status, headers, body = get_url(url, method, data, headers)
     if body:
         try:
             body = json.loads(body)
         except ValueError:
             logger.error("bad json body from sreg (%s): %s" %
                                                     (url, body))
             raise BackendError('Bad answer from proxy')
     return status, body
Exemplo n.º 3
0
    def test_get_url(self):

        # malformed url
        self.assertRaises(ValueError, get_url, 'impossible url')

        # unknown location
        code, headers, body = get_url('http://dwqkndwqpihqdw.com',
                                      get_body=False)
        self.assertEquals(code, 502)
        self.assertTrue('Name or service not known' in body)

        # any page
        code, headers, body = get_url('http://google.com', get_body=False)
        self.assertEquals(code, 200)
        self.assertEquals(body, '')

        # page with auth failure
        code, headers, body = get_url('http://badauth',
                                      user='******',
                                      password='******')
        self.assertEquals(code, 401)

        # page with right auth
        code, headers, body = get_url('http://goodauth',
                                      user='******',
                                      password='******')
        self.assertEquals(code, 200)
        self.assertEquals(body, '{}')

        # page that times out
        code, headers, body = get_url('http://timeout', timeout=0.1)
        self.assertEquals(code, 504)

        # page that fails
        code, headers, body = get_url('http://error', get_body=False)
        self.assertEquals(code, 500)
Exemplo n.º 4
0
    def test_get_url(self):

        # malformed url
        self.assertRaises(ValueError, get_url, 'impossible url')

        # unknown location
        code, headers, body = get_url('http://dwqkndwqpihqdw.com',
                                      get_body=False)
        self.assertEquals(code, 502)
        self.assertTrue('Name or service not known' in body)

        # any page
        code, headers, body = get_url('http://google.com', get_body=False)
        self.assertEquals(code, 200)
        self.assertEquals(body, '')

        # page with auth failure
        code, headers, body = get_url('http://badauth',
                                      user='******',
                                      password='******')
        self.assertEquals(code, 401)

        # page with right auth
        code, headers, body = get_url('http://goodauth',
                                      user='******',
                                      password='******')
        self.assertEquals(code, 200)
        self.assertEquals(body, '{}')

        # page that times out
        code, headers, body = get_url('http://timeout', timeout=0.1)
        self.assertEquals(code, 504)

        # page that fails
        code, headers, body = get_url('http://error', get_body=False)
        self.assertEquals(code, 500)