Ejemplo n.º 1
0
    def test_with_malformed_json(self):
        resp = mock.Mock(text='{foo')
        with pytest.raises(InvalidRequestError) as e:
            handle_api_error(resp, 400)

        assert str(e.value) == 'None'
        assert e.value.json_body is None
Ejemplo n.º 2
0
    def test_with_malformed_json(self):
        resp = mock.Mock(text="{foo")
        with pytest.raises(InvalidRequestError) as e:
            handle_api_error(resp, 400)

        assert str(e.value) == "None"
        assert e.value.json_body is None
Ejemplo n.º 3
0
    def test_exception_info(self):
        resp = mock.Mock(text='{"message": "foo"}')
        with pytest.raises(InvalidRequestError) as e:
            handle_api_error(resp, 400)

        e = e.value
        assert str(e) == "foo"
        assert e.http_body == '{"message": "foo"}'
        assert e.http_status == 400
        assert e.json_body == {"message": "foo"}
Ejemplo n.º 4
0
    def test_exception_info(self):
        resp = mock.Mock(text='{"message": "foo"}')
        with pytest.raises(InvalidRequestError) as e:
            handle_api_error(resp, 400)

        e = e.value
        assert str(e) == 'foo'
        assert e.http_body == '{"message": "foo"}'
        assert e.http_status == 400
        assert e.json_body == {'message': 'foo'}
Ejemplo n.º 5
0
 def test_invalid_request(self):
     resp = mock.Mock(text="")
     with pytest.raises(InvalidRequestError):
         handle_api_error(resp, 404)
     with pytest.raises(InvalidRequestError):
         handle_api_error(resp, 405)
     with pytest.raises(InvalidRequestError):
         handle_api_error(resp, 409)
Ejemplo n.º 6
0
 def test_invalid_request(self):
     resp = mock.Mock(text='')
     with pytest.raises(InvalidRequestError):
         handle_api_error(resp, 404)
     with pytest.raises(InvalidRequestError):
         handle_api_error(resp, 405)
     with pytest.raises(InvalidRequestError):
         handle_api_error(resp, 409)
Ejemplo n.º 7
0
 def test_server_error(self):
     resp = mock.Mock(text="")
     with pytest.raises(ServerError):
         handle_api_error(resp, 500)
Ejemplo n.º 8
0
 def test_authentication_error(self):
     resp = mock.Mock(text="")
     with pytest.raises(AuthenticationError):
         handle_api_error(resp, 401)
Ejemplo n.º 9
0
 def test_server_error(self):
     resp = mock.Mock(text='')
     with pytest.raises(ServerError):
         handle_api_error(resp, 500)
Ejemplo n.º 10
0
 def test_authentication_error(self):
     resp = mock.Mock(text='')
     with pytest.raises(AuthenticationError):
         handle_api_error(resp, 401)