Skip to content

Commit 9605172

Browse files
committed
review changes
1 parent f7aa293 commit 9605172

File tree

4 files changed

+48
-52
lines changed

4 files changed

+48
-52
lines changed

datastore/google/cloud/datastore/client.py

+4-8
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,15 @@
1717

1818
from google.cloud._helpers import _LocalStack
1919
from google.cloud._helpers import (_determine_default_project as
20-
_default_project)
21-
20+
_base_default_project)
2221
from google.cloud.client import ClientWithProject
23-
2422
from google.cloud.datastore import helpers
2523
from google.cloud.datastore._http import HTTPDatastoreAPI
2624
from google.cloud.datastore.batch import Batch
2725
from google.cloud.datastore.entity import Entity
2826
from google.cloud.datastore.key import Key
2927
from google.cloud.datastore.query import Query
3028
from google.cloud.datastore.transaction import Transaction
31-
3229
from google.cloud.environment_vars import DISABLE_GRPC
3330
from google.cloud.environment_vars import GCD_DATASET
3431
from google.cloud.environment_vars import GCD_HOST
@@ -75,7 +72,7 @@ def _determine_default_project(project=None):
7572
project = _get_gcd_project()
7673

7774
if project is None:
78-
project = _default_project(project=project)
75+
project = _base_default_project(project=project)
7976

8077
return project
8178

@@ -306,9 +303,8 @@ def get(self, key, missing=None, deferred=None,
306303
307304
:type eventual: bool
308305
:param eventual: (Optional) Defaults to strongly consistent (False).
309-
Setting True will use eventual consistency,
310-
but cannot be used inside a transaction or
311-
will raise ValueError.
306+
Setting True will use eventual consistency, but cannot
307+
be used inside a transaction or will raise ValueError.
312308
313309
:rtype: :class:`google.cloud.datastore.entity.Entity` or ``NoneType``
314310
:returns: The requested entity if it exists.

datastore/google/cloud/datastore/helpers.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
from google.cloud._helpers import _pb_timestamp_to_datetime
2626
from google.cloud.datastore.entity import Entity
2727
from google.cloud.datastore.key import Key
28-
from google.cloud.proto.datastore.v1 import entity_pb2 as _entity_pb2
29-
from google.cloud.proto.datastore.v1 import datastore_pb2 as _datastore_pb2
28+
from google.cloud.proto.datastore.v1 import entity_pb2
29+
from google.cloud.proto.datastore.v1 import datastore_pb2
3030

3131
from google.protobuf import struct_pb2
3232
from google.type import latlng_pb2
@@ -205,7 +205,7 @@ def entity_to_protobuf(entity):
205205
:rtype: :class:`.entity_pb2.Entity`
206206
:returns: The protobuf representing the entity.
207207
"""
208-
entity_pb = _entity_pb2.Entity()
208+
entity_pb = entity_pb2.Entity()
209209
if entity.key is not None:
210210
key_pb = entity.key.to_protobuf()
211211
entity_pb.key.CopyFrom(key_pb)
@@ -253,15 +253,15 @@ def get_read_options(eventual, transaction_id):
253253
"""
254254
if transaction_id is None:
255255
if eventual:
256-
return _datastore_pb2.ReadOptions(
257-
read_consistency=_datastore_pb2.ReadOptions.EVENTUAL)
256+
return datastore_pb2.ReadOptions(
257+
read_consistency=datastore_pb2.ReadOptions.EVENTUAL)
258258
else:
259-
return _datastore_pb2.ReadOptions()
259+
return datastore_pb2.ReadOptions()
260260
else:
261261
if eventual:
262262
raise ValueError('eventual must be False when in a transaction')
263263
else:
264-
return _datastore_pb2.ReadOptions(
264+
return datastore_pb2.ReadOptions(
265265
transaction=transaction_id)
266266

267267

datastore/tests/unit/test_client.py

+2-37
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def fallback_mock(project=None):
8585
patch = mock.patch.multiple(
8686
'google.cloud.datastore.client',
8787
_get_gcd_project=gcd_mock,
88-
_default_project=fallback_mock)
88+
_base_default_project=fallback_mock)
8989
with patch:
9090
returned_project = self._call_fut(project_called)
9191

@@ -138,7 +138,7 @@ def test_constructor_w_project_no_environ(self):
138138
# Some environments (e.g. AppVeyor CI) run in GCE, so
139139
# this test would fail artificially.
140140
patch = mock.patch(
141-
'google.cloud.datastore.client._default_project',
141+
'google.cloud.datastore.client._base_default_project',
142142
return_value=None)
143143
with patch:
144144
self.assertRaises(EnvironmentError, self._make_one, None)
@@ -1010,41 +1010,6 @@ def test_query_w_namespace_collision(self):
10101010
client, project=self.PROJECT, namespace=namespace2, kind=kind)
10111011

