Skip to content

Commit

Permalink
Use 'make_exception' from 'datastore.connection.Connection._request'.
Browse files Browse the repository at this point in the history
Fixes #508.
  • Loading branch information
tseaver committed Jan 28, 2015
1 parent e80e21a commit 6f2796c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
9 changes: 3 additions & 6 deletions gcloud/datastore/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@

"""Connections to gcloud datastore API servers."""

import six

from gcloud import connection
from gcloud.exceptions import make_exception
from gcloud.datastore import _datastore_v1_pb2 as datastore_pb
from gcloud.datastore import helpers

Expand Down Expand Up @@ -54,7 +53,7 @@ def _request(self, dataset_id, method, data):
:rtype: string
:returns: The string response content from the API call.
:raises: :class:`six.moves.http_client.HTTPException` if the response
:raises: :class:`gcloud.exceptions.GCloudError` if the response
code is not 200 OK.
"""
headers = {
Expand All @@ -68,9 +67,7 @@ def _request(self, dataset_id, method, data):

status = headers['status']
if status != '200':
message = ('Request failed with status code %s. '
'Error was: %s' % (status, content))
raise six.moves.http_client.HTTPException(message)
raise make_exception(headers, content)

return content

Expand Down
14 changes: 7 additions & 7 deletions gcloud/datastore/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,16 @@ def test__request_w_200(self):
self.assertEqual(http._called_with['body'], DATA)

def test__request_not_200(self):
import six
from gcloud.exceptions import BadRequest

DATASET_ID = 'DATASET'
METHOD = 'METHOD'
DATA = 'DATA'
conn = self._makeOne()
conn._http = Http({'status': '400'}, 'Bad Request')
with self.assertRaises(six.moves.http_client.HTTPException) as e:
conn._http = Http({'status': '400'}, '{"message": "Bad Request"}')
with self.assertRaises(BadRequest) as e:
conn._request(DATASET_ID, METHOD, DATA)
expected_message = ('Request failed with status code 400. '
'Error was: Bad Request')
expected_message = ('400 Bad Request')
self.assertEqual(str(e.exception), expected_message)

def test__rpc(self):
Expand Down Expand Up @@ -845,12 +844,13 @@ class Http(object):
_called_with = None

def __init__(self, headers, content):
self._headers = headers
from httplib2 import Response
self._response = Response(headers)
self._content = content

def request(self, **kw):
self._called_with = kw
return self._headers, self._content
return self._response, self._content


class HttpMultiple(object):
Expand Down

0 comments on commit 6f2796c

Please sign in to comment.