Skip to content

Commit 91bd475

Browse files
committed
Add /datastore/ in emulator URI path.
Fixes #1707.
1 parent 8da951d commit 91bd475

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

gcloud/datastore/connection.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,12 @@ class Connection(connection.Connection):
5656
def __init__(self, credentials=None, http=None, api_base_url=None):
5757
super(Connection, self).__init__(credentials=credentials, http=http)
5858
if api_base_url is None:
59-
api_base_url = os.getenv(GCD_HOST,
60-
self.__class__.API_BASE_URL)
59+
try:
60+
# gcd.sh has /datastore/ in the path still since it supports
61+
# v1beta2 and v1beta3 simultaneously.
62+
api_base_url = '%s/datastore' % (os.environ[GCD_HOST],)
63+
except KeyError:
64+
api_base_url = self.__class__.API_BASE_URL
6165
self.api_base_url = api_base_url
6266

6367
def _request(self, project, method, data):

gcloud/datastore/test_connection.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,14 @@ def test_custom_url_from_env(self):
5757
from gcloud.connection import API_BASE_URL
5858
from gcloud.environment_vars import GCD_HOST
5959

60-
HOST = object()
60+
HOST = 'CURR_HOST'
6161
fake_environ = {GCD_HOST: HOST}
6262

63-
with _Monkey(os, getenv=fake_environ.get):
63+
with _Monkey(os, environ=fake_environ):
6464
conn = self._makeOne()
6565

6666
self.assertNotEqual(conn.api_base_url, API_BASE_URL)
67-
self.assertEqual(conn.api_base_url, HOST)
67+
self.assertEqual(conn.api_base_url, HOST + '/datastore')
6868

6969
def test_custom_url_from_constructor(self):
7070
from gcloud.connection import API_BASE_URL
@@ -84,7 +84,7 @@ def test_custom_url_constructor_and_env(self):
8484
HOST2 = object()
8585
fake_environ = {GCD_HOST: HOST1}
8686

87-
with _Monkey(os, getenv=fake_environ.get):
87+
with _Monkey(os, environ=fake_environ):
8888
conn = self._makeOne(api_base_url=HOST2)
8989

9090
self.assertNotEqual(conn.api_base_url, API_BASE_URL)

0 commit comments

Comments
 (0)