10121012

1013-
class Test__get_read_options(unittest.TestCase):
1014-
1015-
def _call_fut(self, eventual, transaction_id):
1016-
from google.cloud.datastore.helpers import get_read_options
1017-
1018-
return get_read_options(eventual, transaction_id)
1019-
1020-
def test_eventual_w_transaction(self):
1021-
with self.assertRaises(ValueError):
1022-
self._call_fut(True, b'123')
1023-
1024-
def test_eventual_wo_transaction(self):
1025-
from google.cloud.proto.datastore.v1 import datastore_pb2
1026-
1027-
read_options = self._call_fut(True, None)
1028-
expected = datastore_pb2.ReadOptions(
1029-
read_consistency=datastore_pb2.ReadOptions.EVENTUAL)
1030-
self.assertEqual(read_options, expected)
1031-
1032-
def test_default_w_transaction(self):
1033-
from google.cloud.proto.datastore.v1 import datastore_pb2
1034-
1035-
txn_id = b'123abc-easy-as'
1036-
read_options = self._call_fut(False, txn_id)
1037-
expected = datastore_pb2.ReadOptions(transaction=txn_id)
1038-
self.assertEqual(read_options, expected)
1039-
1040-
def test_default_wo_transaction(self):
1041-
from google.cloud.proto.datastore.v1 import datastore_pb2
1042-
1043-
read_options = self._call_fut(False, None)
1044-
expected = datastore_pb2.ReadOptions()
1045-
self.assertEqual(read_options, expected)
1046-
1047-
10481013
class _NoCommitBatch(object):
10491014

10501015
def __init__(self, client):

datastore/tests/unit/test_helpers.py

+35
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,41 @@ def test_w_nothing_in_pb(self):
498498
self.assertRaises(ValueError, self._call_fut, pb)
499499

500500

501+
class Test__get_read_options(unittest.TestCase):
502+
503+
def _call_fut(self, eventual, transaction_id):
504+
from google.cloud.datastore.helpers import get_read_options
505+
506+
return get_read_options(eventual, transaction_id)
507+
508+
def test_eventual_w_transaction(self):
509+
with self.assertRaises(ValueError):
510+
self._call_fut(True, b'123')
511+
512+
def test_eventual_wo_transaction(self):
513+
from google.cloud.proto.datastore.v1 import datastore_pb2
514+
515+
read_options = self._call_fut(True, None)
516+
expected = datastore_pb2.ReadOptions(
517+
read_consistency=datastore_pb2.ReadOptions.EVENTUAL)
518+
self.assertEqual(read_options, expected)
519+
520+
def test_default_w_transaction(self):
521+
from google.cloud.proto.datastore.v1 import datastore_pb2
522+
523+
txn_id = b'123abc-easy-as'
524+
read_options = self._call_fut(False, txn_id)
525+
expected = datastore_pb2.ReadOptions(transaction=txn_id)
526+
self.assertEqual(read_options, expected)
527+
528+
def test_default_wo_transaction(self):
529+
from google.cloud.proto.datastore.v1 import datastore_pb2
530+
531+
read_options = self._call_fut(False, None)
532+
expected = datastore_pb2.ReadOptions()
533+
self.assertEqual(read_options, expected)
534+
535+
501536
class Test__pb_attr_value(unittest.TestCase):
502537

503538
def _call_fut(self, val):

0 commit comments

Comments
 (0)