@@ -67,7 +67,7 @@ def test_preset(self):
6767
6868class Test__get_production_dataset_id (unittest2 .TestCase ):
6969
70- def _callFUT (self , dataset_id = None ):
70+ def _callFUT (self ):
7171 from gcloud .datastore import _implicit_environ
7272 return _implicit_environ ._get_production_dataset_id ()
7373
@@ -94,7 +94,7 @@ def test_value_set(self):
9494
9595class Test__get_gcd_dataset_id (unittest2 .TestCase ):
9696
97- def _callFUT (self , dataset_id = None ):
97+ def _callFUT (self ):
9898 from gcloud .datastore import _implicit_environ
9999 return _implicit_environ ._get_gcd_dataset_id ()
100100
@@ -146,6 +146,43 @@ def test_value_set(self):
146146 self .assertEqual (dataset_id , APP_ENGINE_ID )
147147
148148
149+ class Test_compute_engine_id (unittest2 .TestCase ):
150+
151+ def _callFUT (self ):
152+ from gcloud .datastore import _implicit_environ
153+ return _implicit_environ .compute_engine_id ()
154+
155+ def _monkeyConnection (self , connection ):
156+ from gcloud ._testing import _Monkey
157+ from gcloud .datastore import _implicit_environ
158+
159+ def _factory (host , timeout ):
160+ connection .host = host
161+ connection .timeout = timeout
162+ return connection
163+
164+ return _Monkey (_implicit_environ , HTTPConnection = _factory )
165+
166+ def test_bad_status (self ):
167+ connection = _HTTPConnection (404 , None )
168+ with self ._monkeyConnection (connection ):
169+ dataset_id = self ._callFUT ()
170+ self .assertEqual (dataset_id , None )
171+
172+ def test_success (self ):
173+ COMPUTE_ENGINE_ID = object ()
174+ connection = _HTTPConnection (200 , COMPUTE_ENGINE_ID )
175+ with self ._monkeyConnection (connection ):
176+ dataset_id = self ._callFUT ()
177+ self .assertEqual (dataset_id , COMPUTE_ENGINE_ID )
178+
179+ def test_socket_raises (self ):
180+ connection = _TimeoutHTTPConnection ()
181+ with self ._monkeyConnection (connection ):
182+ dataset_id = self ._callFUT ()
183+ self .assertEqual (dataset_id , None )
184+
185+
149186class Test__determine_default_dataset_id (unittest2 .TestCase ):
150187
151188 def _callFUT (self , dataset_id = None ):
0 commit comments