示例#1
0
    def test_request_with_http_error(self, http_server):
        url = '%s?code=%s&response=%s' % (http_server.base_uri, 404,
                                          '{"a":"b"}')
        req = Request(Request.JSON, 'GET', url, {})

        with pytest.raises(HTTPError) as exc_info:
            with http_server:
                send_request.json_request(req, self.session)
        assert exc_info.value.code == 404
        assert exc_info.value.response == {'a': "b"}
示例#2
0
    def test_request_timeout_error(self, http_server):
        def handler(self):
            self.send_response(204)
            import time
            time.sleep(1)
            pass

        http_server.handler.do_GET = handler
        req = Request(Request.JSON, 'GET', http_server.base_uri,
                      {'timeout': 0.05})
        with http_server:
            with pytest.raises(NetworkError):
                send_request.json_request(req, self.session)
示例#3
0
    def test_json_request(self, http_server):

        url = '%s?response=%s' % (http_server.base_uri, '{"foo":"bar"}')
        req = Request(Request.JSON, 'GET', url, {})

        with http_server:
            result = send_request.json_request(req, self.session)

        assert result.get('code') is 200
        assert 'foo' in result.get('content')
        assert result.get('content').get('foo') == 'bar'
示例#4
0
 def test_no_connection_error(self, http_server):
     req = Request(Request.JSON, 'GET', 'http://not-exist.example.com', {})
     with pytest.raises(ConnectionError):
         send_request.json_request(req, self.session)