@@ -53,79 +53,6 @@ def test_ctor_explicit(self):
5353 self .assertEqual (sorted (entity .exclude_from_indexes ),
5454 sorted (_EXCLUDE_FROM_INDEXES ))
5555
56- def test__must_key_no_key (self ):
57- from gcloud .datastore .entity import NoKey
58-
59- entity = self ._makeOne ()
60- self .assertRaises (NoKey , getattr , entity , '_must_key' )
61-
62- def test_save_no_key (self ):
63- from gcloud .datastore .entity import NoKey
64-
65- entity = self ._makeOne ()
66- entity ['foo' ] = 'Foo'
67- self .assertRaises (NoKey , entity .save )
68-
69- def test_save_wo_transaction_wo_auto_id_wo_returned_key (self ):
70- connection = _Connection ()
71- key = _Key ()
72- entity = self ._makeOne (key = key )
73- entity ['foo' ] = 'Foo'
74- entity .save (connection = connection )
75- self .assertEqual (entity ['foo' ], 'Foo' )
76- self .assertEqual (connection ._saved ,
77- (_DATASET_ID , 'KEY' , {'foo' : 'Foo' }, ()))
78- self .assertEqual (key ._path , None )
79-
80- def test_save_w_transaction_wo_partial_key (self ):
81- connection = _Connection ()
82- transaction = connection ._transaction = _Transaction ()
83- key = _Key ()
84- entity = self ._makeOne (key = key )
85- entity ['foo' ] = 'Foo'
86- entity .save (connection = connection )
87- self .assertEqual (entity ['foo' ], 'Foo' )
88- self .assertEqual (connection ._saved ,
89- (_DATASET_ID , 'KEY' , {'foo' : 'Foo' }, ()))
90- self .assertEqual (transaction ._added , ())
91- self .assertEqual (key ._path , None )
92-
93- def test_save_w_transaction_w_partial_key (self ):
94- connection = _Connection ()
95- transaction = connection ._transaction = _Transaction ()
96- key = _Key ()
97- key ._partial = True
98- entity = self ._makeOne (key = key )
99- entity ['foo' ] = 'Foo'
100- entity .save (connection = connection )
101- self .assertEqual (entity ['foo' ], 'Foo' )
102- self .assertEqual (connection ._saved ,
103- (_DATASET_ID , 'KEY' , {'foo' : 'Foo' }, ()))
104- self .assertEqual (transaction ._added , (entity ,))
105- self .assertEqual (key ._path , None )
106-
107- def test_save_w_returned_key_exclude_from_indexes (self ):
108- from gcloud .datastore import datastore_v1_pb2 as datastore_pb
109- from gcloud .datastore .key import Key
110-
111- key_pb = datastore_pb .Key ()
112- key_pb .partition_id .dataset_id = _DATASET_ID
113- key_pb .path_element .add (kind = _KIND , id = _ID )
114- connection = _Connection ()
115- connection ._save_result = (True , _ID )
116- key = Key ('KIND' , dataset_id = _DATASET_ID )
117- entity = self ._makeOne (key = key , exclude_from_indexes = ['foo' ])
118- entity ['foo' ] = 'Foo'
119- entity .save (connection = connection )
120- self .assertEqual (entity ['foo' ], 'Foo' )
121- self .assertEqual (connection ._saved [0 ], _DATASET_ID )
122- self .assertEqual (connection ._saved [1 ], key .to_protobuf ())
123- self .assertEqual (connection ._saved [2 ], {'foo' : 'Foo' })
124- self .assertEqual (connection ._saved [3 ], ('foo' ,))
125- self .assertEqual (len (connection ._saved ), 4 )
126-
127- self .assertEqual (entity .key ._path , [{'kind' : _KIND , 'id' : _ID }])
128-
12956 def test___repr___no_key_empty (self ):
13057 entity = self ._makeOne ()
13158 self .assertEqual (repr (entity ), '<Entity {}>' )
@@ -149,38 +76,6 @@ class _Key(object):
14976 def __init__ (self , dataset_id = _DATASET_ID ):
15077 self .dataset_id = dataset_id
15178
152- def to_protobuf (self ):
153- return self ._key
154-
155- @property
156- def is_partial (self ):
157- return self ._partial
158-
15979 @property
16080 def path (self ):
16181 return self ._path
162-
163-
164- class _Connection (object ):
165- _transaction = _saved = _deleted = None
166- _save_result = (False , None )
167-
168- def transaction (self ):
169- return self ._transaction
170-
171- def save_entity (self , dataset_id , key_pb , properties ,
172- exclude_from_indexes = ()):
173- self ._saved = (dataset_id , key_pb , properties ,
174- tuple (exclude_from_indexes ))
175- return self ._save_result
176-
177-
178- class _Transaction (object ):
179- _added = ()
180-
181- def __nonzero__ (self ):
182- return True
183- __bool__ = __nonzero__
184-
185- def add_auto_id_entity (self , entity ):
186- self ._added += (entity ,)
0 commit comments