Exemplo n.º 1
0
    def test_pickle(self) -> None:
        err = client.ClientResponseError(request_info=self.request_info,
                                         history=())
        for proto in range(pickle.HIGHEST_PROTOCOL + 1):
            pickled = pickle.dumps(err, proto)
            err2 = pickle.loads(pickled)
            assert err2.request_info == self.request_info
            assert err2.history == ()
            assert err2.status == 0
            assert err2.message == ''
            assert err2.headers is None

        err = client.ClientResponseError(request_info=self.request_info,
                                         history=(),
                                         status=400,
                                         message='Something wrong',
                                         headers={})
        err.foo = 'bar'
        for proto in range(pickle.HIGHEST_PROTOCOL + 1):
            pickled = pickle.dumps(err, proto)
            err2 = pickle.loads(pickled)
            assert err2.request_info == self.request_info
            assert err2.history == ()
            assert err2.status == 400
            assert err2.message == 'Something wrong'
            assert err2.headers == {}
            assert err2.foo == 'bar'
Exemplo n.º 2
0
    def test_repr(self) -> None:
        err = client.ClientResponseError(request_info=self.request_info,
                                         history=())
        assert repr(err) == ("ClientResponseError(%r, ())" %
                             (self.request_info, ))

        err = client.ClientResponseError(request_info=self.request_info,
                                         history=(),
                                         status=400,
                                         message='Something wrong',
                                         headers={})
        assert repr(err) == ("ClientResponseError(%r, (), status=400, "
                             "message='Something wrong', headers={})" %
                             (self.request_info, ))
Exemplo n.º 3
0
 def test_str(self) -> None:
     err = client.ClientResponseError(request_info=self.request_info,
                                      history=(),
                                      status=400,
                                      message='Something wrong',
                                      headers={})
     assert str(err) == ("400, message='Something wrong', "
                         "url='http://example.com'")
Exemplo n.º 4
0
def test_response_deprecated_code_property() -> None:
    with pytest.warns(DeprecationWarning):
        err = client.ClientResponseError(code=400,
                                         history=None,
                                         request_info=None)
    with pytest.warns(DeprecationWarning):
        assert err.code == err.status
    with pytest.warns(DeprecationWarning):
        err.code = '404'
    with pytest.warns(DeprecationWarning):
        assert err.code == err.status
Exemplo n.º 5
0
def test_response_deprecated_code_property() -> None:
    request_info = mock.Mock(real_url='http://example.com')
    with pytest.warns(DeprecationWarning):
        err = client.ClientResponseError(code=400,
                                         history=None,
                                         request_info=request_info)
    with pytest.warns(DeprecationWarning):
        assert err.code == err.status
    with pytest.warns(DeprecationWarning):
        err.code = '404'
    with pytest.warns(DeprecationWarning):
        assert err.code == err.status
Exemplo n.º 6
0
def test_response_status() -> None:
    err = client.ClientResponseError(status=400,
                                     history=None,
                                     request_info=None)
    assert err.status == 400
Exemplo n.º 7
0
 def test_status(self) -> None:
     err = client.ClientResponseError(status=400,
                                      history=(),
                                      request_info=self.request_info)
     assert err.status == 400
Exemplo n.º 8
0
def test_response_both_code_and_status() -> None:
    with pytest.raises(ValueError):
        client.ClientResponseError(code=400,
                                   status=400,
                                   history=None,
                                   request_info=None)
Exemplo n.º 9
0
def test_response_status() -> None:
    request_info = mock.Mock(real_url='http://example.com')
    err = client.ClientResponseError(status=400,
                                     history=None,
                                     request_info=request_info)
    assert err.status == 400
Exemplo n.º 10
0
def test_response_default_status():
    err = client.ClientResponseError(history=None,
                                     request_info=None)
    assert err.status == 0