8000 Renaming datastore Batch.mutation to mutations. by dhermes · Pull Request #1306 · googleapis/google-cloud-python · GitHub
[go: up one dir, main page]

Skip to content

Renaming datastore Batch.mutation to mutations. #1306

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 22, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions gcloud/datastore/batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ def connection(self):
return self._client.connection

@property
def mutation(self):
"""Getter for the current mutation.
def mutations(self):
"""Getter for the changes accumulated by this batch.

Every batch is committed with a single Mutation
representing the 'work' to be done as part of the batch.
Expand Down Expand Up @@ -146,10 +146,10 @@ def put(self, entity):
raise ValueError("Key must be from same dataset as batch")

if entity.key.is_partial:
entity_pb = self.mutation.insert_auto_id.add()
entity_pb = self.mutations.insert_auto_id.add()
self._partial_key_entities.append(entity)
else:
entity_pb = self.mutation.upsert.add()
entity_pb = self.mutations.upsert.add()

_assign_entity_to_pb(entity_pb, entity)

Expand All @@ -169,7 +169,7 @@ def delete(self, key):
raise ValueError("Key must be from same dataset as batch")

key_pb = helpers._prepare_key_for_request(key.to_protobuf())
self.mutation.delete.add().CopyFrom(key_pb)
self.mutations.delete.add().CopyFrom(key_pb)

def begin(self):
"""No-op
Expand All @@ -186,7 +186,7 @@ def commit(self):
context manager.
"""
_, updated_keys = self.connection.commit(
self.dataset_id, self.mutation, self._id)
self.dataset_id, self.mutations, self._id)
# If the back-end returns without error, we are guaranteed that
# the response's 'insert_auto_id_key' will match (length and order)
# the request's 'insert_auto_id` entities, which are derived from
Expand Down
66 changes: 33 additions & 33 deletions gcloud/datastore/test_batch.py
Original file 8000 line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def test_ctor(self):
self.assertEqual(batch.connection, connection)
self.assertEqual(batch.namespace, _NAMESPACE)
self.assertTrue(batch._id is None)
self.assertTrue(isinstance(batch.mutation, Mutation))
self.assertTrue(isinstance(batch.mutations, Mutation))
self.assertEqual(batch._partial_key_entities, [])

def test_current(self):
Expand Down Expand Up @@ -89,12 +89,12 @@ def test_put_entity_w_partial_key(self):

batch.put(entity)

insert_auto_ids = list(batch.mutation.insert_auto_id)
insert_auto_ids = list(batch.mutations.insert_auto_id)
self.assertEqual(len(insert_auto_ids), 1)
self.assertEqual(insert_auto_ids[0].key, key._key)
upserts = list(batch.mutation.upsert)
upserts = list(batch.mutations.upsert)
self.assertEqual(len(upserts), 0)
deletes = list(batch.mutation.delete)
deletes = list(batch.mutations.delete)
self.assertEqual(len(deletes), 0)
self.assertEqual(batch._partial_key_entities, [entity])

Expand All @@ -115,9 +115,9 @@ def test_put_entity_w_completed_key(self):

batch.put(entity)

insert_auto_ids = list(batch.mutation.insert_auto_id)
insert_auto_ids = list(batch.mutations.insert_auto_id)
self.assertEqual(len(insert_auto_ids), 0)
upserts = list(batch.mutation.upsert)
upserts = list(batch.mutations.upsert)
self.assertEqual(len(upserts), 1)

upsert = upserts[0]
Expand All @@ -131,7 +131,7 @@ def test_put_entity_w_completed_key(self):
self.assertFalse(props['spam'].list_value[2].indexed)
self.assertFalse('frotz' in props)

deletes = list(batch.mutation.delete)
deletes = list(batch.mutations.delete)
self.assertEqual(len(deletes), 0)

def test_put_entity_w_completed_key_prefixed_dataset_id(self):
Expand All @@ -151,9 +151,9 @@ def test_put_entity_w_completed_key_prefixed_dataset_id(self):

batch.put(entity)

insert_auto_ids = list(batch.mutation.insert_auto_id)
insert_auto_ids = list(batch.mutations.insert_auto_id)
self.assertEqual(len(insert_auto_ids), 0)
upserts = list(batch.mutation.upsert)
upserts = list(batch.mutations.upsert)
self.assertEqual(len(upserts), 1)

