Пример #1
0
    def test_proxy_request_http_error(self, stderr, Request, urlopen):
        lines = []
        stderr.write.side_effect = lambda data, **kw: lines.append(data)
        request = mock.Mock()
        Request.return_value = request
        fp = mock.Mock()
        fp.read.return_value = "something went wrong"
        urlopen.side_effect = urllib2.HTTPError("/", 400, "Bad request", {}, fp)
        with self.assertRaises(SystemExit) as cm:
            admin_plugin.proxy_request(self.service_name, "/", body="waat", method="GET")
        exc = cm.exception
        self.assertEqual(1, exc.code)
        expected_output = r"""ERROR: 400 - Bad request
       something went wrong
"""
        self.assertEqual(expected_output, "".join(lines))
Пример #2
0
    def test_proxy_request_http_error(self, stderr, Request, urlopen):
        lines = []
        stderr.write.side_effect = lambda data, **kw: lines.append(data)
        request = mock.Mock()
        Request.return_value = request
        fp = mock.Mock()
        fp.read.return_value = "something went wrong"
        urlopen.side_effect = urllib2.HTTPError("/", 400, "Bad request", {}, fp)
        with self.assertRaises(SystemExit) as cm:
            admin_plugin.proxy_request(self.service_name, "/", body="waat",
                                       method="GET")
        exc = cm.exception
        self.assertEqual(1, exc.code)
        expected_output = r"""ERROR: 400 - Bad request
       something went wrong
"""
        self.assertEqual(expected_output, "".join(lines))