10000 Updating datastore URI template for v1beta3. · googleapis/google-cloud-python@73be231 · GitHub
[go: up one dir, main page]

Skip to content

Commit 73be231

Browse files
committed
Updating datastore URI template for v1beta3.
Also updating the docs link in the README.
1 parent f220a36 commit 73be231

File tree

3 files changed

+55
-100
lines changed

3 files changed

+55
-100
lines changed

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ writes, strong consistency for reads and ancestor queries, and eventual
8686
consistency for all other queries.
8787

8888
.. _Cloud Datastore: https://cloud.google.com/datastore/docs
89-
.. _Datastore API docs: https://cloud.google.com/datastore/docs/apis/v1beta2/
89+
.. _Datastore API docs: https://cloud.google.com/datastore/docs/apis/v1beta3/
9090

9191
See the ``gcloud-python`` API `datastore documentation`_ to learn how to
9292
interact with the Cloud Datastore using this Client Library.

gcloud/datastore/connection.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,17 @@ class Connection(connection.Connection):
4040
from :mod:`gcloud.connection`.
4141
"""
4242

43-
API_BASE_URL = 'https://www.googleapis.com'
43+
API_BASE_URL = 'https://datastore.googleapis.com'
4444
"""The base of the API call URL."""
4545

46-
API_VERSION = 'v1beta2'
46+
API_VERSION = 'v1beta3'
4747
"""The version of the API, used in building the API call's URL."""
4848

49-
API_URL_TEMPLATE = ('{api_base}/datastore/{api_version}'
50-
'/datasets/{dataset_id}/{method}')
49+
API_URL_TEMPLATE = ('{api_base}/{api_version}/projects'
50+
'/{project}:{method}')
5151
"""A template for the URL of a particular API call."""
5252

53-
SCOPE = ('https://www.googleapis.com/auth/datastore',
54-
'https://www.googleapis.com/auth/userinfo.email')
53+
SCOPE = ('https://www.googleapis.com/auth/datastore',)
5554
"""The scopes required for authenticating as a Cloud Datastore consumer."""
5655

5756
def __init__(self, credentials=None, http=None, api_base_url=None):
@@ -86,7 +85,7 @@ def _request(self, dataset_id, method, data):
8685
'User-Agent': self.USER_AGENT,
8786
}
8887
headers, content = self.http.request(
89-
uri=self.build_api_url(dataset_id=dataset_id, method=method),
88+
uri=self.build_api_url(project=dataset_id, method=method),
9089
method='POST', headers=headers, body=data)
9190

9291
status = headers['status']
@@ -117,16 +116,15 @@ def _rpc(self, dataset_id, method, request_pb, response_pb_cls):
117116
data=request_pb.SerializeToString())
118117
return response_pb_cls.FromString(response)
119118

