From 1b0b19cd720ec7dc736f460bef155c3f279d2d70 Mon Sep 17 00:00:00 2001 From: Tres Seaver Date: Mon, 13 Jul 2015 14:06:54 -0400 Subject: [PATCH] Nuke used-only-once '_get_connection'. Addresses: https://github.com/GoogleCloudPlatform/gcloud-python/pull/979#commitcomment-12124175 --- gcloud/datastore/client.py | 11 +---------- gcloud/datastore/test_client.py | 30 +++++++----------------------- 2 files changed, 8 insertions(+), 33 deletions(-) diff --git a/gcloud/datastore/client.py b/gcloud/datastore/client.py index ec267400ac7d..ae07af1d2746 100644 --- a/gcloud/datastore/client.py +++ b/gcloud/datastore/client.py @@ -79,15 +79,6 @@ def _determine_default_dataset_id(dataset_id=None): return dataset_id -def _get_connection(): - """Shortcut method to establish a connection to the Cloud Datastore. - - :rtype: :class:`gcloud.datastore.connection.Connection` - :returns: A connection defined with the proper credentials. - """ - return Connection.from_environment() - - def _extended_lookup(connection, dataset_id, key_pbs, missing=None, deferred=None, eventual=False, transaction_id=None): @@ -186,7 +177,7 @@ def __init__(self, dataset_id=None, namespace=None, connection=None): raise EnvironmentError('Dataset ID could not be inferred.') self.dataset_id = dataset_id if connection is None: - connection = _get_connection() + connection = Connection.from_environment() self.connection = connection self._batch_stack = _LocalStack() self.namespace = namespace diff --git a/gcloud/datastore/test_client.py b/gcloud/datastore/test_client.py index d7c0968aac60..81ce96f04faa 100644 --- a/gcloud/datastore/test_client.py +++ b/gcloud/datastore/test_client.py @@ -165,28 +165,6 @@ def test_gce(self): ['prod_mock', 'gcd_mock', 'gae_mock', 'gce_mock']) -class Test__get_connection(unittest2.TestCase): - - def _callFUT(self): - from gcloud.datastore.client import _get_connection - return _get_connection() - - def test_it(self): - from gcloud import credentials - from gcloud.datastore.connection import SCOPE - from gcloud.datastore.connection import Connection - from gcloud.test_credentials import _Client - from gcloud._testing import _Monkey - - client = _Client() - with _Monkey(credentials, client=client): - found = self._callFUT() - self.assertTrue(isinstance(found, Connection)) - self.assertTrue(found._credentials is client._signed) - self.assertEqual(found._credentials._scopes, SCOPE) - self.assertTrue(client._get_app_default_called) - - class TestClient(unittest2.TestCase): DATASET_ID = 'DATASET' @@ -211,10 +189,16 @@ def test_ctor_w_implicit_inputs(self): OTHER = 'other' conn = object() + + class _Connection(object): + @classmethod + def from_environment(cls): + return conn + klass = self._getTargetClass() with _Monkey(_MUT, _determine_default_dataset_id=lambda x: x or OTHER, - _get_connection=lambda: conn): + Connection=_Connection): client = klass() self.assertEqual(client.dataset_id, OTHER) self.assertEqual(client.namespace, None)