8000 Merge pull request #980 from dhermes/fix-datastore-plumbing-modules · googleapis/google-cloud-python@c8593bf · GitHub
[go: up one dir, main page]

Skip to content 8000

Commit c8593bf

Browse files
committed
Merge pull request #980 from dhermes/fix-datastore-plumbing-modules
Fix datastore test plumbing modules.
2 parents 3c76dbf + c190be4 commit c8593bf

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

system_tests/clear_datastore.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222

2323
_implicit_environ._DATASET_ENV_VAR_NAME = 'GCLOUD_TESTS_DATASET_ID'
24+
CLIENT = datastore.Client()
2425

2526

2627
FETCH_MAX = 20
@@ -36,7 +37,7 @@
3637

3738
def fetch_keys(kind, fetch_max=FETCH_MAX, query=None, cursor=None):
3839
if query is None:
39-
query = datastore.Query(kind=kind, projection=['__key__'])
40+
query = CLIENT.query(kind=kind, projection=['__key__'])
4041

4142
iterator = query.fetch(limit=fetch_max, start_cursor=cursor)
4243

@@ -65,7 +66,7 @@ def remove_kind(kind):
6566
return
6667

6768
delete_outside_transaction = False
68-
with datastore.Transaction():
69+
with CLIENT.transaction():
6970
# Now that we have all results, we seek to delete.
7071
print('Deleting keys:')
7172
print(results)
@@ -74,10 +75,10 @@ def remove_kind(kind):
7475
if len(ancestors) > TRANSACTION_MAX_GROUPS:
7576
delete_outside_transaction = True
7677
else:
77-
datastore.delete_multi([result.key for result in results])
78+
CLIENT.delete_multi([result.key for result in results])
7879

7980
if delete_outside_transaction:
80-
datastore.delete_multi([result.key for result in results])
81+
CLIENT.delete_multi([result.key for result in results])
8182

8283

8384
def remove_all_entities():

system_tests/populate_datastore.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222

2323
_implicit_environ._DATASET_ENV_VAR_NAME = 'GCLOUD_TESTS_DATASET_ID'
24+
CLIENT = datastore.Client()
2425

2526

2627
ANCESTOR = ('Book', 'GoT')
@@ -82,12 +83,12 @@
8283

8384

8485
def add_characters():
85-
with datastore.Transaction() as xact:
86+
with CLIENT.transaction() as xact:
8687
for key_path, character in zip(KEY_PATHS, CHARACTERS):
8788
if key_path[-1] != character['name']:
8889
raise ValueError(('Character and key don\'t agree',
8990
key_path, character))
90-
entity = datastore.Entity(key=datastore.Key(*key_path))
91+
entity = datastore.Entity(key=CLIENT.key(*key_path))
9192
entity.update(character)
9293
xact.put(entity)
9394
print('Adding Character %s %s' % (character['name'],

0 commit comments

Comments
 (0)
0