upsert = upserts[0]
Expand All @@ -167,7 +167,7 @@ def test_put_entity_w_completed_key_prefixed_dataset_id(self):
self.assertFalse(props['spam'].list_value[2].indexed)
self.assertFalse('frotz' in props)

deletes = list(batch.mutation.delete)
deletes = list(batch.mutations.delete)
self.assertEqual(len(deletes), 0)

def test_delete_w_partial_key(self):
Expand Down Expand Up @@ -198,11 +198,11 @@ def test_delete_w_completed_key(self):

batch.delete(key)

insert_auto_ids = list(batch.mutation.insert_auto_id)
insert_auto_ids = list(batch.mutations.insert_auto_id)
self.assertEqual(len(insert_auto_ids), 0)
upserts = list(batch.mutation.upsert)
upserts = list(batch.mutations.upsert)
self.assertEqual(len(upserts), 0)
deletes = list(batch.mutation.delete)
deletes = list(batch.mutations.delete)
self.assertEqual(len(deletes), 1)
self.assertEqual(deletes[0], key._key)

Expand All @@ -215,11 +215,11 @@ def test_delete_w_completed_key_w_prefixed_dataset_id(self):

batch.delete(key)

insert_auto_ids = list(batch.mutation.insert_auto_id)
insert_auto_ids = list(batch.mutations.insert_auto_id)
self.assertEqual(len(insert_auto_ids), 0)
upserts = list(batch.mutation.upsert)
upserts = list(batch.mutations.upsert)
self.assertEqual(len(upserts), 0)
deletes = list(batch.mutation.delete)
deletes = list(batch.mutations.delete)
self.assertEqual(len(deletes), 1)
self.assertEqual(deletes[0], key._key)

Expand All @@ -232,7 +232,7 @@ def test_commit(self):
batch.commit()

self.assertEqual(connection._committed,
[(_DATASET, batch.mutation, None)])
[(_DATASET, batch.mutations, None)])

def test_commit_w_partial_key_entities(self):
_DATASET = 'DATASET'
Expand All @@ -248,7 +248,7 @@ def test_commit_w_partial_key_entities(self):
batch.commit()

self.assertEqual(connection._committed,
[(_DATASET, batch.mutation, None)])
[(_DATASET, batch.mutations, None)])
self.assertFalse(entity.key.is_partial)
self.assertEqual(entity.key._id, _NEW_ID)

Expand All @@ -268,15 +268,15 @@ def test_as_context_mgr_wo_error(self):

self.assertEqual(list(client._batches), [])

insert_auto_ids = list(batch.mutation.insert_auto_id)
insert_auto_ids = list(batch.mutations.insert_auto_id)
self.assertEqual(len(insert_auto_ids), 0)
upserts = list(batch.mutation.upsert)
upserts = list(batch.mutations.upsert)
self.assertEqual(len(upserts), 1)
self.assertEqual(upserts[0].key, key._key)
deletes = list(batch.mutation.delete)
deletes = list(batch.mutations.delete)
self.assertEqual(len(deletes), 0)
self.assertEqual(connection._committed,
[(_DATASET, batch.mutation, None)])
[(_DATASET, batch.mutations, None)])

def test_as_context_mgr_nested(self):
_DATASET = 'DATASET'
Expand All @@ -301,25 +301,25 @@ def test_as_context_mgr_nested(self):

self.assertEqual(list(client._batches), [])

insert_auto_ids = list(batch1.mutation.insert_auto_id)
insert_auto_ids = list(batch1.mutations.insert_auto_id)
self.assertEqual(len(insert_auto_ids), 0)
upserts = list(batch1.mutation.upsert)
upserts = list(batch1.mutations.upsert)
self.assertEqual(len(upserts), 1)
self.assertEqual(upserts[0].key, key1._key)
deletes = list(batch1.mutation.delete)
deletes = list(batch1.mutations.delete)
self.assertEqual(len(deletes), 0)

insert_auto_ids = list(batch2.mutation.insert_auto_id)
insert_auto_ids = list(batch2.mutations.insert_auto_id)
self.assertEqual(len(insert_auto_ids), 0)
upserts = list(batch2.mutation.upsert)
upserts = list(batch2.mutations.upsert)
self.assertEqual(len(upserts), 1)
self.assertEqual(upserts[0].key, key2._key)
deletes = list(batch2.mutation.delete)
deletes = list(batch2.mutations.delete)
self.assertEqual(len(deletes), 0)

