Skip to content

Commit 39bbf25

Browse files
committed
Updating unit test for removal of datastore Connection.
Also moved the Connection.lookup() method onto GAPIC and GAPIC-like HTTP API object.
1 parent 04950cd commit 39bbf25

File tree

3 files changed

+209
-371
lines changed

3 files changed

+209
-371
lines changed

datastore/unit_tests/test__gax.py

Lines changed: 1 addition & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
import mock
1818

19-
from google.cloud.datastore._http import _HAVE_GRPC
19+
from google.cloud.datastore.client import _HAVE_GRPC
2020

2121

2222
@unittest.skipUnless(_HAVE_GRPC, 'No gRPC')
@@ -112,95 +112,6 @@ def test_gax_error_not_mapped(self):
112112
self._fake_method(exc)
113113

114114

115-
class Test_DatastoreAPIOverGRPC(unittest.TestCase):
116-
117-
@staticmethod
118-
def _get_target_class():
119-
from google.cloud.datastore._gax import _DatastoreAPIOverGRPC
120-
121-
return _DatastoreAPIOverGRPC
122-
123-
def _make_one(self, stub, connection=None, secure=True):
124-
if secure:
125-
patch = mock.patch(
126-
'google.cloud.datastore._gax.make_secure_stub',
127-
return_value=stub)
128-
base_url = 'https://test.invalid'
129-
else:
130-
patch = mock.patch(
131-
'google.cloud.datastore._gax.make_insecure_stub',
132-
return_value=stub)
133-
base_url = 'http://test.invalid'
134-
135-
if connection is None:
136-
connection = mock.Mock(
137-
credentials=object(),
138-
api_base_url=base_url,
139-
spec=['credentials', 'api_base_url'],
140-
)
141-
142-
with patch as make_stub_mock:
143-
api_obj = self._get_target_class()(connection)
144-
return api_obj, make_stub_mock
145-
146-
def test_constructor(self):
147-
from google.cloud._http import DEFAULT_USER_AGENT
148-
import google.cloud.datastore._gax as MUT
149-
150-
host = 'test.invalid'
151-
conn = mock.Mock(
152-
credentials=object(),
153-
api_base_url='https://' + host,
154-
spec=['credentials', 'api_base_url'],
155-
)
156-
157-
stub = _GRPCStub()
158-
datastore_api, make_stub_mock = self._make_one(
159-
stub, connection=conn)
160-
161-
self.assertIs(datastore_api._stub, stub)
162-
make_stub_mock.assert_called_once_with(
163-
conn.credentials,
164-
DEFAULT_USER_AGENT,
165-
MUT.datastore_pb2_grpc.DatastoreStub,
166-
host,
167-
extra_options=MUT._GRPC_EXTRA_OPTIONS,
168-
)
169-
170-
def test_constructor_insecure(self):
171-
from google.cloud.proto.datastore.v1 import datastore_pb2_grpc
172-
173-
host = 'test.invalid'
174-
conn = mock.Mock(
175-
credentials=object(),
176-
api_base_url='http://' + host,
177-
spec=['credentials', 'api_base_url'],
178-
)
179-
180-
stub = _GRPCStub()
181-
datastore_api, make_stub_mock = self._make_one(
182-
stub, connection=conn, secure=False)
183-
184-
self.assertIs(datastore_api._stub, stub)
185-
make_stub_mock.assert_called_once_with(
186-
datastore_pb2_grpc.DatastoreStub,
187-
host,
188-
)
189-
190-
def test_lookup(self):
191-
return_val = object()
192-
stub = _GRPCStub(return_val)
193-
datastore_api, _ = self._make_one(stub=stub)
194-
195-
request_pb = mock.Mock(project_id=None, spec=['project_id'])
196-
project = 'PROJECT'
197-
result = datastore_api.lookup(project, request_pb)
198-
self.assertIs(result, return_val)
199-
self.assertEqual(request_pb.project_id, project)
200-
self.assertEqual(stub.method_calls,
201-
[(request_pb, 'Lookup')])
202-
203-
204115
@unittest.skipUnless(_HAVE_GRPC, 'No gRPC')
205116
class TestGAPICDatastoreAPI(unittest.TestCase):
206117

@@ -263,17 +174,3 @@ def test_it(self, make_chan, mock_klass):
263174
mock_klass.assert_called_once_with(
264175
channel=mock.sentinel.channel, lib_name='gccl',
265176
lib_version=__version__)
266-
267-
268-
class _GRPCStub(object):
269-
270-
def __init__(self, return_val=None):
271-
self.return_val = return_val
272-
self.method_calls = []
273-
274-
def _method(self, request_pb, name):
275-
self.method_calls.append((request_pb, name))
276-
return self.return_val
277-
278-
def Lookup(self, request_pb):
279-
return self._method(request_pb, 'Lookup')

0 commit comments

Comments
 (0)