def test_request__badrequest_with_no_json_body(self, mock_session): response = mock.Mock(status_code=400) response.json.side_effect = ValueError mock_session.return_value.request = mock.Mock( side_effect=BadRequest(response=response) ) reddit = Reddit(client_id="dummy", client_secret="dummy", user_agent="dummy") with pytest.raises(Exception) as excinfo: reddit.request("POST", "/") assert str(excinfo.value).startswith("Unexpected BadRequest without json body.")
def test_request__json_and_body(self): reddit = Reddit(client_id="dummy", client_secret="dummy", user_agent="dummy") with pytest.raises(ClientException) as excinfo: reddit.request( method="POST", path="/", data={"key": "value"}, json={"key": "value"}, ) assert str(excinfo.value).startswith( "At most one of `data` and `json` is supported." )
def test_request__badrequest_with_no_json_body(self, mock_session): response = mock.Mock(status_code=400, text="") response.json.side_effect = ValueError mock_session.return_value.request = mock.Mock(side_effect=BadRequest( response=response)) reddit = Reddit(client_id="dummy", client_secret="dummy", user_agent="dummy") with pytest.raises(Exception) as excinfo: reddit.request("POST", "/") assert str(excinfo.value) == "received 400 HTTP response"