self.assertEqual(connection._committed,
[(_DATASET, batch2.mutation, None),
(_DATASET, batch1.mutation, None)])
[(_DATASET, batch2.mutations, None),
(_DATASET, batch1.mutations, None)])

def test_as_context_mgr_w_error(self):
_DATASET = 'DATASET'
Expand All @@ -341,12 +341,12 @@ def test_as_context_mgr_w_error(self):

self.assertEqual(list(client._batches), [])

insert_auto_ids = list(batch.mutation.insert_auto_id)
insert_auto_ids = list(batch.mutations.insert_auto_id)
self.assertEqual(len(insert_auto_ids), 0)
upserts = list(batch.mutation.upsert)
upserts = list(batch.mutations.upsert)
self.assertEqual(len(upserts), 1)
self.assertEqual(upserts[0].key, key._key)
deletes = list(batch.mutation.delete)
deletes = list(batch.mutations.delete)
self.assertEqual(len(deletes), 0)
self.assertEqual(connection._committed, [])

Expand Down
18 changes: 9 additions & 9 deletions gcloud/datastore/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -647,14 +647,14 @@ def test_put_multi_existing_batch_w_completed_key(self):
result = client.put_multi([entity])

self.assertEqual(result, None)
self.assertEqual(len(CURR_BATCH.mutation.insert_auto_id), 0)
upserts = list(CURR_BATCH.mutation.upsert)
self.assertEqual(len(CURR_BATCH.mutations.insert_auto_id), 0)
upserts = list(CURR_BATCH.mutations.upsert)
self.assertEqual(len(upserts), 1)
self.assertEqual(upserts[0].key, key.to_protobuf())
properties = list(upserts[0].property)
self.assertEqual(properties[0].name, 'foo')
self.assertEqual(properties[0].value.string_value, u'bar')
self.assertEqual(len(CURR_BATCH.mutation.delete), 0)
self.assertEqual(len(CURR_BATCH.mutations.delete), 0)

def test_delete(self):
_called_with = []
Expand Down Expand Up @@ -707,9 +707,9 @@ def test_delete_multi_w_existing_batch(self):
result = client.delete_multi([key])

self.assertEqual(result, None)
self.assertEqual(len(CURR_BATCH.mutation.insert_auto_id), 0)
self.assertEqual(len(CURR_BATCH.mutation.upsert), 0)
deletes = list(CURR_BATCH.mutation.delete)
self.assertEqual(len(CURR_BATCH.mutations.insert_auto_id), 0)
self.assertEqual(len(CURR_BATCH.mutations.upsert), 0)
deletes = list(CURR_BATCH.mutations.delete)
self.assertEqual(len(deletes), 1)
self.assertEqual(deletes[0], key._key)
self.assertEqual(len(client.connection._commit_cw), 0)
Expand All @@ -725,9 +725,9 @@ def test_delete_multi_w_existing_transaction(self):
result = client.delete_multi([key])

self.assertEqual(result, None)
self.assertEqual(len(CURR_XACT.mutation.insert_auto_id), 0)
self.assertEqual(len(CURR_XACT.mutation.upsert), 0)
deletes = list(CURR_XACT.mutation.delete)
self.assertEqual(len(CURR_XACT.mutations.insert_auto_id), 0)
self.assertEqual(len(CURR_XACT.mutations.upsert), 0)
deletes = list(CURR_XACT.mutations.delete)
self.assertEqual(len(deletes), 1)
self.assertEqual(deletes[0], key._key)
self.assertEqual(len(client.connection._commit_cw), 0)
Expand Down
2 changes: 1 addition & 1 deletion gcloud/datastore/test_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def test_ctor_defaults(self):
self.assertEqual(xact.connection, connection)
self.assertEqual(xact.id, None)
self.assertEqual(xact._status, self._getTargetClass()._INITIAL)
self.assertTrue(isinstance(xact.mutation, Mutation))
self.assertTrue(isinstance(xact.mutations, Mutation))
self.assertEqual(len(xact._partial_key_entities), 0)

def test_current(self):
Expand Down
0