Skip to content

Commit ec3725b

Browse files
authored
docs: Change Python client examples from sample_task to sampleTask (GoogleCloudPlatform#7231)
## Description The examples in other client libraries are all using `sampleTask`. Additionally, the doc says: > The following example creates a key with kind Task using a key name, "sampleTask", as the identifier: Closes internal bug 210583283 ## Checklist - [x] I have followed [Sample Guidelines from AUTHORING_GUIDE.MD](https://github.com/GoogleCloudPlatform/python-docs-samples/blob/main/AUTHORING_GUIDE.md) - [ ] README is updated to include [all relevant information](https://github.com/GoogleCloudPlatform/python-docs-samples/blob/main/AUTHORING_GUIDE.md#readme-file) - [x] **Tests** pass: `nox -s py-3.6` (see [Test Environment Setup](https://github.com/GoogleCloudPlatform/python-docs-samples/blob/main/AUTHORING_GUIDE.md#test-environment-setup)) - [x] **Lint** pass: `nox -s lint` (see [Test Environment Setup](https://github.com/GoogleCloudPlatform/python-docs-samples/blob/main/AUTHORING_GUIDE.md#test-environment-setup)) - [ ] These samples need a new **API enabled** in testing projects to pass (let us know which ones) - [ ] These samples need a new/updated **env vars** in testing projects set to pass (let us know which ones) - [x] Please **merge** this PR for me once it is approved. - [ ] This sample adds a new sample directory, and I updated the [CODEOWNERS file](https://github.com/GoogleCloudPlatform/python-docs-samples/blob/main/.github/CODEOWNERS) with the codeowners for this sample
1 parent 207347f commit ec3725b

File tree

2 files changed

+29
-13
lines changed

2 files changed

+29
-13
lines changed

datastore/cloud-client/snippets.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -150,26 +150,26 @@ def incomplete_key(client):
150150

151151
def named_key(client):
152152
# [START datastore_named_key]
153-
key = client.key("Task", "sample_task")
153+
key = client.key("Task", "sampleTask")
154154
# [END datastore_named_key]
155155

156156
return key
157157

158158

159159
def key_with_parent(client):
160160
# [START datastore_key_with_parent]
161-
key = client.key("TaskList", "default", "Task", "sample_task")
161+
key = client.key("TaskList", "default", "Task", "sampleTask")
162162
# Alternatively
163163
parent_key = client.key("TaskList", "default")
164-
key = client.key("Task", "sample_task", parent=parent_key)
164+
key = client.key("Task", "sampleTask", parent=parent_key)
165165
# [END datastore_key_with_parent]
166166

167167
return key
168168

169169

170170
def key_with_multilevel_parent(client):
171171
# [START datastore_key_with_multilevel_parent]
172-
key = client.key("User", "alice", "TaskList", "default", "Task", "sample_task")
172+
key = client.key("User", "alice", "TaskList", "default", "Task", "sampleTask")
173173
# [END datastore_key_with_multilevel_parent]
174174

175175
return key
@@ -193,7 +193,7 @@ def basic_entity(client):
193193

194194
def entity_with_parent(client):
195195
# [START datastore_entity_with_parent]
196-
key_with_parent = client.key("TaskList", "default", "Task", "sample_task")
196+
key_with_parent = client.key("TaskList", "default", "Task", "sampleTask")
197197

198198
task = datastore.Entity(key=key_with_parent)
199199

@@ -241,7 +241,7 @@ def array_value(client):
241241

242242
def upsert(client):
243243
# [START datastore_upsert]
244-
complete_key = client.key("Task", "sample_task")
244+
complete_key = client.key("Task", "sampleTask")
245245

246246
task = datastore.Entity(key=complete_key)
247247

@@ -288,7 +288,7 @@ def update(client):
288288

289289
# [START datastore_update]
290290
with client.transaction():
291-
key = client.key("Task", "sample_task")
291+
key = client.key("Task", "sampleTask")
292292
task = client.get(key)
293293

294294
task["done"] = True
@@ -304,7 +304,7 @@ def lookup(client):
304304
upsert(client)
305305

306306
# [START datastore_lookup]
307-
key = client.key("Task", "sample_task")
307+
key = client.key("Task", "sampleTask")
308308
task = client.get(key)
309309
# [END datastore_lookup]
310310

@@ -316,7 +316,7 @@ def delete(client):
316316
upsert(client)
317317

318318
# [START datastore_delete]
319-
key = client.key("Task", "sample_task")
319+
key = client.key("Task", "sampleTask")
320320
client.delete(key)
321321
# [END datastore_delete]
322322

@@ -767,7 +767,9 @@ def transfer_funds(client, from_key, to_key, amount):
767767
def transactional_get_or_create(client):
768768
# [START datastore_transactional_get_or_create]
769769
with client.transaction():
770-
key = client.key("Task", datetime.datetime.now(tz=datetime.timezone.utc).isoformat())
770+
key = client.key(
771+
"Task", datetime.datetime.now(tz=datetime.timezone.utc).isoformat()
772+
)
771773

772774
task = client.get(key)
773775

datastore/cloud-client/snippets_test.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,30 @@ def test_incomplete_key(self, client):
5050
assert snippets.incomplete_key(client)
5151

5252
def test_named_key(self, client):
53-
assert snippets.named_key(client)
53+
key = snippets.named_key(client)
54+
assert key
55+
assert key.name == "sampleTask"
5456

5557
def test_key_with_parent(self, client):
56-
assert snippets.key_with_parent(client)
58+
key = snippets.key_with_parent(client)
59+
assert key
60+
assert key.name == "sampleTask"
61+
assert key.parent.name == "default"
5762

5863
def test_key_with_multilevel_parent(self, client):
59-
assert snippets.key_with_multilevel_parent(client)
64+
key = snippets.key_with_multilevel_parent(client)
65+
assert key
66+
assert key.name == "sampleTask"
67+
assert key.parent.name == "default"
68+
assert key.parent.parent.name == "alice"
6069

6170
def test_basic_entity(self, client):
6271
assert snippets.basic_entity(client)
6372

6473
def test_entity_with_parent(self, client):
74+
task = snippets.entity_with_parent(client)
75+
assert task
76+
assert task.key.name == "sampleTask"
6577
assert snippets.entity_with_parent(client)
6678

6779
def test_properties(self, client):
@@ -74,6 +86,7 @@ def test_upsert(self, client):
7486
task = snippets.upsert(client)
7587
client.entities_to_delete.append(task)
7688
assert task
89+
assert task.key.name == "sampleTask"
7790

7891
def test_insert(self, client):
7992
task = snippets.insert(client)
@@ -89,6 +102,7 @@ def test_lookup(self, client):
89102
task = snippets.lookup(client)
90103
client.entities_to_delete.append(task)
91104
assert task
105+
assert task.key.name == "sampleTask"
92106

93107
def test_delete(self, client):
94108
snippets.delete(client)

0 commit comments

Comments
 (0)