1717import unittest2
1818
1919from gcloud import datastore
20- from gcloud .datastore .entity import Entity
21- from gcloud .datastore .key import Key
22- from gcloud .datastore .query import Query
23- from gcloud .datastore .transaction import Transaction
2420# This assumes the command is being run via tox hence the
2521# repository root is the current directory.
2622from regression import populate_datastore
@@ -36,7 +32,7 @@ def setUp(self):
3632 self .case_entities_to_delete = []
3733
3834 def tearDown (self ):
39- with Transaction ():
35+ with datastore . Transaction ():
4036 for entity in self .case_entities_to_delete :
4137 entity .key .delete ()
4238
@@ -45,7 +41,7 @@ class TestDatastoreAllocateIDs(TestDatastore):
4541
4642 def test_allocate_ids (self ):
4743 num_ids = 10
48- allocated_keys = datastore .allocate_ids (Key ('Kind' ), num_ids )
44+ allocated_keys = datastore .allocate_ids (datastore . Key ('Kind' ), num_ids )
4945 self .assertEqual (len (allocated_keys ), num_ids )
5046
5147 unique_ids = set ()
@@ -70,7 +66,7 @@ def _get_post(self, id_or_name=None, post_content=None):
7066 'rating' : 5.0 ,
7167 }
7268 # Create an entity with the given content.
73- entity = Entity (key = Key ('Post' ))
69+ entity = datastore . Entity (key = datastore . Key ('Post' ))
7470 entity .update (post_content )
7571
7672 # Update the entity key.
@@ -112,7 +108,7 @@ def test_post_with_generated_id(self):
112108 self ._generic_test_post ()
113109
114110 def test_save_multiple (self ):
115- with Transaction ():
111+ with datastore . Transaction ():
116112 entity1 = self ._get_post ()
117113 entity1 .save ()
118114 # Register entity to be deleted.
@@ -137,23 +133,23 @@ def test_save_multiple(self):
137133 self .assertEqual (len (matches ), 2 )
138134
139135 def test_empty_kind (self ):
140- query = Query (kind = 'Post' )
136+ query = datastore . Query (kind = 'Post' )
141137 posts = list (query .fetch (limit = 2 ))
142138 self .assertEqual (posts , [])
143139
144140
145141class TestDatastoreSaveKeys (TestDatastore ):
146142
147143 def test_save_key_self_reference (self ):
148- key = Key ('Person' , 'name' )
149- entity = Entity (key = key )
144+ key = datastore . Key ('Person' , 'name' )
145+ entity = datastore . Entity (key = key )
150146 entity ['fullName' ] = u'Full name'
151147 entity ['linkedTo' ] = key # Self reference.
152148
153149 entity .save ()
154150 self .case_entities_to_delete .append (entity )
155151
156- query = Query (kind = 'Person' )
152+ query = datastore . Query (kind = 'Person' )
157153 query .add_filter ('linkedTo' , '=' , key )
158154
159155 stored_persons = list (query .fetch (limit = 2 ))
@@ -171,10 +167,10 @@ class TestDatastoreQuery(TestDatastore):
171167 def setUpClass (cls ):
172168 super (TestDatastoreQuery , cls ).setUpClass ()
173169 cls .CHARACTERS = populate_datastore .CHARACTERS
174- cls .ANCESTOR_KEY = Key (* populate_datastore .ANCESTOR )
170+ cls .ANCESTOR_KEY = datastore . Key (* populate_datastore .ANCESTOR )
175171
176172 def _base_query (self ):
177- return Query (kind = 'Character' , ancestor = self .ANCESTOR_KEY )
173+ return datastore . Query (kind = 'Character' , ancestor = self .ANCESTOR_KEY )
178174
179175 def test_limit_queries (self ):
180176 limit = 5
@@ -219,7 +215,7 @@ def test_ancestor_query(self):
219215 self .assertEqual (len (entities ), expected_matches )
220216
221217 def test_query___key___filter (self ):
222- rickard_key = Key (* populate_datastore .RICKARD )
218+ rickard_key = datastore . Key (* populate_datastore .RICKARD )
223219
224220 query = self ._base_query ()
225221 query .add_filter ('__key__' , '=' , rickard_key )
@@ -341,10 +337,10 @@ def test_query_group_by(self):
341337class TestDatastoreTransaction (TestDatastore ):
342338
343339 def test_transaction (self ):
344- entity = Entity (key = Key ('Company' , 'Google' ))
340+ entity = datastore . Entity (key = datastore . Key ('Company' , 'Google' ))
345341 entity ['url' ] = u'www.google.com'
346342
347- with Transaction ():
343+ with datastore . Transaction ():
348344 retrieved_entity = datastore .get (entity .key )
349345 if retrieved_entity is None :
350346 entity .save ()
0 commit comments