120-
def build_api_url(self, dataset_id, method, base_url=None,
119+
def build_api_url(self, project, method, base_url=None,
121120
api_version=None):
122121
"""Construct the URL for a particular API call.
123122
124123
This method is used internally to come up with the URL to use when
125124
making RPCs to the Cloud Datastore API.
126125
127-
:type dataset_id: string
128-
:param dataset_id: The ID of the dataset to connect to. This is
129-
usually your project name in the cloud console.
126+
:type project: string
127+
:param project: The project to make the request for.
130128
131129
:type method: string
132130
:param method: The API method to call (ie, runQuery, lookup, ...).
@@ -142,7 +140,7 @@ def build_api_url(self, dataset_id, method, base_url=None,
142140
return self.API_URL_TEMPLATE.format(
143141
api_base=(base_url or self.api_base_url),
144142
api_version=(api_version or self.API_VERSION),
145-
dataset_id=dataset_id, method=method)
143+
project=project, method=method)
146144

147145
def lookup(self, dataset_id, key_pbs,
148146
eventual=False, transaction_id=None):

gcloud/datastore/test_connection.py

Lines changed: 44 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,9 @@ def _verifyProtobufCall(self, called_with, URI, conn):
4747
conn.USER_AGENT)
4848

4949
def test_default_url(self):
50-
from gcloud.connection import API_BASE_URL
51-
50+
klass = self._getTargetClass()
5251
conn = self._makeOne()
53-
self.assertEqual(conn.api_base_url, API_BASE_URL)
52+
self.assertEqual(conn.api_base_url, klass.API_BASE_URL)
5453

5554
def test_custom_url_from_env(self):
5655
import os
@@ -143,11 +142,9 @@ def test__request_w_200(self):
143142
conn = self._makeOne()
144143
URI = '/'.join([
145144
conn.api_base_url,
146-
'datastore',
147145
conn.API_VERSION,
148-
'datasets',
149-
DATASET_ID,
150-
METHOD,
146+
'projects',
147+
DATASET_ID + ':' + METHOD,
151148
])
152149
http = conn._http = Http({'status': '200'}, 'CONTENT')
153150
self.assertEqual(conn._request(DATASET_ID, METHOD, DATA), 'CONTENT')
@@ -189,11 +186,9 @@ def FromString(cls, pb):
189186
conn = self._makeOne()
190187
URI = '/'.join([
191188
conn.api_base_url,
192-
'datastore',
193189
conn.API_VERSION,
194-
'datasets',
195-
DATASET_ID,
196-
METHOD,
190+
'projects',
191+
DATASET_ID + ':' + METHOD,
197192
])
198193
http = conn._http = Http({'status': '200'}, 'CONTENT')
199194
response = conn._rpc(DATASET_ID, METHOD, ReqPB(), RspPB)
@@ -208,11 +203,9 @@ def test_build_api_url_w_default_base_version(self):
208203
conn = self._makeOne()
209204
URI = '/'.join([
210205
conn.api_base_url,
211-
'datastore',
212206
conn.API_VERSION,
213-
'datasets',
214-
DATASET_ID,
215-
METHOD,
207+
'projects',
208+
DATASET_ID + ':' + METHOD,
216209
])
217210
self.assertEqual(conn.build_api_url(DATASET_ID, METHOD), URI)
218211

@@ -224,11 +217,9 @@ def test_build_api_url_w_explicit_base_version(self):
224217
conn = self._makeOne()
225218
URI = '/'.join([
226219
BASE,
227-
'datastore',
228220
VER,
229-
'datasets',
230-
DATASET_ID,
231-
METHOD,
221+
'projects',
222+
DATASET_ID + ':' + METHOD,
232223
])
233224
self.assertEqual(conn.build_api_url(DATASET_ID, METHOD, BASE, VER),
234225
URI)
@@ -242,11 +233,9 @@ def test_lookup_single_key_empty_response(self):
242233
conn = self._makeOne()
243234
URI = '/'.join([
244235
conn.api_base_url,
245-
'datastore',
246236
conn.API_VERSION,
247-
'datasets',
248-
DATASET_ID,
249-
'lookup',
237+
'projects',
238+
DATASET_ID + ':lookup',
250239
])
251240
http = conn._http = Http({'status': '200'}, rsp_pb.SerializeToString())
252241
found, missing, deferred = conn.lookup(DATASET_ID, [key_pb])
@@ -271,11 +260,9 @@ def test_lookup_single_key_empty_response_w_eventual(self):
271260
conn = self._makeOne()
272261
URI = '/'.join([
273262
conn.api_base_url,
274-
'datastore',
275263
conn.API_VERSION,
276-
'datasets',
277-
DATASET_ID,
278-
'lookup',
264+
'projects',
265+
DATASET_ID + ':lookup',
279266
])
280267
http = conn._http = Http({'status': '200'}, rsp_pb.SerializeToString())
281268
found, missing, deferred = conn.lookup(DATASET_ID, [key_pb],
@@ -313,11 +300,9 @@ def test_lookup_single_key_empty_response_w_transaction(self):
313300
conn = self._makeOne()
314301
URI = '/'.join([
315302
conn.api_base_url,
316-
'datastore',
317303
conn.API_VERSION,
318-
'datasets',
319-
DATASET_ID,
320-
'lookup',
304+
'projects',
305+
DATASET_ID + ':lookup',
321306
])
322307
http = conn._http = Http({'status': '200'}, rsp_pb.SerializeToString())
323308
found, missing, deferred = conn.lookup(DATASET_ID, [key_pb],
@@ -348,11 +333,9 @@ def test_lookup_single_key_nonempty_response(self):
348333
conn = self._makeOne()
349334
URI = '/'.join([
350335
conn.api_base_url,
351-
'datastore',
352336
conn.API_VERSION,
353-
'datasets',
354-
DATASET_ID,
355-
'lookup',
337+
'projects',
338+
DATASET_ID + ':lookup',
356339
])
357340
http = conn._http = Http({'status': '200'}, rsp_pb.SerializeToString())
358341
(found,), missing, deferred = conn.lookup(DATASET_ID, [key_pb])
@@ -379,11 +362,9 @@ def test_lookup_multiple_keys_empty_response(self):
379362
conn = self._makeOne()
380363
URI = '/'.join([
381364
conn.api_base_url,
382-
'datastore',
383365
conn.API_VERSION,
384-
'datasets',
385-
DATASET_ID,
386-
'lookup',
366+
'projects',
367+
DATASET_ID + ':lookup',
387368
])
388369
http = conn._http = Http({'status': '200'}, rsp_pb.SerializeToString())
389370
found, missing, deferred = conn.lookup(DATASET_ID, [key_pb1, key_pb2])
@@ -414,11 +395,9 @@ def test_lookup_multiple_keys_w_missing(self):
414395
conn = self._makeOne()
415396
URI = '/'.join([
416397
conn.api_base_url,
417-
'datastore',
418398
conn.API_VERSION,
419-
'datasets',
420-
DATASET_ID,
421-
'lookup',
399+
'projects',
400+
DATASET_ID + ':lookup',
422401
])
423402
http = conn._http = Http({'status': '200'}, rsp_pb.SerializeToString())
424403
result, missing, deferred = conn.lookup(DATASET_ID, [key_pb1, key_pb2])
@@ -448,11 +427,9 @@ def test_lookup_multiple_keys_w_deferred(self):
448427
conn = self._makeOne()
449428
URI = '/'.join([
450429
conn.api_base_url,
451-
'datastore',
452430
conn.API_VERSION,
453-
'datasets',
454-
DATASET_ID,
455-
'lookup',
431+
'projects',
432+
DATASET_ID + ':lookup',
456433
])
457434
http = conn._http = Http({'status': '200'}, rsp_pb.SerializeToString())
458435
result, missing, deferred = conn.lookup(DATASET_ID, [key_pb1, key_pb2])
@@ -490,11 +467,9 @@ def test_run_query_w_eventual_no_transaction(self):
490467
conn = self._makeOne()
491468
URI = '/'.join([
492469
conn.api_base_url,
493-
'datastore',
494470
conn.API_VERSION,
495-
'datasets',
496-
DATASET_ID,
497-
'runQuery',
471+
'projects',
472+
DATASET_ID + ':runQuery',
498473
])
499474
http = conn._http = Http({'status': '200'}, rsp_pb.SerializeToString())
500475
pbs, end, more, skipped = conn.run_query(DATASET_ID, q_pb,
@@ -531,11 +506,9 @@ def test_run_query_wo_eventual_w_transaction(self):
531506
conn = self._makeOne()
532507
URI = '/'.join([
533508
conn.api_base_url,
534-
'datastore',
535509
conn.API_VERSION,
536-
'datasets',
537-
DATASET_ID,
538-
'runQuery',
510+
'projects',
511+
DATASET_ID + ':runQuery',
539512
])
540513
http = conn._http = Http({'status': '200'}, rsp_pb.SerializeToString())
541514
pbs, end, more, skipped = conn.run_query(
@@ -589,11 +562,9 @@ def test_run_query_wo_namespace_empty_result(self):
589562
conn = self._makeOne()
590563
URI = '/'.join([
591564
conn.api_base_url,
592-
'datastore',
593565
conn.API_VERSION,
594-
'datasets',
595-
DATASET_ID,
596-
'runQuery',
566+
'projects',
567+
DATASET_ID + ':runQuery',
597568
])
598569
http = conn._http = Http({'status': '200'}, rsp_pb.SerializeToString())
599570
pbs, end, more, skipped = conn.run_query(DATASET_ID, q_pb)
@@ -624,11 +595,9 @@ def test_run_query_w_namespace_nonempty_result(self):
624595
conn = self._makeOne()
625596
URI = '/'.join([
626597
conn.api_base_url,
627-
'datastore',
628598
conn.API_VERSION,
629-
'datasets',
630-
DATASET_ID,
631-
'runQuery',
599+
'projects',
600+
DATASET_ID + ':runQuery',
632601
])
633602
http = conn._http = Http({'status': '200'}, rsp_pb.SerializeToString())
634603
pbs = conn.run_query(DATASET_ID, q_pb, 'NS')[0]
@@ -651,11 +620,9 @@ def test_begin_transaction(self):
651620
conn = self._makeOne()
652621
URI = '/'.join([
653622
conn.api_base_url,
654-
'datastore',
655623
conn.API_VERSION,
656-
'datasets',
657-
DATASET_ID,
658-
'beginTransaction',
624+
'projects',
625+
DATASET_ID + ':beginTransaction',
659626
])
660627
http = conn._http = Http({'status': '200'}, rsp_pb.SerializeToString())
661628
self.assertEqual(conn.begin_transaction(DATASET_ID), TRANSACTION)
@@ -683,11 +650,9 @@ def test_commit_wo_transaction(self):
683650
conn = self._makeOne()
684651
URI = '/'.join([
685652
conn.api_base_url,
686-
'datastore',
687653
conn.API_VERSION,
688-
'datasets',
689-
DATASET_ID,
690-
'commit',
654+
'projects',
655+
DATASET_ID + ':commit',
691656
])
692657
http = conn._http = Http({'status': '200'}, rsp_pb.SerializeToString())
693658

@@ -730,11 +695,9 @@ def test_commit_w_transaction(self):
730695
conn = self._makeOne()
731696
URI = '/'.join([
732697
conn.api_base_url,
733-
'datastore',
734698
conn.API_VERSION,
735-
'datasets',
736-
DATASET_ID,
737-
'commit',
699+
'projects',
700+
DATASET_ID + ':commit',
738701
])
739702
http = conn._http = Http({'status': '200'}, rsp_pb.SerializeToString())
740703

@@ -769,11 +732,9 @@ def test_rollback_ok(self):
769732
conn = self._makeOne()
770733
URI = '/'.join([
771734
conn.api_base_url,
772-
'datastore',
773735
conn.API_VERSION,
774-
'datasets',
775-
DATASET_ID,
776-
'rollback',
736+
'projects',
737+
DATASET_ID + ':rollback',
777738
])
778739
http = conn._http = Http({'status': '200'}, rsp_pb.SerializeToString())
779740
self.assertEqual(conn.rollback(DATASET_ID, TRANSACTION), None)
@@ -792,11 +753,9 @@ def test_allocate_ids_empty(self):
792753
conn = self._makeOne()
793754
URI = '/'.join([
794755
conn.api_base_url,
795-
'datastore',
796756
conn.API_VERSION,
797-
'datasets',
798-
DATASET_ID,
799-
'allocateIds',
757+
'projects',
758+
DATASET_ID + ':allocateIds',
800759
])
801760
http = conn._http = Http({'status': '200'}, rsp_pb.SerializeToString())
802761
self.assertEqual(conn.allocate_ids(DATASET_ID, []), [])
@@ -825,11 +784,9 @@ def test_allocate_ids_non_empty(self):
825784
conn = self._makeOne()
826785
URI = '/'.join([
827786
conn.api_base_url,
828-
'datastore',
829787
conn.API_VERSION,
830-
'datasets',
831-
DATASET_ID,
832-
'allocateIds',
788+
'projects',
789+
DATASET_ID + ':allocateIds',
833790
])
834791
http = conn._http = Http({'status': '200'}, rsp_pb.SerializeToString())
835792
self.assertEqual(conn.allocate_ids(DATASET_ID, before_key_pbs),

0 commit comments

Comments
 (0)
0