diff --git a/bigquery/google/cloud/bigquery/_http.py b/bigquery/google/cloud/bigquery/_http.py index 85a25d643d1f..fd5bb3cb8b23 100644 --- a/bigquery/google/cloud/bigquery/_http.py +++ b/bigquery/google/cloud/bigquery/_http.py @@ -14,10 +14,10 @@ """Create / interact with Google BigQuery connections.""" -from google.cloud import connection as base_connection +from google.cloud import _http -class Connection(base_connection.JSONConnection): +class Connection(_http.JSONConnection): """A connection to Google BigQuery via the JSON REST API.""" API_BASE_URL = 'https://www.googleapis.com' diff --git a/bigquery/google/cloud/bigquery/dataset.py b/bigquery/google/cloud/bigquery/dataset.py index f29fdbc8a243..e209433b5e10 100644 --- a/bigquery/google/cloud/bigquery/dataset.py +++ b/bigquery/google/cloud/bigquery/dataset.py @@ -422,7 +422,7 @@ def create(self, client=None): """ client = self._require_client(client) path = '/projects/%s/datasets' % (self.project,) - api_response = client.connection.api_request( + api_response = client._connection.api_request( method='POST', path=path, data=self._build_resource()) self._set_properties(api_response) @@ -443,8 +443,8 @@ def exists(self, client=None): client = self._require_client(client) try: - client.connection.api_request(method='GET', path=self.path, - query_params={'fields': 'id'}) + client._connection.api_request(method='GET', path=self.path, + query_params={'fields': 'id'}) except NotFound: return False else: @@ -463,7 +463,7 @@ def reload(self, client=None): """ client = self._require_client(client) - api_response = client.connection.api_request( + api_response = client._connection.api_request( method='GET', path=self.path) self._set_properties(api_response) @@ -502,7 +502,7 @@ def patch(self, client=None, **kw): if 'location' in kw: partial['location'] = kw['location'] - api_response = client.connection.api_request( + api_response = client._connection.api_request( method='PATCH', path=self.path, data=partial) self._set_properties(api_response) @@ -518,7 +518,7 @@ def update(self, client=None): ``client`` stored on the current dataset. """ client = self._require_client(client) - api_response = client.connection.api_request( + api_response = client._connection.api_request( method='PUT', path=self.path, data=self._build_resource()) self._set_properties(api_response) @@ -534,7 +534,7 @@ def delete(self, client=None): ``client`` stored on the current dataset. """ client = self._require_client(client) - client.connection.api_request(method='DELETE', path=self.path) + client._connection.api_request(method='DELETE', path=self.path) def list_tables(self, max_results=None, page_token=None): """List tables for the project associated with this client. diff --git a/bigquery/google/cloud/bigquery/job.py b/bigquery/google/cloud/bigquery/job.py index 7766c120c5cd..203dd2df6dd0 100644 --- a/bigquery/google/cloud/bigquery/job.py +++ b/bigquery/google/cloud/bigquery/job.py @@ -316,7 +316,7 @@ def begin(self, client=None): client = self._require_client(client) path = '/projects/%s/jobs' % (self.project,) - api_response = client.connection.api_request( + api_response = client._connection.api_request( method='POST', path=path, data=self._build_resource()) self._set_properties(api_response) @@ -337,8 +337,8 @@ def exists(self, client=None): client = self._require_client(client) try: - client.connection.api_request(method='GET', path=self.path, - query_params={'fields': 'id'}) + client._connection.api_request(method='GET', path=self.path, + query_params={'fields': 'id'}) except NotFound: return False else: @@ -357,7 +357,7 @@ def reload(self, client=None): """ client = self._require_client(client) - api_response = client.connection.api_request( + api_response = client._connection.api_request( method='GET', path=self.path) self._set_properties(api_response) @@ -374,7 +374,7 @@ def cancel(self, client=None): """ client = self._require_client(client) - api_response = client.connection.api_request( + api_response = client._connection.api_request( method='POST', path='%s/cancel' % (self.path,)) self._set_properties(api_response['job']) diff --git a/bigquery/google/cloud/bigquery/query.py b/bigquery/google/cloud/bigquery/query.py index 5c7c3681a539..fa1b1da63883 100644 --- a/bigquery/google/cloud/bigquery/query.py +++ b/bigquery/google/cloud/bigquery/query.py @@ -334,7 +334,7 @@ def run(self, client=None): client = self._require_client(client) path = '/projects/%s/queries' % (self.project,) - api_response = client.connection.api_request( + api_response = client._connection.api_request( method='POST', path=path, data=self._build_resource()) self._set_properties(api_response) @@ -392,9 +392,9 @@ def fetch_data(self, max_results=None, page_token=None, start_index=None, params['timeoutMs'] = timeout_ms path = '/projects/%s/queries/%s' % (self.project, self.name) - response = client.connection.api_request(method='GET', - path=path, - query_params=params) + response = client._connection.api_request(method='GET', + path=path, + query_params=params) self._set_properties(response) total_rows = response.get('totalRows') diff --git a/bigquery/google/cloud/bigquery/table.py b/bigquery/google/cloud/bigquery/table.py index 870d8520159e..f8b52f772f87 100644 --- a/bigquery/google/cloud/bigquery/table.py +++ b/bigquery/google/cloud/bigquery/table.py @@ -492,7 +492,7 @@ def create(self, client=None): client = self._require_client(client) path = '/projects/%s/datasets/%s/tables' % ( self._dataset.project, self._dataset.name) - api_response = client.connection.api_request( + api_response = client._connection.api_request( method='POST', path=path, data=self._build_resource()) self._set_properties(api_response) @@ -513,8 +513,8 @@ def exists(self, client=None): client = self._require_client(client) try: - client.connection.api_request(method='GET', path=self.path, - query_params={'fields': 'id'}) + client._connection.api_request(method='GET', path=self.path, + query_params={'fields': 'id'}) except NotFound: return False else: @@ -533,7 +533,7 @@ def reload(self, client=None): """ client = self._require_client(client) - api_response = client.connection.api_request( + api_response = client._connection.api_request( method='GET', path=self.path) self._set_properties(api_response) @@ -608,7 +608,7 @@ def patch(self, partial['schema'] = { 'fields': _build_schema_resource(schema)} - api_response = client.connection.api_request( + api_response = client._connection.api_request( method='PATCH', path=self.path, data=partial) self._set_properties(api_response) @@ -624,7 +624,7 @@ def update(self, client=None): ``client`` stored on the current dataset. """ client = self._require_client(client) - api_response = client.connection.api_request( + api_response = client._connection.api_request( method='PUT', path=self.path, data=self._build_resource()) self._set_properties(api_response) @@ -640,7 +640,7 @@ def delete(self, client=None): ``client`` stored on the current dataset. """ client = self._require_client(client) - client.connection.api_request(method='DELETE', path=self.path) + client._connection.api_request(method='DELETE', path=self.path) def fetch_data(self, max_results=None, page_token=None, client=None): """API call: fetch the table data via a GET request @@ -764,7 +764,7 @@ def insert_data(self, if template_suffix is not None: data['templateSuffix'] = template_suffix - response = client.connection.api_request( + response = client._connection.api_request( method='POST', path='%s/insertAll' % self.path, data=data) @@ -885,7 +885,7 @@ def upload_from_file(self, a file opened in text mode. """ client = self._require_client(client) - connection = client.connection + connection = client._connection content_type = 'application/octet-stream' # Rewind the file if desired. diff --git a/bigquery/unit_tests/test_client.py b/bigquery/unit_tests/test_client.py index 9034658692d9..61ad81227aee 100644 --- a/bigquery/unit_tests/test_client.py +++ b/bigquery/unit_tests/test_client.py @@ -31,9 +31,9 @@ def test_ctor(self): creds = _Credentials() http = object() client = self._make_one(project=PROJECT, credentials=creds, http=http) - self.assertIsInstance(client.connection, Connection) - self.assertIs(client.connection.credentials, creds) - self.assertIs(client.connection.http, http) + self.assertIsInstance(client._connection, Connection) + self.assertIs(client._connection.credentials, creds) + self.assertIs(client._connection.http, http) def test_list_projects_defaults(self): import six @@ -59,7 +59,7 @@ def test_list_projects_defaults(self): } creds = _Credentials() client = self._make_one(PROJECT_1, creds) - conn = client.connection = _Connection(DATA) + conn = client._connection = _Connection(DATA) iterator = client.list_projects() page = six.next(iterator.pages) @@ -88,7 +88,7 @@ def test_list_projects_explicit_response_missing_projects_key(self): DATA = {} creds = _Credentials() client = self._make_one(PROJECT, creds) - conn = client.connection = _Connection(DATA) + conn = client._connection = _Connection(DATA) iterator = client.list_projects(max_results=3, page_token=TOKEN) page = six.next(iterator.pages) @@ -130,7 +130,7 @@ def test_list_datasets_defaults(self): } creds = _Credentials() client = self._make_one(PROJECT, creds) - conn = client.connection = _Connection(DATA) + conn = client._connection = _Connection(DATA) iterator = client.list_datasets() page = six.next(iterator.pages) @@ -158,7 +158,7 @@ def test_list_datasets_explicit_response_missing_datasets_key(self): DATA = {} creds = _Credentials() client = self._make_one(PROJECT, creds) - conn = client.connection = _Connection(DATA) + conn = client._connection = _Connection(DATA) iterator = client.list_datasets( include_all=True, max_results=3, page_token=TOKEN) @@ -306,7 +306,7 @@ def test_list_jobs_defaults(self): } creds = _Credentials() client = self._make_one(PROJECT, creds) - conn = client.connection = _Connection(DATA) + conn = client._connection = _Connection(DATA) iterator = client.list_jobs() page = six.next(iterator.pages) @@ -362,7 +362,7 @@ def test_list_jobs_load_job_wo_sourceUris(self): } creds = _Credentials() client = self._make_one(PROJECT, creds) - conn = client.connection = _Connection(DATA) + conn = client._connection = _Connection(DATA) iterator = client.list_jobs() page = six.next(iterator.pages) @@ -390,7 +390,7 @@ def test_list_jobs_explicit_missing(self): TOKEN = 'TOKEN' creds = _Credentials() client = self._make_one(PROJECT, creds) - conn = client.connection = _Connection(DATA) + conn = client._connection = _Connection(DATA) iterator = client.list_jobs(max_results=1000, page_token=TOKEN, all_users=True, state_filter='done') diff --git a/bigquery/unit_tests/test_dataset.py b/bigquery/unit_tests/test_dataset.py index 1493d266d44f..ec7c56722368 100644 --- a/bigquery/unit_tests/test_dataset.py +++ b/bigquery/unit_tests/test_dataset.py @@ -785,7 +785,7 @@ class _Client(object): def __init__(self, project='project', connection=None): self.project = project - self.connection = connection + self._connection = connection class _Connection(object): diff --git a/bigquery/unit_tests/test_job.py b/bigquery/unit_tests/test_job.py index 67b1477f9732..c73715262ba4 100644 --- a/bigquery/unit_tests/test_job.py +++ b/bigquery/unit_tests/test_job.py @@ -1648,7 +1648,7 @@ class _Client(object): def __init__(self, project='project', connection=None): self.project = project - self.connection = connection + self._connection = connection def dataset(self, name): from google.cloud.bigquery.dataset import Dataset diff --git a/bigquery/unit_tests/test_query.py b/bigquery/unit_tests/test_query.py index 58bc8ced8e1b..43aedf334ce0 100644 --- a/bigquery/unit_tests/test_query.py +++ b/bigquery/unit_tests/test_query.py @@ -440,7 +440,7 @@ class _Client(object): def __init__(self, project='project', connection=None): self.project = project - self.connection = connection + self._connection = connection def dataset(self, name): from google.cloud.bigquery.dataset import Dataset diff --git a/bigquery/unit_tests/test_table.py b/bigquery/unit_tests/test_table.py index d049107a0769..73fd84cec5e3 100644 --- a/bigquery/unit_tests/test_table.py +++ b/bigquery/unit_tests/test_table.py @@ -1880,7 +1880,7 @@ class _Client(object): def __init__(self, project='project', connection=None): self.project = project - self.connection = connection + self._connection = connection def job_from_resource(self, resource): # pylint: disable=unused-argument return self._job diff --git a/bigtable/google/cloud/bigtable/client.py b/bigtable/google/cloud/bigtable/client.py index e6d8173f8b39..c2c160592228 100644 --- a/bigtable/google/cloud/bigtable/client.py +++ b/bigtable/google/cloud/bigtable/client.py @@ -41,7 +41,7 @@ from google.cloud.bigtable.instance import _EXISTING_INSTANCE_LOCATION_ID from google.cloud.client import _ClientFactoryMixin from google.cloud.client import _ClientProjectMixin -from google.cloud.connection import DEFAULT_USER_AGENT +from google.cloud._http import DEFAULT_USER_AGENT from google.cloud.credentials import get_credentials from google.cloud.environment_vars import BIGTABLE_EMULATOR diff --git a/core/google/cloud/connection.py b/core/google/cloud/_http.py similarity index 100% rename from core/google/cloud/connection.py rename to core/google/cloud/_http.py diff --git a/core/google/cloud/client.py b/core/google/cloud/client.py index 893cde192910..521fa11e8e2b 100644 --- a/core/google/cloud/client.py +++ b/core/google/cloud/client.py @@ -18,7 +18,7 @@ import six from google.cloud._helpers import _determine_default_project -from google.cloud.connection import Connection +from google.cloud._http import Connection from google.cloud.credentials import get_credentials @@ -120,7 +120,7 @@ class Client(_ClientFactoryMixin): def __init__(self, credentials=None, http=None): if credentials is None and http is None: credentials = get_credentials() - self.connection = self._connection_class( + self._connection = self._connection_class( credentials=credentials, http=http) diff --git a/core/google/cloud/iterator.py b/core/google/cloud/iterator.py index 5f774aa4a846..2d0a93689d32 100644 --- a/core/google/cloud/iterator.py +++ b/core/google/cloud/iterator.py @@ -382,12 +382,12 @@ def _get_next_page_response(self): """ params = self._get_query_params() if self._HTTP_METHOD == 'GET': - return self.client.connection.api_request( + return self.client._connection.api_request( method=self._HTTP_METHOD, path=self.path, query_params=params) elif self._HTTP_METHOD == 'POST': - return self.client.connection.api_request( + return self.client._connection.api_request( method=self._HTTP_METHOD, path=self.path, data=params) diff --git a/core/google/cloud/operation.py b/core/google/cloud/operation.py index 388e45dcbb94..8bc848e7facb 100644 --- a/core/google/cloud/operation.py +++ b/core/google/cloud/operation.py @@ -104,7 +104,7 @@ class Operation(object): :type client: :class:`~google.cloud.client.Client` :param client: The client used to poll for the status of the operation. If the operation was created via JSON/HTTP, the client - must own a :class:`~google.cloud.connection.Connection` + must own a :class:`~google.cloud._http.Connection` to send polling requests. If created via protobuf, the client must have a gRPC stub in the ``_operations_stub`` attribute. @@ -218,7 +218,7 @@ def _get_operation_http(self): :returns: The latest status of the current operation. """ path = 'operations/%s' % (self.name,) - api_response = self.client.connection.api_request( + api_response = self.client._connection.api_request( method='GET', path=path) return json_format.ParseDict( api_response, operations_pb2.Operation()) diff --git a/core/unit_tests/test_connection.py b/core/unit_tests/test__http.py similarity index 99% rename from core/unit_tests/test_connection.py rename to core/unit_tests/test__http.py index e2eaa7e267aa..72d79a707aac 100644 --- a/core/unit_tests/test_connection.py +++ b/core/unit_tests/test__http.py @@ -19,7 +19,8 @@ class TestConnection(unittest.TestCase): @staticmethod def _get_target_class(): - from google.cloud.connection import Connection + from google.cloud._http import Connection + return Connection def _make_one(self, *args, **kw): @@ -111,7 +112,8 @@ class TestJSONConnection(unittest.TestCase): @staticmethod def _get_target_class(): - from google.cloud.connection import JSONConnection + from google.cloud._http import JSONConnection + return JSONConnection def _make_one(self, *args, **kw): diff --git a/core/unit_tests/test_client.py b/core/unit_tests/test_client.py index 3ae51b9e82cd..e7fe5c03be12 100644 --- a/core/unit_tests/test_client.py +++ b/core/unit_tests/test_client.py @@ -60,8 +60,8 @@ def mock_get_credentials(): with _Monkey(client, get_credentials=mock_get_credentials): client_obj = self._make_one() - self.assertIsInstance(client_obj.connection, _MockConnection) - self.assertIs(client_obj.connection.credentials, CREDENTIALS) + self.assertIsInstance(client_obj._connection, _MockConnection) + self.assertIs(client_obj._connection.credentials, CREDENTIALS) self.assertEqual(FUNC_CALLS, ['get_credentials']) def test_ctor_explicit(self): @@ -69,9 +69,9 @@ def test_ctor_explicit(self): HTTP = object() client_obj = self._make_one(credentials=CREDENTIALS, http=HTTP) - self.assertIsInstance(client_obj.connection, _MockConnection) - self.assertIs(client_obj.connection.credentials, CREDENTIALS) - self.assertIs(client_obj.connection.http, HTTP) + self.assertIsInstance(client_obj._connection, _MockConnection) + self.assertIs(client_obj._connection.credentials, CREDENTIALS) + self.assertIs(client_obj._connection.http, HTTP) def test_from_service_account_json(self): from google.cloud._testing import _Monkey @@ -83,7 +83,7 @@ def test_from_service_account_json(self): with _Monkey(client, ServiceAccountCredentials=mock_creds): client_obj = KLASS.from_service_account_json(MOCK_FILENAME) - self.assertIs(client_obj.connection.credentials, mock_creds._result) + self.assertIs(client_obj._connection.credentials, mock_creds._result) self.assertEqual(mock_creds.json_called, [MOCK_FILENAME]) def test_from_service_account_json_fail(self): @@ -104,7 +104,7 @@ def test_from_service_account_p12(self): client_obj = KLASS.from_service_account_p12(CLIENT_EMAIL, MOCK_FILENAME) - self.assertIs(client_obj.connection.credentials, mock_creds._result) + self.assertIs(client_obj._connection.credentials, mock_creds._result) self.assertEqual(mock_creds.p12_called, [(CLIENT_EMAIL, MOCK_FILENAME)]) @@ -155,8 +155,8 @@ def mock_get_credentials(): client_obj = self._make_one() self.assertEqual(client_obj.project, PROJECT) - self.assertIsInstance(client_obj.connection, _MockConnection) - self.assertIs(client_obj.connection.credentials, CREDENTIALS) + self.assertIsInstance(client_obj._connection, _MockConnection) + self.assertIs(client_obj._connection.credentials, CREDENTIALS) self.assertEqual( FUNC_CALLS, [(None, '_determine_default_project'), 'get_credentials']) @@ -196,9 +196,9 @@ def _explicit_ctor_helper(self, project): self.assertEqual(client_obj.project, project.decode('utf-8')) else: self.assertEqual(client_obj.project, project) - self.assertIsInstance(client_obj.connection, _MockConnection) - self.assertIs(client_obj.connection.credentials, CREDENTIALS) - self.assertIs(client_obj.connection.http, HTTP) + self.assertIsInstance(client_obj._connection, _MockConnection) + self.assertIs(client_obj._connection.credentials, CREDENTIALS) + self.assertIs(client_obj._connection.http, HTTP) def test_ctor_explicit_bytes(self): PROJECT = b'PROJECT' diff --git a/core/unit_tests/test_iterator.py b/core/unit_tests/test_iterator.py index b66deae9fdc8..7f10ea47f104 100644 --- a/core/unit_tests/test_iterator.py +++ b/core/unit_tests/test_iterator.py @@ -591,7 +591,7 @@ def api_request(self, **kw): class _Client(object): def __init__(self, connection): - self.connection = connection + self._connection = connection class SimpleIter(object): diff --git a/core/unit_tests/test_operation.py b/core/unit_tests/test_operation.py index 2f59f4a5729b..41c469ba336d 100644 --- a/core/unit_tests/test_operation.py +++ b/core/unit_tests/test_operation.py @@ -419,4 +419,4 @@ class _Client(object): def __init__(self, connection=None): self._operations_stub = _OperationsStub() - self.connection = connection + self._connection = connection diff --git a/datastore/google/cloud/datastore/_http.py b/datastore/google/cloud/datastore/_http.py index 4636b2651b7a..b66626fabccb 100644 --- a/datastore/google/cloud/datastore/_http.py +++ b/datastore/google/cloud/datastore/_http.py @@ -21,7 +21,7 @@ from google.cloud._helpers import make_insecure_stub from google.cloud._helpers import make_secure_stub -from google.cloud import connection as connection_module +from google.cloud import _http as connection_module from google.cloud.environment_vars import DISABLE_GRPC from google.cloud.environment_vars import GCD_HOST from google.cloud import exceptions diff --git a/datastore/google/cloud/datastore/batch.py b/datastore/google/cloud/datastore/batch.py index e944b56b7a6e..2c09f357ee2e 100644 --- a/datastore/google/cloud/datastore/batch.py +++ b/datastore/google/cloud/datastore/batch.py @@ -103,15 +103,6 @@ def namespace(self): """ return self._client.namespace - @property - def connection(self): - """Getter for connection over which the batch will run. - - :rtype: :class:`google.cloud.datastore._http.Connection` - :returns: The connection over which the batch will run. - """ - return self._client.connection - def _add_partial_key_entity_pb(self): """Adds a new mutation for an entity with a partial key. @@ -247,7 +238,7 @@ def _commit(self): This is called by :meth:`commit`. """ # NOTE: ``self._commit_request`` will be modified. - _, updated_keys = self.connection.commit( + _, updated_keys = self._client._connection.commit( self.project, self._commit_request, self._id) # If the back-end returns without error, we are guaranteed that # :meth:`Connection.commit` will return keys that match (length and diff --git a/datastore/google/cloud/datastore/client.py b/datastore/google/cloud/datastore/client.py index fc9cbf2ea321..c9eccdd6fd09 100644 --- a/datastore/google/cloud/datastore/client.py +++ b/datastore/google/cloud/datastore/client.py @@ -294,7 +294,7 @@ def get_multi(self, keys, missing=None, deferred=None, transaction=None): transaction = self.current_transaction entity_pbs = _extended_lookup( - connection=self.connection, + connection=self._connection, project=self.project, key_pbs=[k.to_protobuf() for k in keys], missing=missing, @@ -414,7 +414,7 @@ def allocate_ids(self, incomplete_key, num_ids): incomplete_key_pb = incomplete_key.to_protobuf() incomplete_key_pbs = [incomplete_key_pb] * num_ids - conn = self.connection + conn = self._connection allocated_key_pbs = conn.allocate_ids(incomplete_key.project, incomplete_key_pbs) allocated_ids = [allocated_key_pb.path[-1].id diff --git a/datastore/google/cloud/datastore/query.py b/datastore/google/cloud/datastore/query.py index a9488db725af..a6f6c845e17f 100644 --- a/datastore/google/cloud/datastore/query.py +++ b/datastore/google/cloud/datastore/query.py @@ -492,7 +492,7 @@ def _next_page(self): pb = self._build_protobuf() transaction = self.client.current_transaction - query_results = self.client.connection.run_query( + query_results = self.client._connection.run_query( query_pb=pb, project=self._query.project, namespace=self._query.namespace, diff --git a/datastore/google/cloud/datastore/transaction.py b/datastore/google/cloud/datastore/transaction.py index ef61d64a61d6..d3fe0b45e240 100644 --- a/datastore/google/cloud/datastore/transaction.py +++ b/datastore/google/cloud/datastore/transaction.py @@ -145,7 +145,8 @@ def begin(self): """ super(Transaction, self).begin() try: - self._id = self.connection.begin_transaction(self.project) + self._id = self._client._connection.begin_transaction( + self.project) except: self._status = self._ABORTED raise @@ -159,7 +160,7 @@ def rollback(self): - Sets the current transaction's ID to None. """ try: - self.connection.rollback(self.project, self._id) + self._client._connection.rollback(self.project, self._id) finally: super(Transaction, self).rollback() # Clear our own ID in case this gets accidentally reused. diff --git a/datastore/unit_tests/test__http.py b/datastore/unit_tests/test__http.py index 611bda7e2f3e..2b0e826143ff 100644 --- a/datastore/unit_tests/test__http.py +++ b/datastore/unit_tests/test__http.py @@ -397,7 +397,7 @@ def test_default_url(self): def test_custom_url_from_env(self): import mock - from google.cloud.connection import API_BASE_URL + from google.cloud._http import API_BASE_URL from google.cloud.environment_vars import GCD_HOST HOST = 'CURR_HOST' diff --git a/datastore/unit_tests/test_batch.py b/datastore/unit_tests/test_batch.py index 737668af02b4..0bdc8762e64c 100644 --- a/datastore/unit_tests/test_batch.py +++ b/datastore/unit_tests/test_batch.py @@ -35,7 +35,7 @@ def test_ctor(self): batch = self._make_one(client) self.assertEqual(batch.project, _PROJECT) - self.assertEqual(batch.connection, connection) + self.assertIs(batch._client, client) self.assertEqual(batch.namespace, _NAMESPACE) self.assertIsNone(batch._id) self.assertEqual(batch._status, batch._INITIAL) @@ -439,7 +439,7 @@ class _Client(object): def __init__(self, project, connection, namespace=None): self.project = project - self.connection = connection + self._connection = connection self.namespace = namespace self._batches = [] diff --git a/datastore/unit_tests/test_client.py b/datastore/unit_tests/test_client.py index 61bb56ff96a0..a817e4066a25 100644 --- a/datastore/unit_tests/test_client.py +++ b/datastore/unit_tests/test_client.py @@ -171,9 +171,9 @@ def fallback_mock(project): client = klass() self.assertEqual(client.project, OTHER) self.assertIsNone(client.namespace) - self.assertIsInstance(client.connection, _MockConnection) - self.assertIs(client.connection.credentials, creds) - self.assertIsNone(client.connection.http) + self.assertIsInstance(client._connection, _MockConnection) + self.assertIs(client._connection.credentials, creds) + self.assertIsNone(client._connection.http) self.assertIsNone(client.current_batch) self.assertIsNone(client.current_transaction) self.assertEqual(default_called, [None]) @@ -189,9 +189,9 @@ def test_ctor_w_explicit_inputs(self): http=http) self.assertEqual(client.project, OTHER) self.assertEqual(client.namespace, NAMESPACE) - self.assertIsInstance(client.connection, _MockConnection) - self.assertIs(client.connection.credentials, creds) - self.assertIs(client.connection.http, http) + self.assertIsInstance(client._connection, _MockConnection) + self.assertIs(client._connection.credentials, creds) + self.assertIs(client._connection.http, http) self.assertIsNone(client.current_batch) self.assertEqual(list(client._batch_stack), []) @@ -269,7 +269,7 @@ def test_get_multi_miss(self): creds = object() client = self._make_one(credentials=creds) - client.connection._add_lookup_result() + client._connection._add_lookup_result() key = Key('Kind', 1234, project=self.PROJECT) results = client.get_multi([key]) self.assertEqual(results, []) @@ -291,7 +291,7 @@ def test_get_multi_miss_w_missing(self): creds = object() client = self._make_one(credentials=creds) # Set missing entity on mock connection. - client.connection._add_lookup_result(missing=[missed]) + client._connection._add_lookup_result(missing=[missed]) key = Key(KIND, ID, project=self.PROJECT) missing = [] @@ -330,7 +330,7 @@ def test_get_multi_miss_w_deferred(self): # Set deferred entity on mock connection. creds = object() client = self._make_one(credentials=creds) - client.connection._add_lookup_result(deferred=[key.to_protobuf()]) + client._connection._add_lookup_result(deferred=[key.to_protobuf()]) deferred = [] entities = client.get_multi([key], deferred=deferred) @@ -356,8 +356,8 @@ def test_get_multi_w_deferred_from_backend_but_not_passed(self): creds = object() client = self._make_one(credentials=creds) # mock up two separate requests - client.connection._add_lookup_result([entity1_pb], deferred=[key2_pb]) - client.connection._add_lookup_result([entity2_pb]) + client._connection._add_lookup_result([entity1_pb], deferred=[key2_pb]) + client._connection._add_lookup_result([entity2_pb]) missing = [] found = client.get_multi([key1, key2], missing=missing) @@ -373,7 +373,7 @@ def test_get_multi_w_deferred_from_backend_but_not_passed(self): self.assertEqual(found[1].key.path, key2.path) self.assertEqual(found[1].key.project, key2.project) - cw = client.connection._lookup_cw + cw = client._connection._lookup_cw self.assertEqual(len(cw), 2) ds_id, k_pbs, eventual, tid = cw[0] @@ -404,7 +404,7 @@ def test_get_multi_hit(self): # Make a connection to return the entity pb. creds = object() client = self._make_one(credentials=creds) - client.connection._add_lookup_result([entity_pb]) + client._connection._add_lookup_result([entity_pb]) key = Key(KIND, ID, project=self.PROJECT) result, = client.get_multi([key]) @@ -431,7 +431,7 @@ def test_get_multi_hit_w_transaction(self): # Make a connection to return the entity pb. creds = object() client = self._make_one(credentials=creds) - client.connection._add_lookup_result([entity_pb]) + client._connection._add_lookup_result([entity_pb]) key = Key(KIND, ID, project=self.PROJECT) txn = client.transaction() @@ -446,7 +446,7 @@ def test_get_multi_hit_w_transaction(self): self.assertEqual(list(result), ['foo']) self.assertEqual(result['foo'], 'Foo') - cw = client.connection._lookup_cw + cw = client._connection._lookup_cw self.assertEqual(len(cw), 1) _, _, _, transaction_id = cw[0] self.assertEqual(transaction_id, TXN_ID) @@ -465,7 +465,7 @@ def test_get_multi_hit_multiple_keys_same_project(self): # Make a connection to return the entity pbs. creds = object() client = self._make_one(credentials=creds) - client.connection._add_lookup_result([entity_pb1, entity_pb2]) + client._connection._add_lookup_result([entity_pb1, entity_pb2]) key1 = Key(KIND, ID1, project=self.PROJECT) key2 = Key(KIND, ID2, project=self.PROJECT) @@ -508,7 +508,7 @@ def test_get_multi_max_loops(self): # Make a connection to return the entity pb. creds = object() client = self._make_one(credentials=creds) - client.connection._add_lookup_result([entity_pb]) + client._connection._add_lookup_result([entity_pb]) key = Key(KIND, ID, project=self.PROJECT) deferred = [] @@ -564,14 +564,14 @@ def test_put_multi_no_batch_w_partial_key(self): creds = object() client = self._make_one(credentials=creds) - client.connection._commit.append([_KeyPB(key)]) + client._connection._commit.append([_KeyPB(key)]) result = client.put_multi([entity]) self.assertIsNone(result) - self.assertEqual(len(client.connection._commit_cw), 1) + self.assertEqual(len(client._connection._commit_cw), 1) (project, - commit_req, transaction_id) = client.connection._commit_cw[0] + commit_req, transaction_id) = client._connection._commit_cw[0] self.assertEqual(project, self.PROJECT) mutated_entity = _mutated_pb(self, commit_req.mutations, 'insert') @@ -627,20 +627,20 @@ def test_delete_multi_no_keys(self): client = self._make_one(credentials=creds) result = client.delete_multi([]) self.assertIsNone(result) - self.assertEqual(len(client.connection._commit_cw), 0) + self.assertEqual(len(client._connection._commit_cw), 0) def test_delete_multi_no_batch(self): key = _Key(self.PROJECT) creds = object() client = self._make_one(credentials=creds) - client.connection._commit.append([]) + client._connection._commit.append([]) result = client.delete_multi([key]) self.assertIsNone(result) - self.assertEqual(len(client.connection._commit_cw), 1) + self.assertEqual(len(client._connection._commit_cw), 1) (project, - commit_req, transaction_id) = client.connection._commit_cw[0] + commit_req, transaction_id) = client._connection._commit_cw[0] self.assertEqual(project, self.PROJECT) mutated_key = _mutated_pb(self, commit_req.mutations, 'delete') @@ -658,7 +658,7 @@ def test_delete_multi_w_existing_batch(self): self.assertIsNone(result) mutated_key = _mutated_pb(self, CURR_BATCH.mutations, 'delete') self.assertEqual(mutated_key, key._key) - self.assertEqual(len(client.connection._commit_cw), 0) + self.assertEqual(len(client._connection._commit_cw), 0) def test_delete_multi_w_existing_transaction(self): creds = object() @@ -671,7 +671,7 @@ def test_delete_multi_w_existing_transaction(self): self.assertIsNone(result) mutated_key = _mutated_pb(self, CURR_XACT.mutations, 'delete') self.assertEqual(mutated_key, key._key) - self.assertEqual(len(client.connection._commit_cw), 0) + self.assertEqual(len(client._connection._commit_cw), 0) def test_allocate_ids_w_partial_key(self): NUM_IDS = 2 diff --git a/datastore/unit_tests/test_query.py b/datastore/unit_tests/test_query.py index 728dbc3dc63d..0e431623e369 100644 --- a/datastore/unit_tests/test_query.py +++ b/datastore/unit_tests/test_query.py @@ -679,7 +679,7 @@ class _Client(object): def __init__(self, project, connection, namespace=None): self.project = project - self.connection = connection + self._connection = connection self.namespace = namespace @property diff --git a/datastore/unit_tests/test_transaction.py b/datastore/unit_tests/test_transaction.py index 46fbf21320e5..c09304df6f5b 100644 --- a/datastore/unit_tests/test_transaction.py +++ b/datastore/unit_tests/test_transaction.py @@ -33,7 +33,7 @@ def test_ctor_defaults(self): client = _Client(_PROJECT, connection) xact = self._make_one(client) self.assertEqual(xact.project, _PROJECT) - self.assertEqual(xact.connection, connection) + self.assertIs(xact._client, client) self.assertIsNone(xact.id) self.assertEqual(xact._status, self._get_target_class()._INITIAL) self.assertIsInstance(xact._commit_request, @@ -227,7 +227,7 @@ class _Client(object): def __init__(self, project, connection, namespace=None): self.project = project - self.connection = connection + self._connection = connection self.namespace = namespace self._batches = [] diff --git a/dns/google/cloud/dns/changes.py b/dns/google/cloud/dns/changes.py index 7dad3de23e8c..62895f07928a 100644 --- a/dns/google/cloud/dns/changes.py +++ b/dns/google/cloud/dns/changes.py @@ -218,7 +218,7 @@ def create(self, client=None): client = self._require_client(client) path = '/projects/%s/managedZones/%s/changes' % ( self.zone.project, self.zone.name) - api_response = client.connection.api_request( + api_response = client._connection.api_request( method='POST', path=path, data=self._build_resource()) self._set_properties(api_response) @@ -238,8 +238,8 @@ def exists(self, client=None): """ client = self._require_client(client) try: - client.connection.api_request(method='GET', path=self.path, - query_params={'fields': 'id'}) + client._connection.api_request(method='GET', path=self.path, + query_params={'fields': 'id'}) except NotFound: return False else: @@ -258,6 +258,6 @@ def reload(self, client=None): """ client = self._require_client(client) - api_response = client.connection.api_request( + api_response = client._connection.api_request( method='GET', path=self.path) self._set_properties(api_response) diff --git a/dns/google/cloud/dns/client.py b/dns/google/cloud/dns/client.py index aa285562fca7..0cd2577bc775 100644 --- a/dns/google/cloud/dns/client.py +++ b/dns/google/cloud/dns/client.py @@ -55,7 +55,7 @@ def quotas(self): sub-mapping of the project resource. """ path = '/projects/%s' % (self.project,) - resp = self.connection.api_request(method='GET', path=path) + resp = self._connection.api_request(method='GET', path=path) return {key: int(value) for key, value in resp['quota'].items() diff --git a/dns/google/cloud/dns/connection.py b/dns/google/cloud/dns/connection.py index 79377d8d4788..1b2283f3403b 100644 --- a/dns/google/cloud/dns/connection.py +++ b/dns/google/cloud/dns/connection.py @@ -14,10 +14,10 @@ """Create / interact with Google Cloud DNS connections.""" -from google.cloud import connection as base_connection +from google.cloud import _http -class Connection(base_connection.JSONConnection): +class Connection(_http.JSONConnection): """A connection to Google Cloud DNS via the JSON REST API.""" API_BASE_URL = 'https://www.googleapis.com' diff --git a/dns/google/cloud/dns/zone.py b/dns/google/cloud/dns/zone.py index b7b5c594c320..3eecf079bccf 100644 --- a/dns/google/cloud/dns/zone.py +++ b/dns/google/cloud/dns/zone.py @@ -260,7 +260,7 @@ def create(self, client=None): """ client = self._require_client(client) path = '/projects/%s/managedZones' % (self.project,) - api_response = client.connection.api_request( + api_response = client._connection.api_request( method='POST', path=path, data=self._build_resource()) self._set_properties(api_response) @@ -281,8 +281,8 @@ def exists(self, client=None): client = self._require_client(client) try: - client.connection.api_request(method='GET', path=self.path, - query_params={'fields': 'id'}) + client._connection.api_request(method='GET', path=self.path, + query_params={'fields': 'id'}) except NotFound: return False else: @@ -301,7 +301,7 @@ def reload(self, client=None): """ client = self._require_client(client) - api_response = client.connection.api_request( + api_response = client._connection.api_request( method='GET', path=self.path) self._set_properties(api_response) @@ -317,7 +317,7 @@ def delete(self, client=None): ``client`` stored on the current zone. """ client = self._require_client(client) - client.connection.api_request(method='DELETE', path=self.path) + client._connection.api_request(method='DELETE', path=self.path) def list_resource_record_sets(self, max_results=None, page_token=None, client=None): diff --git a/dns/unit_tests/test_changes.py b/dns/unit_tests/test_changes.py index 40a6f30b5d4e..1543bbfb1921 100644 --- a/dns/unit_tests/test_changes.py +++ b/dns/unit_tests/test_changes.py @@ -323,7 +323,7 @@ class _Client(object): def __init__(self, project='project', connection=None): self.project = project - self.connection = connection + self._connection = connection class _Connection(object): diff --git a/dns/unit_tests/test_client.py b/dns/unit_tests/test_client.py index 0f849ed9dbb4..40eecc512921 100644 --- a/dns/unit_tests/test_client.py +++ b/dns/unit_tests/test_client.py @@ -34,9 +34,9 @@ def test_ctor(self): http = object() client = self._make_one(project=self.PROJECT, credentials=creds, http=http) - self.assertIsInstance(client.connection, Connection) - self.assertIs(client.connection.credentials, creds) - self.assertIs(client.connection.http, http) + self.assertIsInstance(client._connection, Connection) + self.assertIs(client._connection.credentials, creds) + self.assertIs(client._connection.http, http) def test_quotas_defaults(self): PATH = 'projects/%s' % (self.PROJECT,) @@ -60,7 +60,7 @@ def test_quotas_defaults(self): for key, value in DATA['quota'].items()} creds = _Credentials() client = self._make_one(self.PROJECT, creds) - conn = client.connection = _Connection(DATA) + conn = client._connection = _Connection(DATA) quotas = client.quotas() @@ -95,7 +95,7 @@ def test_quotas_w_kind_key(self): WITH_KIND['quota']['kind'] = 'dns#quota' creds = _Credentials() client = self._make_one(self.PROJECT, creds) - conn = client.connection = _Connection(WITH_KIND) + conn = client._connection = _Connection(WITH_KIND) quotas = client.quotas() @@ -132,7 +132,7 @@ def test_list_zones_defaults(self): } creds = _Credentials() client = self._make_one(self.PROJECT, creds) - conn = client.connection = _Connection(DATA) + conn = client._connection = _Connection(DATA) iterator = client.list_zones() page = six.next(iterator.pages) @@ -177,7 +177,7 @@ def test_list_zones_explicit(self): } creds = _Credentials() client = self._make_one(self.PROJECT, creds) - conn = client.connection = _Connection(DATA) + conn = client._connection = _Connection(DATA) iterator = client.list_zones(max_results=3, page_token=TOKEN) page = six.next(iterator.pages) diff --git a/dns/unit_tests/test_zone.py b/dns/unit_tests/test_zone.py index 681da61d2420..c02c231f7b9d 100644 --- a/dns/unit_tests/test_zone.py +++ b/dns/unit_tests/test_zone.py @@ -673,7 +673,7 @@ class _Client(object): def __init__(self, project='project', connection=None): self.project = project - self.connection = connection + self._connection = connection class _Connection(object): diff --git a/docs/google-cloud-api.rst b/docs/google-cloud-api.rst index 0fb79d966cfb..bb2fd2842e9f 100644 --- a/docs/google-cloud-api.rst +++ b/docs/google-cloud-api.rst @@ -16,13 +16,6 @@ Credentials Helpers :members: :show-inheritance: -Base Connections -~~~~~~~~~~~~~~~~ - -.. automodule:: google.cloud.connection - :members: - :show-inheritance: - Exceptions ~~~~~~~~~~ diff --git a/language/google/cloud/language/connection.py b/language/google/cloud/language/connection.py index 4b2a7de9a6c2..a1e0269becf5 100644 --- a/language/google/cloud/language/connection.py +++ b/language/google/cloud/language/connection.py @@ -14,10 +14,10 @@ """Basic connection for Google Cloud Natural Language API.""" -from google.cloud import connection as base_connection +from google.cloud import _http -class Connection(base_connection.JSONConnection): +class Connection(_http.JSONConnection): """A connection to Google Cloud Natural Language JSON REST API.""" API_BASE_URL = 'https://language.googleapis.com' diff --git a/language/google/cloud/language/document.py b/language/google/cloud/language/document.py index 0691da25833c..3eec41d552d2 100644 --- a/language/google/cloud/language/document.py +++ b/language/google/cloud/language/document.py @@ -167,7 +167,7 @@ def analyze_entities(self): 'document': self._to_dict(), 'encodingType': self.encoding, } - api_response = self.client.connection.api_request( + api_response = self.client._connection.api_request( method='POST', path='analyzeEntities', data=data) return [Entity.from_api_repr(entity) for entity in api_response['entities']] @@ -184,7 +184,7 @@ def analyze_sentiment(self): :returns: The sentiment of the current document. """ data = {'document': self._to_dict()} - api_response = self.client.connection.api_request( + api_response = self.client._connection.api_request( method='POST', path='analyzeSentiment', data=data) return Sentiment.from_api_repr(api_response['documentSentiment']) @@ -238,7 +238,7 @@ def annotate_text(self, include_syntax=True, include_entities=True, 'features': features, 'encodingType': self.encoding, } - api_response = self.client.connection.api_request( + api_response = self.client._connection.api_request( method='POST', path='annotateText', data=data) sentences = [Sentence.from_api_repr(sentence) diff --git a/language/unit_tests/test_client.py b/language/unit_tests/test_client.py index 95c77ad32fd5..0ebee751a24d 100644 --- a/language/unit_tests/test_client.py +++ b/language/unit_tests/test_client.py @@ -31,9 +31,9 @@ def test_ctor(self): creds = _Credentials() http = object() client = self._make_one(credentials=creds, http=http) - self.assertIsInstance(client.connection, Connection) - self.assertIs(client.connection.credentials, creds) - self.assertIs(client.connection.http, http) + self.assertIsInstance(client._connection, Connection) + self.assertIs(client._connection.credentials, creds) + self.assertIs(client._connection.http, http) def test_document_from_text_factory(self): from google.cloud.language.document import Document diff --git a/language/unit_tests/test_document.py b/language/unit_tests/test_document.py index db43af5e81ca..5d2bfe5c1da4 100644 --- a/language/unit_tests/test_document.py +++ b/language/unit_tests/test_document.py @@ -390,4 +390,4 @@ def api_request(self, **kwargs): class _Client(object): def __init__(self, connection=None): - self.connection = connection + self._connection = connection diff --git a/logging/google/cloud/logging/_gax.py b/logging/google/cloud/logging/_gax.py index 1df2be5daf70..259b8e20e55a 100644 --- a/logging/google/cloud/logging/_gax.py +++ b/logging/google/cloud/logging/_gax.py @@ -35,7 +35,7 @@ from google.cloud._helpers import _datetime_to_rfc3339 from google.cloud._helpers import make_secure_channel -from google.cloud.connection import DEFAULT_USER_AGENT +from google.cloud._http import DEFAULT_USER_AGENT from google.cloud.exceptions import Conflict from google.cloud.exceptions import NotFound from google.cloud.iterator import GAXIterator @@ -531,7 +531,7 @@ def make_gax_logging_api(client): :returns: A metrics API instance with the proper credentials. """ channel = make_secure_channel( - client.connection.credentials, DEFAULT_USER_AGENT, + client._connection.credentials, DEFAULT_USER_AGENT, LoggingServiceV2Api.SERVICE_ADDRESS) generated = LoggingServiceV2Api(channel=channel) return _LoggingAPI(generated, client) @@ -547,7 +547,7 @@ def make_gax_metrics_api(client): :returns: A metrics API instance with the proper credentials. """ channel = make_secure_channel( - client.connection.credentials, DEFAULT_USER_AGENT, + client._connection.credentials, DEFAULT_USER_AGENT, MetricsServiceV2Api.SERVICE_ADDRESS) generated = MetricsServiceV2Api(channel=channel) return _MetricsAPI(generated, client) @@ -563,7 +563,7 @@ def make_gax_sinks_api(client): :returns: A metrics API instance with the proper credentials. """ channel = make_secure_channel( - client.connection.credentials, DEFAULT_USER_AGENT, + client._connection.credentials, DEFAULT_USER_AGENT, ConfigServiceV2Api.SERVICE_ADDRESS) generated = ConfigServiceV2Api(channel=channel) return _SinksAPI(generated, client) diff --git a/logging/google/cloud/logging/_http.py b/logging/google/cloud/logging/_http.py index a1fa388b0f09..8d9eccc819d5 100644 --- a/logging/google/cloud/logging/_http.py +++ b/logging/google/cloud/logging/_http.py @@ -16,14 +16,14 @@ import functools -from google.cloud import connection as base_connection +from google.cloud import _http from google.cloud.iterator import HTTPIterator from google.cloud.logging._helpers import entry_from_resource from google.cloud.logging.sink import Sink from google.cloud.logging.metric import Metric -class Connection(base_connection.JSONConnection): +class Connection(_http.JSONConnection): """A connection to Google Stackdriver Logging via the JSON REST API. :type credentials: :class:`oauth2client.client.OAuth2Credentials` @@ -67,7 +67,7 @@ class _LoggingAPI(object): def __init__(self, client): self._client = client - self._connection = client.connection + self._connection = client._connection def list_entries(self, projects, filter_=None, order_by=None, page_size=None, page_token=None): @@ -191,7 +191,7 @@ class _SinksAPI(object): """ def __init__(self, client): self._client = client - self._connection = client.connection + self._connection = client._connection def list_sinks(self, project, page_size=None, page_token=None): """List sinks for the project associated with this client. @@ -328,7 +328,7 @@ class _MetricsAPI(object): """ def __init__(self, client): self._client = client - self._connection = client.connection + self._connection = client._connection def list_metrics(self, project, page_size=None, page_token=None): """List metrics for the project associated with this client. diff --git a/logging/google/cloud/logging/handlers/transports/background_thread.py b/logging/google/cloud/logging/handlers/transports/background_thread.py index 3c1e76872985..144bccafc838 100644 --- a/logging/google/cloud/logging/handlers/transports/background_thread.py +++ b/logging/google/cloud/logging/handlers/transports/background_thread.py @@ -150,10 +150,10 @@ class BackgroundThreadTransport(Transport): """ def __init__(self, client, name): - http = copy.deepcopy(client.connection.http) - http = client.connection.credentials.authorize(http) + http = copy.deepcopy(client._connection.http) + http = client._connection.credentials.authorize(http) self.client = Client(client.project, - client.connection.credentials, + client._connection.credentials, http) logger = self.client.logger(name) self.worker = _Worker(logger) diff --git a/logging/unit_tests/handlers/transports/test_background_thread.py b/logging/unit_tests/handlers/transports/test_background_thread.py index a7ef4fc43190..3695c591288c 100644 --- a/logging/unit_tests/handlers/transports/test_background_thread.py +++ b/logging/unit_tests/handlers/transports/test_background_thread.py @@ -188,7 +188,7 @@ class _Client(object): def __init__(self, project): self.project = project - self.connection = _Connection() + self._connection = _Connection() def logger(self, name): # pylint: disable=unused-argument self._logger = _Logger(name) diff --git a/logging/unit_tests/test__gax.py b/logging/unit_tests/test__gax.py index 7497a07efc7d..79d0568f899f 100644 --- a/logging/unit_tests/test__gax.py +++ b/logging/unit_tests/test__gax.py @@ -1312,4 +1312,4 @@ def __init__(self, credentials): class _Client(object): def __init__(self, credentials): - self.connection = _Connection(credentials) + self._connection = _Connection(credentials) diff --git a/logging/unit_tests/test__http.py b/logging/unit_tests/test__http.py index 1a6d5cd5d9f3..1a6e2d548a06 100644 --- a/logging/unit_tests/test__http.py +++ b/logging/unit_tests/test__http.py @@ -94,7 +94,7 @@ def test_list_entries_no_paging(self): } client = Client(project=self.PROJECT, credentials=object(), use_gax=False) - client.connection = _Connection(RETURNED) + client._connection = _Connection(RETURNED) api = self._make_one(client) iterator = api.list_entries([self.PROJECT]) @@ -117,7 +117,7 @@ def test_list_entries_no_paging(self): self.assertIsNone(entry.severity) self.assertIsNone(entry.http_request) - called_with = client.connection._called_with + called_with = client._connection._called_with expected_path = '/%s' % (self.LIST_ENTRIES_PATH,) self.assertEqual(called_with, { 'method': 'POST', @@ -172,7 +172,7 @@ def test_list_entries_w_paging(self): } client = Client(project=self.PROJECT, credentials=object(), use_gax=False) - client.connection = _Connection(RETURNED) + client._connection = _Connection(RETURNED) api = self._make_one(client) iterator = api.list_entries( @@ -207,7 +207,7 @@ def test_list_entries_w_paging(self): self.assertIsNone(entry2.severity) self.assertIsNone(entry2.http_request) - called_with = client.connection._called_with + called_with = client._connection._called_with expected_path = '/%s' % (self.LIST_ENTRIES_PATH,) self.assertEqual(called_with, { 'method': 'POST', @@ -802,4 +802,4 @@ def _datetime_to_rfc3339_w_nanos(value): class _Client(object): def __init__(self, connection): - self.connection = connection + self._connection = connection diff --git a/logging/unit_tests/test_client.py b/logging/unit_tests/test_client.py index ea6bd89fb961..2cc1cf4ff328 100644 --- a/logging/unit_tests/test_client.py +++ b/logging/unit_tests/test_client.py @@ -44,7 +44,7 @@ def test_logging_api_wo_gax(self): client = self._make_one(self.PROJECT, credentials=_Credentials(), use_gax=False) - conn = client.connection = object() + conn = client._connection = object() api = client.logging_api self.assertIsInstance(api, _LoggingAPI) @@ -98,7 +98,7 @@ def test_sinks_api_wo_gax(self): with _Monkey(MUT, _USE_GAX=False): client = self._make_one(self.PROJECT, credentials=_Credentials()) - conn = client.connection = object() + conn = client._connection = object() api = client.sinks_api self.assertIsInstance(api, _SinksAPI) @@ -139,7 +139,7 @@ def test_metrics_api_wo_gax(self): with _Monkey(MUT, _USE_GAX=False): client = self._make_one(self.PROJECT, credentials=_Credentials()) - conn = client.connection = object() + conn = client._connection = object() api = client.metrics_api self.assertIsInstance(api, _MetricsAPI) @@ -205,7 +205,7 @@ def test_list_entries_defaults(self): 'entries': ENTRIES, 'nextPageToken': TOKEN, } - client.connection = _Connection(returned) + client._connection = _Connection(returned) iterator = client.list_entries() page = six.next(iterator.pages) @@ -223,7 +223,7 @@ def test_list_entries_defaults(self): self.assertEqual(logger.project, self.PROJECT) self.assertEqual(token, TOKEN) - called_with = client.connection._called_with + called_with = client._connection._called_with self.assertEqual(called_with, { 'path': '/entries:list', 'method': 'POST', @@ -266,7 +266,7 @@ def test_list_entries_explicit(self): client = self._make_one(self.PROJECT, credentials=_Credentials(), use_gax=False) returned = {'entries': ENTRIES} - client.connection = _Connection(returned) + client._connection = _Connection(returned) iterator = client.list_entries( projects=[PROJECT1, PROJECT2], filter_=FILTER, order_by=DESCENDING, @@ -299,7 +299,7 @@ def test_list_entries_explicit(self): self.assertIs(entries[0].logger, entries[1].logger) - called_with = client.connection._called_with + called_with = client._connection._called_with self.assertEqual(called_with, { 'path': '/entries:list', 'method': 'POST', @@ -355,7 +355,7 @@ def test_list_sinks_no_paging(self): 'sinks': SINKS, 'nextPageToken': TOKEN, } - client.connection = _Connection(returned) + client._connection = _Connection(returned) iterator = client.list_sinks() page = six.next(iterator.pages) @@ -374,7 +374,7 @@ def test_list_sinks_no_paging(self): self.assertIs(sink.client, client) # Verify the mocked transport. - called_with = client.connection._called_with + called_with = client._connection._called_with path = '/projects/%s/sinks' % (self.PROJECT,) self.assertEqual(called_with, { 'method': 'GET', @@ -400,7 +400,7 @@ def test_list_sinks_with_paging(self): returned = { 'sinks': SINKS, } - client.connection = _Connection(returned) + client._connection = _Connection(returned) iterator = client.list_sinks(PAGE_SIZE, TOKEN) sinks = list(iterator) @@ -418,7 +418,7 @@ def test_list_sinks_with_paging(self): self.assertIs(sink.client, client) # Verify the mocked transport. - called_with = client.connection._called_with + called_with = client._connection._called_with path = '/projects/%s/sinks' % (self.PROJECT,) self.assertEqual(called_with, { 'method': 'GET', @@ -470,7 +470,7 @@ def test_list_metrics_no_paging(self): returned = { 'metrics': metrics, } - client.connection = _Connection(returned) + client._connection = _Connection(returned) # Execute request. iterator = client.list_metrics() @@ -486,7 +486,7 @@ def test_list_metrics_no_paging(self): self.assertIs(metric.client, client) # Verify mocked transport. - called_with = client.connection._called_with + called_with = client._connection._called_with path = '/projects/%s/metrics' % (self.PROJECT,) self.assertEqual(called_with, { 'method': 'GET', @@ -513,7 +513,7 @@ def test_list_metrics_with_paging(self): 'metrics': metrics, 'nextPageToken': next_token, } - client.connection = _Connection(returned) + client._connection = _Connection(returned) # Execute request. iterator = client.list_metrics(page_size, token) @@ -532,7 +532,7 @@ def test_list_metrics_with_paging(self): self.assertIs(metric.client, client) # Verify mocked transport. - called_with = client.connection._called_with + called_with = client._connection._called_with path = '/projects/%s/metrics' % (self.PROJECT,) self.assertEqual(called_with, { 'method': 'GET', diff --git a/logging/unit_tests/test_logger.py b/logging/unit_tests/test_logger.py index c2770f83d9f3..cbe149102445 100644 --- a/logging/unit_tests/test_logger.py +++ b/logging/unit_tests/test_logger.py @@ -357,7 +357,7 @@ def test_list_entries_defaults(self): returned = { 'nextPageToken': TOKEN, } - client.connection = _Connection(returned) + client._connection = _Connection(returned) logger = self._make_one(self.LOGGER_NAME, client=client) @@ -368,7 +368,7 @@ def test_list_entries_defaults(self): self.assertEqual(len(entries), 0) self.assertEqual(token, TOKEN) - called_with = client.connection._called_with + called_with = client._connection._called_with FILTER = 'logName=projects/%s/logs/%s' % ( self.PROJECT, self.LOGGER_NAME) self.assertEqual(called_with, { @@ -391,7 +391,7 @@ def test_list_entries_explicit(self): PAGE_SIZE = 42 client = Client(project=self.PROJECT, credentials=object(), use_gax=False) - client.connection = _Connection({}) + client._connection = _Connection({}) logger = self._make_one(self.LOGGER_NAME, client=client) iterator = logger.list_entries( projects=[PROJECT1, PROJECT2], filter_=FILTER, order_by=DESCENDING, @@ -402,7 +402,7 @@ def test_list_entries_explicit(self): self.assertEqual(len(entries), 0) self.assertIsNone(token) # self.assertEqual(client._listed, LISTED) - called_with = client.connection._called_with + called_with = client._connection._called_with combined_filter = '%s AND logName=projects/%s/logs/%s' % ( FILTER, self.PROJECT, self.LOGGER_NAME) self.assertEqual(called_with, { @@ -721,7 +721,7 @@ class _Client(object): def __init__(self, project, connection=None): self.project = project - self.connection = connection + self._connection = connection class _Bugout(Exception): diff --git a/monitoring/google/cloud/monitoring/client.py b/monitoring/google/cloud/monitoring/client.py index 6a865b293e9d..de686127c737 100644 --- a/monitoring/google/cloud/monitoring/client.py +++ b/monitoring/google/cloud/monitoring/client.py @@ -529,8 +529,8 @@ def write_time_series(self, timeseries_list): project=self.project) timeseries_dict = [timeseries._to_dict() for timeseries in timeseries_list] - self.connection.api_request(method='POST', path=path, - data={'timeSeries': timeseries_dict}) + self._connection.api_request(method='POST', path=path, + data={'timeSeries': timeseries_dict}) def write_point(self, metric, resource, value, end_time=None, diff --git a/monitoring/google/cloud/monitoring/connection.py b/monitoring/google/cloud/monitoring/connection.py index 8b7200391161..671f00b4e96c 100644 --- a/monitoring/google/cloud/monitoring/connection.py +++ b/monitoring/google/cloud/monitoring/connection.py @@ -14,10 +14,10 @@ """Create / interact with Stackdriver Monitoring connections.""" -from google.cloud import connection as base_connection +from google.cloud import _http -class Connection(base_connection.JSONConnection): +class Connection(_http.JSONConnection): """A connection to Google Stackdriver Monitoring via the JSON REST API. :type credentials: :class:`oauth2client.client.OAuth2Credentials` diff --git a/monitoring/google/cloud/monitoring/group.py b/monitoring/google/cloud/monitoring/group.py index d1e24c68ad2a..04a029e2f73e 100644 --- a/monitoring/google/cloud/monitoring/group.py +++ b/monitoring/google/cloud/monitoring/group.py @@ -175,7 +175,7 @@ def create(self): (normally affecting only ``name``). """ path = '/projects/%s/groups/' % (self.client.project,) - info = self.client.connection.api_request( + info = self.client._connection.api_request( method='POST', path=path, data=self._to_dict()) self._set_properties_from_dict(info) @@ -186,7 +186,7 @@ def exists(self): :returns: Boolean indicating existence of the group. """ try: - self.client.connection.api_request( + self.client._connection.api_request( method='GET', path=self.path, query_params={'fields': 'name'}) except NotFound: return False @@ -201,12 +201,13 @@ def reload(self): This will overwrite any local changes you've made and not saved via :meth:`update`. """ - info = self.client.connection.api_request(method='GET', path=self.path) + info = self.client._connection.api_request( + method='GET', path=self.path) self._set_properties_from_dict(info) def update(self): """Update the group via a ``PUT`` request.""" - info = self.client.connection.api_request( + info = self.client._connection.api_request( method='PUT', path=self.path, data=self._to_dict()) self._set_properties_from_dict(info) @@ -225,7 +226,8 @@ def delete(self): This method will fail for groups that have one or more children groups. """ - self.client.connection.api_request(method='DELETE', path=self.path) + self.client._connection.api_request( + method='DELETE', path=self.path) def fetch_parent(self): """Returns the parent group of this group via a ``GET`` request. @@ -349,7 +351,7 @@ def list_members(self, filter_string=None, end_time=None, start_time=None): if page_token is not None: params['pageToken'] = page_token - response = self.client.connection.api_request( + response = self.client._connection.api_request( method='GET', path=path, query_params=params.copy()) for info in response.get('members', ()): resources.append(Resource._from_dict(info)) @@ -426,7 +428,7 @@ def _list(cls, client, children_of_group=None, ancestors_of_group=None, if page_token is not None: params['pageToken'] = page_token - response = client.connection.api_request( + response = client._connection.api_request( method='GET', path=path, query_params=params.copy()) for info in response.get('group', ()): groups.append(cls._from_dict(client, info)) diff --git a/monitoring/google/cloud/monitoring/metric.py b/monitoring/google/cloud/monitoring/metric.py index 7fc4fdde6494..223843aa92d9 100644 --- a/monitoring/google/cloud/monitoring/metric.py +++ b/monitoring/google/cloud/monitoring/metric.py @@ -149,8 +149,8 @@ def create(self): """ path = '/projects/{project}/metricDescriptors/'.format( project=self.client.project) - response = self.client.connection.api_request(method='POST', path=path, - data=self._to_dict()) + response = self.client._connection.api_request( + method='POST', path=path, data=self._to_dict()) self._init_from_dict(response) def delete(self): @@ -167,7 +167,7 @@ def delete(self): path = '/projects/{project}/metricDescriptors/{type}'.format( project=self.client.project, type=self.type) - self.client.connection.api_request(method='DELETE', path=path) + self.client._connection.api_request(method='DELETE', path=path) @classmethod def _fetch(cls, client, metric_type): @@ -188,7 +188,7 @@ def _fetch(cls, client, metric_type): path = '/projects/{project}/metricDescriptors/{type}'.format( project=client.project, type=metric_type) - info = client.connection.api_request(method='GET', path=path) + info = client._connection.api_request(method='GET', path=path) return cls._from_dict(client, info) @classmethod @@ -236,7 +236,7 @@ def _list(cls, client, filter_string=None, type_prefix=None): if page_token is not None: params['pageToken'] = page_token - response = client.connection.api_request( + response = client._connection.api_request( method='GET', path=path, query_params=params) for info in response.get('metricDescriptors', ()): descriptors.append(cls._from_dict(client, info)) diff --git a/monitoring/google/cloud/monitoring/query.py b/monitoring/google/cloud/monitoring/query.py index 964c862ec810..1653383b5000 100644 --- a/monitoring/google/cloud/monitoring/query.py +++ b/monitoring/google/cloud/monitoring/query.py @@ -487,7 +487,7 @@ def _iter_fragments(self, headers_only=False, page_size=None): page_size=page_size, page_token=page_token, )) - response = self._client.connection.api_request( + response = self._client._connection.api_request( method='GET', path=path, query_params=params, diff --git a/monitoring/google/cloud/monitoring/resource.py b/monitoring/google/cloud/monitoring/resource.py index 3a1eba70e043..19bfe6632acd 100644 --- a/monitoring/google/cloud/monitoring/resource.py +++ b/monitoring/google/cloud/monitoring/resource.py @@ -78,7 +78,7 @@ def _fetch(cls, client, resource_type): path = ('/projects/{project}/monitoredResourceDescriptors/{type}' .format(project=client.project, type=resource_type)) - info = client.connection.api_request(method='GET', path=path) + info = client._connection.api_request(method='GET', path=path) return cls._from_dict(info) @classmethod @@ -114,7 +114,7 @@ def _list(cls, client, filter_string=None): if page_token is not None: params['pageToken'] = page_token - response = client.connection.api_request( + response = client._connection.api_request( method='GET', path=path, query_params=params) for info in response.get('resourceDescriptors', ()): descriptors.append(cls._from_dict(info)) diff --git a/monitoring/unit_tests/test_client.py b/monitoring/unit_tests/test_client.py index 5911924c3259..d22dea8b6d8c 100644 --- a/monitoring/unit_tests/test_client.py +++ b/monitoring/unit_tests/test_client.py @@ -86,7 +86,7 @@ def P(timestamp, value): RESPONSE = {'timeSeries': [SERIES1, SERIES2]} client = self._make_one(project=PROJECT, credentials=_Credentials()) - connection = client.connection = _Connection(RESPONSE) + connection = client._connection = _Connection(RESPONSE) # A simple query. In practice, it can be very convenient to let the # end time default to the start of the current minute. @@ -139,7 +139,7 @@ def test_metric_descriptor_factory(self): DESCRIPTION = 'This is my metric.' client = self._make_one(project=PROJECT, credentials=_Credentials()) - client.connection = _Connection() # For safety's sake. + client._connection = _Connection() # For safety's sake. descriptor = client.metric_descriptor(TYPE, metric_kind=METRIC_KIND, value_type=VALUE_TYPE, @@ -165,7 +165,7 @@ def test_metric_factory(self): } client = self._make_one(project=PROJECT, credentials=_Credentials()) - client.connection = _Connection() # For safety's sake. + client._connection = _Connection() # For safety's sake. metric = client.metric(TYPE, LABELS) self.assertEqual(metric.type, TYPE) self.assertEqual(metric.labels, LABELS) @@ -178,7 +178,7 @@ def test_resource_factory(self): } client = self._make_one(project=PROJECT, credentials=_Credentials()) - client.connection = _Connection() # For safety's sake. + client._connection = _Connection() # For safety's sake. resource = client.resource(TYPE, LABELS) self.assertEqual(resource.type, TYPE) self.assertEqual(resource.labels, LABELS) @@ -204,7 +204,7 @@ def test_timeseries_factory_gauge(self): TIME1_STR = _datetime_to_rfc3339(TIME1, ignore_zone=False) client = self._make_one(project=PROJECT, credentials=_Credentials()) - client.connection = _Connection() # For safety's sake. + client._connection = _Connection() # For safety's sake. metric = client.metric(METRIC_TYPE, METRIC_LABELS) resource = client.resource(RESOURCE_TYPE, RESOURCE_LABELS) @@ -243,7 +243,7 @@ def test_timeseries_factory_cumulative(self): } client = self._make_one(project=PROJECT, credentials=_Credentials()) - client.connection = _Connection() # For safety's sake. + client._connection = _Connection() # For safety's sake. resource = client.resource(RESOURCE_TYPE, RESOURCE_LABELS) VALUE = 42 @@ -297,7 +297,7 @@ def test_fetch_metric_descriptor(self): # This test is identical to TestMetricDescriptor.test_fetch() # except for the following three lines. client = self._make_one(project=PROJECT, credentials=_Credentials()) - connection = client.connection = _Connection(METRIC_DESCRIPTOR) + connection = client._connection = _Connection(METRIC_DESCRIPTOR) descriptor = client.fetch_metric_descriptor(TYPE) self.assertIs(descriptor.client, client) @@ -341,7 +341,7 @@ def test_list_metric_descriptors(self): # This test is identical to TestMetricDescriptor.test_list() # except for the following three lines. client = self._make_one(project=PROJECT, credentials=_Credentials()) - connection = client.connection = _Connection(RESPONSE) + connection = client._connection = _Connection(RESPONSE) descriptors = client.list_metric_descriptors() self.assertEqual(len(descriptors), 2) @@ -386,7 +386,7 @@ def test_fetch_resource_descriptor(self): # This test is identical to TestResourceDescriptor.test_fetch() # except for the following three lines. client = self._make_one(project=PROJECT, credentials=_Credentials()) - connection = client.connection = _Connection(RESOURCE_DESCRIPTOR) + connection = client._connection = _Connection(RESOURCE_DESCRIPTOR) descriptor = client.fetch_resource_descriptor(TYPE) self.assertEqual(descriptor.name, NAME) @@ -434,7 +434,7 @@ def test_list_resource_descriptors(self): # This test is identical to TestResourceDescriptor.test_list() # except for the following three lines. client = self._make_one(project=PROJECT, credentials=_Credentials()) - connection = client.connection = _Connection(RESPONSE) + connection = client._connection = _Connection(RESPONSE) descriptors = client.list_resource_descriptors() self.assertEqual(len(descriptors), 2) @@ -500,7 +500,7 @@ def test_fetch_group(self): } client = self._make_one(project=PROJECT, credentials=_Credentials()) - connection = client.connection = _Connection(GROUP) + connection = client._connection = _Connection(GROUP) group = client.fetch_group(GROUP_ID) self.assertEqual(group.id, GROUP_ID) @@ -533,7 +533,7 @@ def test_list_groups(self): 'group': [GROUP], } client = self._make_one(project=PROJECT, credentials=_Credentials()) - connection = client.connection = _Connection(RESPONSE) + connection = client._connection = _Connection(RESPONSE) groups = client.list_groups() self.assertEqual(len(groups), 1) @@ -569,7 +569,7 @@ def test_write_time_series(self): 'request_ip': '127.0.0.1' } - connection = client.connection = _Connection({}) + connection = client._connection = _Connection({}) METRIC = client.metric(METRIC_TYPE, METRIC_LABELS) METRIC2 = client.metric(METRIC_TYPE2, METRIC_LABELS2) @@ -607,7 +607,7 @@ def test_write_point(self): 'status': 'successful' } - connection = client.connection = _Connection({}) + connection = client._connection = _Connection({}) METRIC = client.metric(METRIC_TYPE, METRIC_LABELS) RESOURCE = client.resource(RESOURCE_TYPE, RESOURCE_LABELS) diff --git a/monitoring/unit_tests/test_group.py b/monitoring/unit_tests/test_group.py index a7c88b317890..32302e23aa14 100644 --- a/monitoring/unit_tests/test_group.py +++ b/monitoring/unit_tests/test_group.py @@ -545,4 +545,4 @@ class _Client(object): def __init__(self, project, connection=None): self.project = project - self.connection = connection + self._connection = connection diff --git a/monitoring/unit_tests/test_metric.py b/monitoring/unit_tests/test_metric.py index 5d4c512e0276..f5866aa7ad63 100644 --- a/monitoring/unit_tests/test_metric.py +++ b/monitoring/unit_tests/test_metric.py @@ -566,4 +566,4 @@ class _Client(object): def __init__(self, project, connection): self.project = project - self.connection = connection + self._connection = connection diff --git a/monitoring/unit_tests/test_query.py b/monitoring/unit_tests/test_query.py index 6354933bcf2a..4d4b2bea2690 100644 --- a/monitoring/unit_tests/test_query.py +++ b/monitoring/unit_tests/test_query.py @@ -14,6 +14,7 @@ import unittest + PROJECT = 'my-project' METRIC_TYPE = 'compute.googleapis.com/instance/uptime' @@ -646,4 +647,4 @@ class _Client(object): def __init__(self, project, connection): self.project = project - self.connection = connection + self._connection = connection diff --git a/monitoring/unit_tests/test_resource.py b/monitoring/unit_tests/test_resource.py index 9b429dc30f8e..07f0d417e951 100644 --- a/monitoring/unit_tests/test_resource.py +++ b/monitoring/unit_tests/test_resource.py @@ -351,4 +351,4 @@ class _Client(object): def __init__(self, project, connection): self.project = project - self.connection = connection + self._connection = connection diff --git a/pubsub/google/cloud/pubsub/_gax.py b/pubsub/google/cloud/pubsub/_gax.py index 2636dbea2c89..57bf688486aa 100644 --- a/pubsub/google/cloud/pubsub/_gax.py +++ b/pubsub/google/cloud/pubsub/_gax.py @@ -31,7 +31,7 @@ from google.cloud._helpers import _to_bytes from google.cloud._helpers import _pb_timestamp_to_rfc3339 from google.cloud._helpers import make_secure_channel -from google.cloud.connection import DEFAULT_USER_AGENT +from google.cloud._http import DEFAULT_USER_AGENT from google.cloud.exceptions import Conflict from google.cloud.exceptions import NotFound from google.cloud.iterator import GAXIterator diff --git a/pubsub/google/cloud/pubsub/_http.py b/pubsub/google/cloud/pubsub/_http.py index 4946ff37bd12..6aef4edd6437 100644 --- a/pubsub/google/cloud/pubsub/_http.py +++ b/pubsub/google/cloud/pubsub/_http.py @@ -18,7 +18,7 @@ import functools import os -from google.cloud import connection as base_connection +from google.cloud import _http from google.cloud.environment_vars import PUBSUB_EMULATOR from google.cloud.iterator import HTTPIterator from google.cloud.pubsub._helpers import subscription_name_from_path @@ -30,7 +30,7 @@ """Pub / Sub API request host.""" -class Connection(base_connection.JSONConnection): +class Connection(_http.JSONConnection): """A connection to Google Cloud Pub/Sub via the JSON REST API. :type credentials: :class:`oauth2client.client.OAuth2Credentials` @@ -108,7 +108,7 @@ class _PublisherAPI(object): def __init__(self, client): self._client = client - self._connection = client.connection + self._connection = client._connection def list_topics(self, project, page_size=None, page_token=None): """API call: list topics for a given project @@ -255,7 +255,7 @@ class _SubscriberAPI(object): def __init__(self, client): self._client = client - self._connection = client.connection + self._connection = client._connection def list_subscriptions(self, project, page_size=None, page_token=None): """API call: list subscriptions for a given project diff --git a/pubsub/google/cloud/pubsub/client.py b/pubsub/google/cloud/pubsub/client.py index c357a5f8753d..dd323aa25fe5 100644 --- a/pubsub/google/cloud/pubsub/client.py +++ b/pubsub/google/cloud/pubsub/client.py @@ -85,7 +85,7 @@ def publisher_api(self): """Helper for publisher-related API calls.""" if self._publisher_api is None: if self._use_gax: - generated = make_gax_publisher_api(self.connection) + generated = make_gax_publisher_api(self._connection) self._publisher_api = GAXPublisherAPI(generated, self) else: self._publisher_api = JSONPublisherAPI(self) @@ -96,7 +96,7 @@ def subscriber_api(self): """Helper for subscriber-related API calls.""" if self._subscriber_api is None: if self._use_gax: - generated = make_gax_subscriber_api(self.connection) + generated = make_gax_subscriber_api(self._connection) self._subscriber_api = GAXSubscriberAPI(generated, self) else: self._subscriber_api = JSONSubscriberAPI(self) @@ -106,7 +106,7 @@ def subscriber_api(self): def iam_policy_api(self): """Helper for IAM policy-related API calls.""" if self._iam_policy_api is None: - self._iam_policy_api = _IAMPolicyAPI(self.connection) + self._iam_policy_api = _IAMPolicyAPI(self._connection) return self._iam_policy_api def list_topics(self, page_size=None, page_token=None): diff --git a/pubsub/unit_tests/test__http.py b/pubsub/unit_tests/test__http.py index f9f94fff098d..290df47012a1 100644 --- a/pubsub/unit_tests/test__http.py +++ b/pubsub/unit_tests/test__http.py @@ -435,7 +435,7 @@ def test_list_subscriptions_no_paging(self): connection = _Connection(RETURNED) creds = _Credentials() client = Client(project=self.PROJECT, credentials=creds) - client.connection = connection + client._connection = connection api = self._make_one(client) iterator = api.list_subscriptions(self.PROJECT) @@ -478,7 +478,7 @@ def test_list_subscriptions_with_paging(self): connection = _Connection(RETURNED) creds = _Credentials() client = Client(project=self.PROJECT, credentials=creds) - client.connection = connection + client._connection = connection api = self._make_one(client) iterator = api.list_subscriptions( @@ -879,7 +879,7 @@ def api_request(self, **kw): class _Client(object): def __init__(self, connection, project): - self.connection = connection + self._connection = connection self.project = project diff --git a/pubsub/unit_tests/test_client.py b/pubsub/unit_tests/test_client.py index 462d55abba2b..d5e29cd94dc7 100644 --- a/pubsub/unit_tests/test_client.py +++ b/pubsub/unit_tests/test_client.py @@ -39,7 +39,7 @@ def test_publisher_api_wo_gax(self): with _Monkey(MUT, _USE_GAX=False): client = self._make_one(project=self.PROJECT, credentials=creds) - conn = client.connection = object() + conn = client._connection = object() api = client.publisher_api self.assertIsInstance(api, _PublisherAPI) @@ -93,7 +93,7 @@ def __init__(self, _wrapped, client): # API instance is cached again = client.publisher_api self.assertIs(again, api) - args = (client.connection,) + args = (client._connection,) self.assertEqual(_called_with, [(args, {})]) def test_subscriber_api_wo_gax(self): @@ -105,7 +105,7 @@ def test_subscriber_api_wo_gax(self): with _Monkey(MUT, _USE_GAX=False): client = self._make_one(project=self.PROJECT, credentials=creds) - conn = client.connection = object() + conn = client._connection = object() api = client.subscriber_api self.assertIsInstance(api, _SubscriberAPI) @@ -145,14 +145,14 @@ def __init__(self, _wrapped, client): # API instance is cached again = client.subscriber_api self.assertIs(again, api) - args = (client.connection,) + args = (client._connection,) self.assertEqual(_called_with, [(args, {})]) def test_iam_policy_api(self): from google.cloud.pubsub._http import _IAMPolicyAPI creds = _Credentials() client = self._make_one(project=self.PROJECT, credentials=creds) - conn = client.connection = object() + conn = client._connection = object() api = client.iam_policy_api self.assertIsInstance(api, _IAMPolicyAPI) self.assertIs(api._connection, conn) @@ -165,7 +165,7 @@ def test_list_topics_no_paging(self): creds = _Credentials() client = self._make_one(project=self.PROJECT, credentials=creds) - client.connection = object() + client._connection = object() api = _FauxPublisherAPI(items=[Topic(self.TOPIC_NAME, client)]) client._publisher_api = api @@ -188,7 +188,7 @@ def test_list_topics_with_paging(self): SIZE = 1 creds = _Credentials() client = self._make_one(project=self.PROJECT, credentials=creds) - client.connection = object() + client._connection = object() api = _FauxPublisherAPI([Topic(self.TOPIC_NAME, client)], TOKEN2) client._publisher_api = api @@ -206,7 +206,7 @@ def test_list_topics_with_paging(self): def test_list_topics_missing_key(self): creds = _Credentials() client = self._make_one(project=self.PROJECT, credentials=creds) - client.connection = object() + client._connection = object() api = _FauxPublisherAPI() client._publisher_api = api @@ -228,7 +228,7 @@ def test_list_subscriptions_no_paging(self): client = self._make_one(project=self.PROJECT, credentials=creds, use_gax=False) returned = {'subscriptions': [SUB_INFO]} - client.connection = _Connection(returned) + client._connection = _Connection(returned) iterator = client.list_subscriptions() subscriptions = list(iterator) @@ -248,7 +248,7 @@ def test_list_subscriptions_no_paging(self): self.assertIsNone(subscription.ack_deadline) self.assertIsNone(subscription.push_endpoint) - called_with = client.connection._called_with + called_with = client._connection._called_with expected_path = '/projects/%s/subscriptions' % (self.PROJECT,) self.assertEqual(called_with, { 'method': 'GET', @@ -280,7 +280,7 @@ def test_list_subscriptions_with_paging(self): 'subscriptions': [SUB_INFO], 'nextPageToken': TOKEN2, } - client.connection = _Connection(returned) + client._connection = _Connection(returned) iterator = client.list_subscriptions( SIZE, TOKEN1) @@ -302,7 +302,7 @@ def test_list_subscriptions_with_paging(self): self.assertEqual(subscription.ack_deadline, ACK_DEADLINE) self.assertEqual(subscription.push_endpoint, PUSH_ENDPOINT) - called_with = client.connection._called_with + called_with = client._connection._called_with expected_path = '/projects/%s/subscriptions' % (self.PROJECT,) self.assertEqual(called_with, { 'method': 'GET', @@ -318,7 +318,7 @@ def test_list_subscriptions_w_missing_key(self): creds = _Credentials() client = self._make_one(project=PROJECT, credentials=creds) - client.connection = object() + client._connection = object() api = client._subscriber_api = _FauxSubscriberAPI() api._list_subscriptions_response = (), None diff --git a/pubsub/unit_tests/test_topic.py b/pubsub/unit_tests/test_topic.py index 8f4838237fd7..06ea6bff42af 100644 --- a/pubsub/unit_tests/test_topic.py +++ b/pubsub/unit_tests/test_topic.py @@ -330,7 +330,7 @@ def test_list_subscriptions_no_paging(self): 'subscriptions': SUBS_LIST, 'nextPageToken': TOKEN, } - client.connection = _Connection(returned) + client._connection = _Connection(returned) topic = self._make_one(self.TOPIC_NAME, client=client) @@ -353,7 +353,7 @@ def test_list_subscriptions_no_paging(self): self.assertEqual(next_page_token, TOKEN) # Verify the mock. - called_with = client.connection._called_with + called_with = client._connection._called_with self.assertEqual(len(called_with), 3) self.assertEqual(called_with['method'], 'GET') path = '/%s/subscriptions' % (self.TOPIC_PATH,) @@ -380,7 +380,7 @@ def test_list_subscriptions_with_paging(self): returned = { 'subscriptions': SUBS_LIST, } - client.connection = _Connection(returned) + client._connection = _Connection(returned) topic = self._make_one(self.TOPIC_NAME, client=client) @@ -403,7 +403,7 @@ def test_list_subscriptions_with_paging(self): self.assertIsNone(next_page_token) # Verify the mock. - called_with = client.connection._called_with + called_with = client._connection._called_with self.assertEqual(len(called_with), 3) self.assertEqual(called_with['method'], 'GET') path = '/%s/subscriptions' % (self.TOPIC_PATH,) @@ -416,7 +416,7 @@ def test_list_subscriptions_missing_key(self): client = Client(project=self.PROJECT, credentials=object(), use_gax=False) - client.connection = _Connection({}) + client._connection = _Connection({}) topic = self._make_one(self.TOPIC_NAME, client=client) iterator = topic.list_subscriptions() @@ -426,7 +426,7 @@ def test_list_subscriptions_missing_key(self): self.assertEqual(len(subscriptions), 0) self.assertIsNone(next_page_token) # Verify the mock. - called_with = client.connection._called_with + called_with = client._connection._called_with self.assertEqual(len(called_with), 3) self.assertEqual(called_with['method'], 'GET') path = '/%s/subscriptions' % (self.TOPIC_PATH,) diff --git a/resource_manager/google/cloud/resource_manager/connection.py b/resource_manager/google/cloud/resource_manager/connection.py index 1b8fd4f0bd7f..ee3bbfcc3e9a 100644 --- a/resource_manager/google/cloud/resource_manager/connection.py +++ b/resource_manager/google/cloud/resource_manager/connection.py @@ -15,10 +15,10 @@ """Create / interact with Google Cloud Resource Manager connections.""" -from google.cloud import connection as base_connection +from google.cloud import _http -class Connection(base_connection.JSONConnection): +class Connection(_http.JSONConnection): """A connection to Google Cloud Resource Manager via the JSON REST API. :type credentials: :class:`oauth2client.client.OAuth2Credentials` diff --git a/resource_manager/google/cloud/resource_manager/project.py b/resource_manager/google/cloud/resource_manager/project.py index 2239cb714a73..a161b0db3c21 100644 --- a/resource_manager/google/cloud/resource_manager/project.py +++ b/resource_manager/google/cloud/resource_manager/project.py @@ -131,8 +131,8 @@ def create(self, client=None): 'name': self.name, 'labels': self.labels, } - resp = client.connection.api_request(method='POST', path='/projects', - data=data) + resp = client._connection.api_request(method='POST', path='/projects', + data=data) self.set_properties_from_api_repr(resource=resp) def reload(self, client=None): @@ -161,7 +161,7 @@ def reload(self, client=None): # We assume the project exists. If it doesn't it will raise a NotFound # exception. - resp = client.connection.api_request(method='GET', path=self.path) + resp = client._connection.api_request(method='GET', path=self.path) self.set_properties_from_api_repr(resource=resp) def exists(self, client=None): @@ -183,7 +183,7 @@ def exists(self, client=None): try: # Note that we have to request the entire resource as the API # doesn't provide a way tocheck for existence only. - client.connection.api_request(method='GET', path=self.path) + client._connection.api_request(method='GET', path=self.path) except NotFound: return False else: @@ -203,8 +203,8 @@ def update(self, client=None): client = self._require_client(client) data = {'name': self.name, 'labels': self.labels} - resp = client.connection.api_request(method='PUT', path=self.path, - data=data) + resp = client._connection.api_request( + method='PUT', path=self.path, data=data) self.set_properties_from_api_repr(resp) def delete(self, client=None, reload_data=False): @@ -232,7 +232,7 @@ def delete(self, client=None, reload_data=False): Default: :data:`False`. """ client = self._require_client(client) - client.connection.api_request(method='DELETE', path=self.path) + client._connection.api_request(method='DELETE', path=self.path) # If the reload flag is set, reload the project. if reload_data: @@ -262,8 +262,8 @@ def undelete(self, client=None, reload_data=False): Default: :data:`False`. """ client = self._require_client(client) - client.connection.api_request(method='POST', - path=self.path + ':undelete') + client._connection.api_request( + method='POST', path=self.path + ':undelete') # If the reload flag is set, reload the project. if reload_data: diff --git a/resource_manager/unit_tests/test_client.py b/resource_manager/unit_tests/test_client.py index 9e73075d5681..1fa4229284fc 100644 --- a/resource_manager/unit_tests/test_client.py +++ b/resource_manager/unit_tests/test_client.py @@ -31,9 +31,9 @@ def test_constructor(self): http = object() credentials = _Credentials() client = self._make_one(credentials=credentials, http=http) - self.assertIsInstance(client.connection, Connection) - self.assertEqual(client.connection._credentials, credentials) - self.assertEqual(client.connection._http, http) + self.assertIsInstance(client._connection, Connection) + self.assertEqual(client._connection._credentials, credentials) + self.assertEqual(client._connection._http, http) def test_new_project_factory(self): from google.cloud.resource_manager.project import Project @@ -69,7 +69,7 @@ def test_fetch_project(self): credentials = _Credentials() client = self._make_one(credentials=credentials) # Patch the connection with one we can easily control. - client.connection = _Connection(project_resource) + client._connection = _Connection(project_resource) project = client.fetch_project(project_id) self.assertIsInstance(project, Project) @@ -84,7 +84,7 @@ def test_list_projects_return_type(self): credentials = _Credentials() client = self._make_one(credentials=credentials) # Patch the connection with one we can easily control. - client.connection = _Connection({}) + client._connection = _Connection({}) results = client.list_projects() self.assertIsInstance(results, HTTPIterator) @@ -106,7 +106,7 @@ def test_list_projects_no_paging(self): ], } # Patch the connection with one we can easily control. - client.connection = _Connection(PROJECTS_RESOURCE) + client._connection = _Connection(PROJECTS_RESOURCE) # Make sure there will be no paging. self.assertFalse('nextPageToken' in PROJECTS_RESOURCE) @@ -147,8 +147,8 @@ def test_list_projects_with_paging(self): ], } # Patch the connection with one we can easily control. - client.connection = _Connection(FIRST_PROJECTS_RESOURCE, - SECOND_PROJECTS_RESOURCE) + client._connection = _Connection(FIRST_PROJECTS_RESOURCE, + SECOND_PROJECTS_RESOURCE) # Page size = 1 with two response means we'll have two requests. results = list(client.list_projects(page_size=1)) @@ -163,7 +163,7 @@ def test_list_projects_with_paging(self): self.assertEqual(project2.status, STATUS) # Check that two requests were required since page_size=1. - request1, request2 = client.connection._requested + request1, request2 = client._connection._requested self.assertEqual(request1, { 'path': '/projects', 'method': 'GET', @@ -197,7 +197,7 @@ def test_list_projects_with_filter(self): ], } # Patch the connection with one we can easily control. - client.connection = _Connection(PROJECTS_RESOURCE) + client._connection = _Connection(PROJECTS_RESOURCE) FILTER_PARAMS = {'id': 'project-id'} results = list(client.list_projects(filter_params=FILTER_PARAMS)) @@ -208,7 +208,7 @@ def test_list_projects_with_filter(self): self.assertEqual(project.status, STATUS) # Check that the filter made it in the request. - request, = client.connection._requested + request, = client._connection._requested self.assertEqual(request, { 'path': '/projects', 'method': 'GET', diff --git a/resource_manager/unit_tests/test_project.py b/resource_manager/unit_tests/test_project.py index e80b51d8a78d..964a9f463e8b 100644 --- a/resource_manager/unit_tests/test_project.py +++ b/resource_manager/unit_tests/test_project.py @@ -338,4 +338,4 @@ def api_request(self, **kw): class _Client(object): def __init__(self, connection=None): - self.connection = connection + self._connection = connection diff --git a/runtimeconfig/google/cloud/runtimeconfig/config.py b/runtimeconfig/google/cloud/runtimeconfig/config.py index 7a259df23f09..0af33d034d5a 100644 --- a/runtimeconfig/google/cloud/runtimeconfig/config.py +++ b/runtimeconfig/google/cloud/runtimeconfig/config.py @@ -153,7 +153,7 @@ def exists(self, client=None): # We only need the status code (200 or not) so we seek to # minimize the returned payload. query_params = {'fields': 'name'} - client.connection.api_request( + client._connection.api_request( method='GET', path=self.path, query_params=query_params) return True except NotFound: @@ -176,7 +176,7 @@ def reload(self, client=None): # We assume the config exists. If it doesn't it will raise a NotFound # exception. - resp = client.connection.api_request(method='GET', path=self.path) + resp = client._connection.api_request(method='GET', path=self.path) self._set_properties(api_response=resp) def get_variable(self, variable_name, client=None): diff --git a/runtimeconfig/google/cloud/runtimeconfig/connection.py b/runtimeconfig/google/cloud/runtimeconfig/connection.py index 958b6a4aa869..5074158c5f47 100644 --- a/runtimeconfig/google/cloud/runtimeconfig/connection.py +++ b/runtimeconfig/google/cloud/runtimeconfig/connection.py @@ -16,10 +16,10 @@ """Create / interact with Google Cloud RuntimeConfig connections.""" -from google.cloud import connection as base_connection +from google.cloud import _http -class Connection(base_connection.JSONConnection): +class Connection(_http.JSONConnection): """A connection to Google Cloud RuntimeConfig via the JSON REST API. :type credentials: :class:`oauth2client.client.OAuth2Credentials` diff --git a/runtimeconfig/google/cloud/runtimeconfig/variable.py b/runtimeconfig/google/cloud/runtimeconfig/variable.py index cf2c733c3a21..602653f5b357 100644 --- a/runtimeconfig/google/cloud/runtimeconfig/variable.py +++ b/runtimeconfig/google/cloud/runtimeconfig/variable.py @@ -206,8 +206,8 @@ def exists(self, client=None): # We only need the status code (200 or not) so we seek to # minimize the returned payload. query_params = {'fields': 'name'} - client.connection.api_request(method='GET', path=self.path, - query_params=query_params) + client._connection.api_request(method='GET', path=self.path, + query_params=query_params) return True except NotFound: return False @@ -229,5 +229,5 @@ def reload(self, client=None): # We assume the variable exists. If it doesn't it will raise a NotFound # exception. - resp = client.connection.api_request(method='GET', path=self.path) + resp = client._connection.api_request(method='GET', path=self.path) self._set_properties(resource=resp) diff --git a/runtimeconfig/unit_tests/test_config.py b/runtimeconfig/unit_tests/test_config.py index 615a61ee1568..44b07e198c3d 100644 --- a/runtimeconfig/unit_tests/test_config.py +++ b/runtimeconfig/unit_tests/test_config.py @@ -331,11 +331,11 @@ def test_list_variables_explicit(self): class _Client(object): - connection = None + _connection = None def __init__(self, project, connection=None): self.project = project - self.connection = connection + self._connection = connection class _Connection(object): diff --git a/runtimeconfig/unit_tests/test_variable.py b/runtimeconfig/unit_tests/test_variable.py index ad51cba666b4..e9ff4ed1dc2b 100644 --- a/runtimeconfig/unit_tests/test_variable.py +++ b/runtimeconfig/unit_tests/test_variable.py @@ -178,11 +178,11 @@ def test_reload_w_alternate_client(self): class _Client(object): - connection = None + _connection = None def __init__(self, project, connection=None): self.project = project - self.connection = connection + self._connection = connection class _Connection(object): diff --git a/speech/google/cloud/speech/_gax.py b/speech/google/cloud/speech/_gax.py index aa9e9aa95d58..70e1b6b66f77 100644 --- a/speech/google/cloud/speech/_gax.py +++ b/speech/google/cloud/speech/_gax.py @@ -27,7 +27,7 @@ from google.cloud._helpers import make_secure_channel from google.cloud._helpers import make_secure_stub -from google.cloud.connection import DEFAULT_USER_AGENT +from google.cloud._http import DEFAULT_USER_AGENT from google.cloud.speech.alternative import Alternative from google.cloud.speech.operation import Operation @@ -39,7 +39,7 @@ class GAPICSpeechAPI(object): """Manage calls through GAPIC wrappers to the Speech API.""" def __init__(self, client=None): self._client = client - credentials = self._client.connection.credentials + credentials = self._client._connection.credentials channel = make_secure_channel( credentials, DEFAULT_USER_AGENT, SpeechApi.SERVICE_ADDRESS) diff --git a/speech/google/cloud/speech/client.py b/speech/google/cloud/speech/client.py index ce93ad785880..125722d128ef 100644 --- a/speech/google/cloud/speech/client.py +++ b/speech/google/cloud/speech/client.py @@ -308,16 +308,7 @@ class _JSONSpeechAPI(object): """ def __init__(self, client): self._client = client - self._connection = client.connection - - @property - def connection(self): - """Connection property. - - :rtype: :class:`~google.cloud.core.connection.Connection` - :returns: Instance of ``Connection`` - """ - return self._connection + self._connection = client._connection def async_recognize(self, sample, language_code=None, max_alternatives=None, profanity_filter=None, diff --git a/speech/google/cloud/speech/connection.py b/speech/google/cloud/speech/connection.py index d74d729344e8..c4661c01e9d5 100644 --- a/speech/google/cloud/speech/connection.py +++ b/speech/google/cloud/speech/connection.py @@ -14,10 +14,10 @@ """Create / interact with Google Cloud Speech connections.""" -from google.cloud import connection as base_connection +from google.cloud import _http -class Connection(base_connection.JSONConnection): +class Connection(_http.JSONConnection): """A connection to Google Cloud Speech JSON REST API.""" API_BASE_URL = 'https://speech.googleapis.com' diff --git a/speech/unit_tests/test_client.py b/speech/unit_tests/test_client.py index 895cd715d39d..f0436e6d5c17 100644 --- a/speech/unit_tests/test_client.py +++ b/speech/unit_tests/test_client.py @@ -82,9 +82,9 @@ def test_ctor(self): creds = _Credentials() http = object() client = self._make_one(credentials=creds, http=http) - self.assertIsInstance(client.connection, Connection) - self.assertTrue(client.connection.credentials is creds) - self.assertTrue(client.connection.http is http) + self.assertIsInstance(client._connection, Connection) + self.assertTrue(client._connection.credentials is creds) + self.assertTrue(client._connection.http is http) def test_ctor_use_gax_preset(self): creds = _Credentials() @@ -147,7 +147,7 @@ def test_sync_recognize_content_with_optional_params_no_gax(self): } credentials = _Credentials() client = self._make_one(credentials=credentials, use_gax=False) - client.connection = _Connection(RETURNED) + client._connection = _Connection(RETURNED) encoding = speech.Encoding.FLAC @@ -160,8 +160,8 @@ def test_sync_recognize_content_with_optional_params_no_gax(self): profanity_filter=True, speech_context=self.HINTS) - self.assertEqual(len(client.connection._requested), 1) - req = client.connection._requested[0] + self.assertEqual(len(client._connection._requested), 1) + req = client._connection._requested[0] self.assertEqual(len(req), 3) self.assertEqual(req['data'], REQUEST) self.assertEqual(req['method'], 'POST') @@ -192,7 +192,7 @@ def test_sync_recognize_source_uri_without_optional_params_no_gax(self): } credentials = _Credentials() client = self._make_one(credentials=credentials, use_gax=False) - client.connection = _Connection(RETURNED) + client._connection = _Connection(RETURNED) encoding = speech.Encoding.FLAC @@ -201,8 +201,8 @@ def test_sync_recognize_source_uri_without_optional_params_no_gax(self): response = client.sync_recognize(sample) - self.assertEqual(len(client.connection._requested), 1) - req = client.connection._requested[0] + self.assertEqual(len(client._connection._requested), 1) + req = client._connection._requested[0] self.assertEqual(len(req), 3) self.assertEqual(req['data'], REQUEST) self.assertEqual(req['method'], 'POST') @@ -222,7 +222,7 @@ def test_sync_recognize_with_empty_results_no_gax(self): credentials = _Credentials() client = self._make_one(credentials=credentials, use_gax=False) - client.connection = _Connection(SYNC_RECOGNIZE_EMPTY_RESPONSE) + client._connection = _Connection(SYNC_RECOGNIZE_EMPTY_RESPONSE) sample = Sample(source_uri=self.AUDIO_SOURCE_URI, encoding=speech.Encoding.FLAC, @@ -240,8 +240,8 @@ def test_sync_recognize_with_empty_results_gax(self): credentials = _Credentials() client = self._make_one(credentials=credentials, use_gax=True) - client.connection = _Connection() - client.connection.credentials = credentials + client._connection = _Connection() + client._connection.credentials = credentials channel_args = [] channel_obj = object() @@ -283,8 +283,8 @@ def test_sync_recognize_with_gax(self): creds = _Credentials() client = self._make_one(credentials=creds, use_gax=True) - client.connection = _Connection() - client.connection.credentials = creds + client._connection = _Connection() + client._connection.credentials = creds client._speech_api = None alternatives = [{ @@ -344,7 +344,7 @@ def test_async_supported_encodings(self): credentials = _Credentials() client = self._make_one(credentials=credentials) - client.connection = _Connection({}) + client._connection = _Connection({}) sample = Sample(source_uri=self.AUDIO_SOURCE_URI, encoding=speech.Encoding.FLAC, @@ -362,7 +362,7 @@ def test_async_recognize_no_gax(self): credentials = _Credentials() client = self._make_one(credentials=credentials, use_gax=False) - client.connection = _Connection(RETURNED) + client._connection = _Connection(RETURNED) sample = Sample(source_uri=self.AUDIO_SOURCE_URI, encoding=speech.Encoding.LINEAR16, @@ -385,8 +385,8 @@ def test_async_recognize_with_gax(self): credentials = _Credentials() client = self._make_one(credentials=credentials, use_gax=True) - client.connection = _Connection() - client.connection.credentials = credentials + client._connection = _Connection() + client._connection.credentials = credentials channel_args = [] channel_obj = object() @@ -652,8 +652,8 @@ def test_speech_api_with_gax(self): creds = _Credentials() client = self._make_one(credentials=creds, use_gax=True) - client.connection = _Connection() - client.connection.credentials = creds + client._connection = _Connection() + client._connection.credentials = creds channel_args = [] channel_obj = object() @@ -680,14 +680,14 @@ def speech_api(channel=None): self.assertEqual(channel_args, [expected]) def test_speech_api_without_gax(self): - from google.cloud.connection import Connection + from google.cloud._http import Connection from google.cloud.speech.client import _JSONSpeechAPI creds = _Credentials() client = self._make_one(credentials=creds, use_gax=False) self.assertIsNone(client._speech_api) self.assertIsInstance(client.speech_api, _JSONSpeechAPI) - self.assertIsInstance(client.speech_api.connection, Connection) + self.assertIsInstance(client.speech_api._connection, Connection) def test_speech_api_preset(self): creds = _Credentials() diff --git a/storage/google/cloud/storage/_helpers.py b/storage/google/cloud/storage/_helpers.py index 18dec847f571..955eba01d7aa 100644 --- a/storage/google/cloud/storage/_helpers.py +++ b/storage/google/cloud/storage/_helpers.py @@ -74,7 +74,7 @@ def reload(self, client=None): # Pass only '?projection=noAcl' here because 'acl' and related # are handled via custom endpoints. query_params = {'projection': 'noAcl'} - api_response = client.connection.api_request( + api_response = client._connection.api_request( method='GET', path=self.path, query_params=query_params, _target_object=self) self._set_properties(api_response) @@ -122,7 +122,7 @@ def patch(self, client=None): # to work properly w/ 'noAcl'. update_properties = {key: self._properties[key] for key in self._changes} - api_response = client.connection.api_request( + api_response = client._connection.api_request( method='PATCH', path=self.path, data=update_properties, query_params={'projection': 'full'}, _target_object=self) self._set_properties(api_response) diff --git a/storage/google/cloud/storage/_http.py b/storage/google/cloud/storage/_http.py index 76fe48549786..9deaf4fd37ca 100644 --- a/storage/google/cloud/storage/_http.py +++ b/storage/google/cloud/storage/_http.py @@ -14,10 +14,10 @@ """Create / interact with Google Cloud Storage connections.""" -from google.cloud import connection as base_connection +from google.cloud import _http -class Connection(base_connection.JSONConnection): +class Connection(_http.JSONConnection): """A connection to Google Cloud Storage via the JSON REST API. :type credentials: :class:`oauth2client.client.OAuth2Credentials` @@ -28,7 +28,7 @@ class Connection(base_connection.JSONConnection): :param http: (Optional) HTTP object to make requests. """ - API_BASE_URL = base_connection.API_BASE_URL + API_BASE_URL = _http.API_BASE_URL """The base of the API call URL.""" API_VERSION = 'v1' diff --git a/storage/google/cloud/storage/acl.py b/storage/google/cloud/storage/acl.py index 4e40348e98bc..e93e292d9d97 100644 --- a/storage/google/cloud/storage/acl.py +++ b/storage/google/cloud/storage/acl.py @@ -407,7 +407,7 @@ def reload(self, client=None): self.entities.clear() - found = client.connection.api_request(method='GET', path=path) + found = client._connection.api_request(method='GET', path=path) self.loaded = True for entry in found.get('items', ()): self.add_entity(self.entity_from_dict(entry)) @@ -436,7 +436,7 @@ def _save(self, acl, predefined, client): path = self.save_path client = self._require_client(client) - result = client.connection.api_request( + result = client._connection.api_request( method='PATCH', path=path, data={self._URL_PATH_ELEM: list(acl)}, diff --git a/storage/google/cloud/storage/batch.py b/storage/google/cloud/storage/batch.py index 96384f9ed9aa..a68d9cdc3ea6 100644 --- a/storage/google/cloud/storage/batch.py +++ b/storage/google/cloud/storage/batch.py @@ -241,10 +241,10 @@ def finish(self): url = '%s/batch' % self.API_BASE_URL - # Use the private ``_connection`` rather than the public - # ``.connection``, since the public connection may be this + # Use the private ``_base_connection`` rather than the property + # ``_connection``, since the property may be this # current batch. - response, content = self._client._connection._make_request( + response, content = self._client._base_connection._make_request( 'POST', url, data=body, headers=headers) responses = list(_unpack_batch_response(response, content)) self._finish_futures(responses) diff --git a/storage/google/cloud/storage/blob.py b/storage/google/cloud/storage/blob.py index 16da5782fef5..b409bc29afcd 100644 --- a/storage/google/cloud/storage/blob.py +++ b/storage/google/cloud/storage/blob.py @@ -235,7 +235,7 @@ def generate_signed_url(self, expiration, method='GET', if credentials is None: client = self._require_client(client) - credentials = client._connection.credentials + credentials = client._base_connection.credentials return generate_signed_url( credentials, resource=resource, @@ -264,9 +264,9 @@ def exists(self, client=None): query_params = {'fields': 'name'} # We intentionally pass `_target_object=None` since fields=name # would limit the local properties. - client.connection.api_request(method='GET', path=self.path, - query_params=query_params, - _target_object=None) + client._connection.api_request( + method='GET', path=self.path, + query_params=query_params, _target_object=None) # NOTE: This will not fail immediately in a batch. However, when # Batch.finish() is called, the resulting `NotFound` will be # raised. @@ -344,13 +344,13 @@ def download_to_file(self, file_obj, client=None): request = Request(download_url, 'GET', headers) - # Use the private ``_connection`` rather than the public - # ``.connection``, since the public connection may be a batch. A - # batch wraps a client's connection, but does not store the `http` - # object. The rest (API_BASE_URL and build_api_url) are also defined - # on the Batch class, but we just use the wrapped connection since - # it has all three (http, API_BASE_URL and build_api_url). - download.initialize_download(request, client._connection.http) + # Use ``_base_connection`` rather ``_connection`` since the current + # connection may be a batch. A batch wraps a client's connection, + # but does not store the ``http`` object. The rest (API_BASE_URL and + # build_api_url) are also defined on the Batch class, but we just + # use the wrapped connection since it has all three (http, + # API_BASE_URL and build_api_url). + download.initialize_download(request, client._base_connection.http) def download_to_filename(self, filename, client=None): """Download the contents of this blob into a named file. @@ -466,13 +466,13 @@ def upload_from_file(self, file_obj, rewind=False, size=None, if the upload response returns an error status. """ client = self._require_client(client) - # Use the private ``_connection`` rather than the public - # ``.connection``, since the public connection may be a batch. A - # batch wraps a client's connection, but does not store the `http` - # object. The rest (API_BASE_URL and build_api_url) are also defined - # on the Batch class, but we just use the wrapped connection since - # it has all three (http, API_BASE_URL and build_api_url). - connection = client._connection + # Use ``_base_connection`` rather ``_connection`` since the current + # connection may be a batch. A batch wraps a client's connection, + # but does not store the ``http`` object. The rest (API_BASE_URL and + # build_api_url) are also defined on the Batch class, but we just + # use the wrapped connection since it has all three (http, + # API_BASE_URL and build_api_url). + connection = client._base_connection content_type = (content_type or self._properties.get('contentType') or 'application/octet-stream') @@ -650,7 +650,7 @@ def compose(self, sources, client=None): 'sourceObjects': [{'name': source.name} for source in sources], 'destination': self._properties.copy(), } - api_response = client.connection.api_request( + api_response = client._connection.api_request( method='POST', path=self.path + '/compose', data=request, _target_object=self) self._set_properties(api_response) @@ -688,7 +688,7 @@ def rewrite(self, source, token=None, client=None): else: query_params = {} - api_response = client.connection.api_request( + api_response = client._connection.api_request( method='POST', path=source.path + '/rewriteTo' + self.path, query_params=query_params, data=self._properties, headers=headers, _target_object=self) diff --git a/storage/google/cloud/storage/bucket.py b/storage/google/cloud/storage/bucket.py index 3c3ac4adc840..c4705645c427 100644 --- a/storage/google/cloud/storage/bucket.py +++ b/storage/google/cloud/storage/bucket.py @@ -144,9 +144,9 @@ def exists(self, client=None): query_params = {'fields': 'name'} # We intentionally pass `_target_object=None` since fields=name # would limit the local properties. - client.connection.api_request(method='GET', path=self.path, - query_params=query_params, - _target_object=None) + client._connection.api_request( + method='GET', path=self.path, + query_params=query_params, _target_object=None) # NOTE: This will not fail immediately in a batch. However, when # Batch.finish() is called, the resulting `NotFound` will be # raised. @@ -171,7 +171,7 @@ def create(self, client=None): query_params = {'project': client.project} properties = {key: self._properties[key] for key in self._changes} properties['name'] = self.name - api_response = client.connection.api_request( + api_response = client._connection.api_request( method='POST', path='/b', query_params=query_params, data=properties, _target_object=self) self._set_properties(api_response) @@ -233,7 +233,7 @@ def get_blob(self, blob_name, client=None): client = self._require_client(client) blob = Blob(bucket=self, name=blob_name) try: - response = client.connection.api_request( + response = client._connection.api_request( method='GET', path=blob.path, _target_object=blob) # NOTE: We assume response.get('name') matches `blob_name`. blob._set_properties(response) @@ -363,8 +363,8 @@ def delete(self, force=False, client=None): # We intentionally pass `_target_object=None` since a DELETE # request has no response value (whether in a standard request or # in a batch request). - client.connection.api_request(method='DELETE', path=self.path, - _target_object=None) + client._connection.api_request( + method='DELETE', path=self.path, _target_object=None) def delete_blob(self, blob_name, client=None): """Deletes a blob from the current bucket. @@ -405,8 +405,8 @@ def delete_blob(self, blob_name, client=None): # We intentionally pass `_target_object=None` since a DELETE # request has no response value (whether in a standard request or # in a batch request). - client.connection.api_request(method='DELETE', path=blob_path, - _target_object=None) + client._connection.api_request( + method='DELETE', path=blob_path, _target_object=None) def delete_blobs(self, blobs, on_error=None, client=None): """Deletes a list of blobs from the current bucket. @@ -472,7 +472,7 @@ def copy_blob(self, blob, destination_bucket, new_name=None, new_name = blob.name new_blob = Blob(bucket=destination_bucket, name=new_name) api_path = blob.path + '/copyTo' + new_blob.path - copy_result = client.connection.api_request( + copy_result = client._connection.api_request( method='POST', path=api_path, _target_object=new_blob) if not preserve_acl: new_blob.acl.save(acl={}, client=client) diff --git a/storage/google/cloud/storage/client.py b/storage/google/cloud/storage/client.py index c1711a9bbdf3..f8a64a3dc98c 100644 --- a/storage/google/cloud/storage/client.py +++ b/storage/google/cloud/storage/client.py @@ -48,13 +48,13 @@ class Client(JSONClient): _connection_class = Connection def __init__(self, project=None, credentials=None, http=None): - self._connection = None + self._base_connection = None super(Client, self).__init__(project=project, credentials=credentials, http=http) self._batch_stack = _LocalStack() @property - def connection(self): + def _connection(self): """Get connection or batch on the client. :rtype: :class:`google.cloud.storage._http.Connection` @@ -64,14 +64,14 @@ def connection(self): if self.current_batch is not None: return self.current_batch else: - return self._connection + return self._base_connection - @connection.setter - def connection(self, value): + @_connection.setter + def _connection(self, value): """Set connection on the client. Intended to be used by constructor (since the base class calls) - self.connection = connection + self._connection = connection Will raise if the connection is set more than once. :type value: :class:`google.cloud.storage._http.Connection` @@ -79,9 +79,9 @@ def connection(self, value): :raises: :class:`ValueError` if connection has already been set. """ - if self._connection is not None: + if self._base_connection is not None: raise ValueError('Connection already set on client') - self._connection = value + self._base_connection = value def _push_batch(self, batch): """Push a batch onto our stack. diff --git a/storage/unit_tests/test__helpers.py b/storage/unit_tests/test__helpers.py index 6912addd4d6c..5bcb26cb275a 100644 --- a/storage/unit_tests/test__helpers.py +++ b/storage/unit_tests/test__helpers.py @@ -223,4 +223,4 @@ def b64encode(self, value): class _Client(object): def __init__(self, connection): - self.connection = connection + self._connection = connection diff --git a/storage/unit_tests/test_acl.py b/storage/unit_tests/test_acl.py index e58138b32c31..52187def7a89 100644 --- a/storage/unit_tests/test_acl.py +++ b/storage/unit_tests/test_acl.py @@ -813,4 +813,4 @@ def api_request(self, **kw): class _Client(object): def __init__(self, connection): - self.connection = connection + self._connection = connection diff --git a/storage/unit_tests/test_batch.py b/storage/unit_tests/test_batch.py index a340fe253d37..74d6cf155835 100644 --- a/storage/unit_tests/test_batch.py +++ b/storage/unit_tests/test_batch.py @@ -380,7 +380,7 @@ def test_as_context_mgr_wo_error(self): project = 'PROJECT' credentials = _Credentials() client = Client(project=project, credentials=credentials) - client._connection._http = http + client._base_connection._http = http self.assertEqual(list(client._batch_stack), []) @@ -416,7 +416,7 @@ def test_as_context_mgr_w_error(self): project = 'PROJECT' credentials = _Credentials() client = Client(project=project, credentials=credentials) - client._connection = connection + client._base_connection = connection self.assertEqual(list(client._batch_stack), []) @@ -598,7 +598,7 @@ class _MockObject(object): class _Client(object): def __init__(self, connection): - self._connection = connection + self._base_connection = connection class _Credentials(object): diff --git a/storage/unit_tests/test_blob.py b/storage/unit_tests/test_blob.py index 2813261228a5..f0a34cd2ca30 100644 --- a/storage/unit_tests/test_blob.py +++ b/storage/unit_tests/test_blob.py @@ -1747,11 +1747,11 @@ def __call__(self, *args, **kwargs): class _Client(object): def __init__(self, connection): - self._connection = connection + self._base_connection = connection @property - def connection(self): - return self._connection + def _connection(self): + return self._base_connection class _Stream(object): diff --git a/storage/unit_tests/test_bucket.py b/storage/unit_tests/test_bucket.py index 2c4aa5d87da1..1a7a7b9cc9eb 100644 --- a/storage/unit_tests/test_bucket.py +++ b/storage/unit_tests/test_bucket.py @@ -1096,5 +1096,5 @@ def api_request(self, **kw): class _Client(object): def __init__(self, connection, project=None): - self.connection = connection + self._connection = connection self.project = project diff --git a/storage/unit_tests/test_client.py b/storage/unit_tests/test_client.py index db15395ae103..ad4eaff75567 100644 --- a/storage/unit_tests/test_client.py +++ b/storage/unit_tests/test_client.py @@ -33,8 +33,8 @@ def test_ctor_connection_type(self): client = self._make_one(project=PROJECT, credentials=CREDENTIALS) self.assertEqual(client.project, PROJECT) - self.assertIsInstance(client.connection, Connection) - self.assertIs(client.connection.credentials, CREDENTIALS) + self.assertIsInstance(client._connection, Connection) + self.assertIs(client._connection.credentials, CREDENTIALS) self.assertIsNone(client.current_batch) self.assertEqual(list(client._batch_stack), []) @@ -59,36 +59,36 @@ def test__push_batch_and__pop_batch(self): self.assertIs(client._pop_batch(), batch1) self.assertEqual(list(client._batch_stack), []) - def test_connection_setter(self): + def test__connection_setter(self): PROJECT = 'PROJECT' CREDENTIALS = _Credentials() client = self._make_one(project=PROJECT, credentials=CREDENTIALS) - client._connection = None # Unset the value from the constructor - client.connection = connection = object() - self.assertIs(client._connection, connection) + client._base_connection = None # Unset the value from the constructor + client._connection = connection = object() + self.assertIs(client._base_connection, connection) - def test_connection_setter_when_set(self): + def test__connection_setter_when_set(self): PROJECT = 'PROJECT' CREDENTIALS = _Credentials() client = self._make_one(project=PROJECT, credentials=CREDENTIALS) - self.assertRaises(ValueError, setattr, client, 'connection', None) + self.assertRaises(ValueError, setattr, client, '_connection', None) - def test_connection_getter_no_batch(self): + def test__connection_getter_no_batch(self): PROJECT = 'PROJECT' CREDENTIALS = _Credentials() client = self._make_one(project=PROJECT, credentials=CREDENTIALS) - self.assertIs(client.connection, client._connection) + self.assertIs(client._connection, client._base_connection) self.assertIsNone(client.current_batch) - def test_connection_getter_with_batch(self): + def test__connection_getter_with_batch(self): from google.cloud.storage.batch import Batch PROJECT = 'PROJECT' CREDENTIALS = _Credentials() client = self._make_one(project=PROJECT, credentials=CREDENTIALS) batch = Batch(client) client._push_batch(batch) - self.assertIsNot(client.connection, client._connection) - self.assertIs(client.connection, batch) + self.assertIsNot(client._connection, client._base_connection) + self.assertIs(client._connection, batch) self.assertIs(client.current_batch, batch) def test_bucket(self): @@ -124,13 +124,13 @@ def test_get_bucket_miss(self): NONESUCH = 'nonesuch' URI = '/'.join([ - client.connection.API_BASE_URL, + client._connection.API_BASE_URL, 'storage', - client.connection.API_VERSION, + client._connection.API_VERSION, 'b', 'nonesuch?projection=noAcl', ]) - http = client.connection._http = _Http( + http = client._connection._http = _Http( {'status': '404', 'content-type': 'application/json'}, b'{}', ) @@ -147,13 +147,13 @@ def test_get_bucket_hit(self): BLOB_NAME = 'blob-name' URI = '/'.join([ - client.connection.API_BASE_URL, + client._connection.API_BASE_URL, 'storage', - client.connection.API_VERSION, + client._connection.API_VERSION, 'b', '%s?projection=noAcl' % (BLOB_NAME,), ]) - http = client.connection._http = _Http( + http = client._connection._http = _Http( {'status': '200', 'content-type': 'application/json'}, '{{"name": "{0}"}}'.format(BLOB_NAME).encode('utf-8'), ) @@ -171,13 +171,13 @@ def test_lookup_bucket_miss(self): NONESUCH = 'nonesuch' URI = '/'.join([ - client.connection.API_BASE_URL, + client._connection.API_BASE_URL, 'storage', - client.connection.API_VERSION, + client._connection.API_VERSION, 'b', 'nonesuch?projection=noAcl', ]) - http = client.connection._http = _Http( + http = client._connection._http = _Http( {'status': '404', 'content-type': 'application/json'}, b'{}', ) @@ -195,13 +195,13 @@ def test_lookup_bucket_hit(self): BLOB_NAME = 'blob-name' URI = '/'.join([ - client.connection.API_BASE_URL, + client._connection.API_BASE_URL, 'storage', - client.connection.API_VERSION, + client._connection.API_VERSION, 'b', '%s?projection=noAcl' % (BLOB_NAME,), ]) - http = client.connection._http = _Http( + http = client._connection._http = _Http( {'status': '200', 'content-type': 'application/json'}, '{{"name": "{0}"}}'.format(BLOB_NAME).encode('utf-8'), ) @@ -221,12 +221,12 @@ def test_create_bucket_conflict(self): BLOB_NAME = 'blob-name' URI = '/'.join([ - client.connection.API_BASE_URL, + client._connection.API_BASE_URL, 'storage', - client.connection.API_VERSION, + client._connection.API_VERSION, 'b?project=%s' % (PROJECT,), ]) - http = client.connection._http = _Http( + http = client._connection._http = _Http( {'status': '409', 'content-type': 'application/json'}, '{"error": {"message": "Conflict"}}', ) @@ -244,12 +244,12 @@ def test_create_bucket_success(self): BLOB_NAME = 'blob-name' URI = '/'.join([ - client.connection.API_BASE_URL, + client._connection.API_BASE_URL, 'storage', - client.connection.API_VERSION, + client._connection.API_VERSION, 'b?project=%s' % (PROJECT,), ]) - http = client.connection._http = _Http( + http = client._connection._http = _Http( {'status': '200', 'content-type': 'application/json'}, '{{"name": "{0}"}}'.format(BLOB_NAME).encode('utf-8'), ) @@ -272,7 +272,7 @@ def test_list_buckets_empty(self): 'project': [PROJECT], 'projection': ['noAcl'], } - http = client.connection._http = _Http( + http = client._connection._http = _Http( {'status': '200', 'content-type': 'application/json'}, b'{}', ) @@ -282,9 +282,9 @@ def test_list_buckets_empty(self): self.assertIsNone(http._called_with['body']) BASE_URI = '/'.join([ - client.connection.API_BASE_URL, + client._connection.API_BASE_URL, 'storage', - client.connection.API_VERSION, + client._connection.API_VERSION, 'b', ]) URI = http._called_with['uri'] @@ -303,12 +303,12 @@ def test_list_buckets_non_empty(self): BUCKET_NAME = 'bucket-name' query_params = urlencode({'project': PROJECT, 'projection': 'noAcl'}) BASE_URI = '/'.join([ - client.connection.API_BASE_URL, + client._connection.API_BASE_URL, 'storage', - client.connection.API_VERSION, + client._connection.API_VERSION, ]) URI = '/'.join([BASE_URI, 'b?%s' % (query_params,)]) - http = client.connection._http = _Http( + http = client._connection._http = _Http( {'status': '200', 'content-type': 'application/json'}, '{{"items": [{{"name": "{0}"}}]}}'.format(BUCKET_NAME) .encode('utf-8'), @@ -343,7 +343,7 @@ def test_list_buckets_all_arguments(self): 'fields': [FIELDS], } - http = client.connection._http = _Http( + http = client._connection._http = _Http( {'status': '200', 'content-type': 'application/json'}, '{"items": []}', ) @@ -360,9 +360,9 @@ def test_list_buckets_all_arguments(self): self.assertIsNone(http._called_with['body']) BASE_URI = '/'.join([ - client.connection.API_BASE_URL, + client._connection.API_BASE_URL, 'storage', - client.connection.API_VERSION, + client._connection.API_VERSION, 'b' ]) URI = http._called_with['uri'] diff --git a/system_tests/datastore.py b/system_tests/datastore.py index 4508b280e649..51e1ffdf17e6 100644 --- a/system_tests/datastore.py +++ b/system_tests/datastore.py @@ -45,7 +45,7 @@ def clone_client(client): cloned_client = datastore.Client(project=client.project, namespace=client.namespace, http=object()) - cloned_client.connection = client.connection + cloned_client._connection = client._connection return cloned_client diff --git a/translate/google/cloud/translate/client.py b/translate/google/cloud/translate/client.py index 572fa2c32e20..f28bd996dffd 100644 --- a/translate/google/cloud/translate/client.py +++ b/translate/google/cloud/translate/client.py @@ -47,7 +47,7 @@ def __init__(self, api_key, http=None, target_language=ENGLISH_ISO_639): self.api_key = api_key if http is None: http = httplib2.Http() - self.connection = Connection(http=http) + self._connection = Connection(http=http) self.target_language = target_language def get_languages(self, target_language=None): @@ -75,7 +75,7 @@ def get_languages(self, target_language=None): target_language = self.target_language if target_language is not None: query_params['target'] = target_language - response = self.connection.api_request( + response = self._connection.api_request( method='GET', path='/languages', query_params=query_params) return response.get('data', {}).get('languages', ()) @@ -117,7 +117,7 @@ def detect_language(self, values): query_params = [('key', self.api_key)] query_params.extend(('q', _to_bytes(value, 'utf-8')) for value in values) - response = self.connection.api_request( + response = self._connection.api_request( method='GET', path='/detect', query_params=query_params) detections = response.get('data', {}).get('detections', ()) @@ -208,7 +208,7 @@ def translate(self, values, target_language=None, format_=None, if source_language is not None: query_params.append(('source', source_language)) - response = self.connection.api_request( + response = self._connection.api_request( method='GET', path='', query_params=query_params) translations = response.get('data', {}).get('translations', ()) diff --git a/translate/google/cloud/translate/connection.py b/translate/google/cloud/translate/connection.py index e1df5a347b91..453a612edfa9 100644 --- a/translate/google/cloud/translate/connection.py +++ b/translate/google/cloud/translate/connection.py @@ -14,10 +14,10 @@ """Create / interact with Google Cloud Translate connections.""" -from google.cloud import connection as base_connection +from google.cloud import _http -class Connection(base_connection.JSONConnection): +class Connection(_http.JSONConnection): """A connection to Google Cloud Translate via the JSON REST API.""" API_BASE_URL = 'https://www.googleapis.com' diff --git a/translate/unit_tests/test_client.py b/translate/unit_tests/test_client.py index f28f2b0c16d6..f3a9ffb76871 100644 --- a/translate/unit_tests/test_client.py +++ b/translate/unit_tests/test_client.py @@ -33,9 +33,9 @@ def test_ctor(self): http = object() client = self._make_one(self.KEY, http=http) - self.assertIsInstance(client.connection, Connection) - self.assertIsNone(client.connection.credentials) - self.assertIs(client.connection.http, http) + self.assertIsInstance(client._connection, Connection) + self.assertIsNone(client._connection.credentials) + self.assertIs(client._connection.http, http) self.assertEqual(client.target_language, ENGLISH_ISO_639) def test_ctor_non_default(self): @@ -44,9 +44,9 @@ def test_ctor_non_default(self): http = object() target = 'es' client = self._make_one(self.KEY, http=http, target_language=target) - self.assertIsInstance(client.connection, Connection) - self.assertIsNone(client.connection.credentials) - self.assertIs(client.connection.http, http) + self.assertIsInstance(client._connection, Connection) + self.assertIsNone(client._connection.credentials) + self.assertIs(client._connection.http, http) self.assertEqual(client.target_language, target) def test_get_languages(self): @@ -63,7 +63,7 @@ def test_get_languages(self): 'languages': supported, }, } - conn = client.connection = _Connection(data) + conn = client._connection = _Connection(data) result = client.get_languages() self.assertEqual(result, supported) @@ -88,7 +88,7 @@ def test_get_languages_no_target(self): 'languages': supported, }, } - conn = client.connection = _Connection(data) + conn = client._connection = _Connection(data) result = client.get_languages() self.assertEqual(result, supported) @@ -113,7 +113,7 @@ def test_get_languages_explicit_target(self): 'languages': supported, }, } - conn = client.connection = _Connection(data) + conn = client._connection = _Connection(data) result = client.get_languages(target_language) self.assertEqual(result, supported) @@ -129,7 +129,7 @@ def test_get_languages_explicit_target(self): def test_detect_language_bad_result(self): client = self._make_one(self.KEY) value = 'takoy' - conn = client.connection = _Connection({}) + conn = client._connection = _Connection({}) with self.assertRaises(ValueError): client.detect_language(value) @@ -159,7 +159,7 @@ def test_detect_language_single_value(self): 'detections': [[detection]], }, } - conn = client.connection = _Connection(data) + conn = client._connection = _Connection(data) result = client.detect_language(value) self.assertEqual(result, detection) @@ -199,7 +199,7 @@ def test_detect_language_multiple_values(self): ], }, } - conn = client.connection = _Connection(data) + conn = client._connection = _Connection(data) result = client.detect_language([value1, value2]) self.assertEqual(result, [detection1, detection2]) @@ -236,7 +236,7 @@ def test_detect_language_multiple_results(self): 'detections': [[detection1, detection2]], }, } - client.connection = _Connection(data) + client._connection = _Connection(data) with self.assertRaises(ValueError): client.detect_language(value) @@ -244,7 +244,7 @@ def test_detect_language_multiple_results(self): def test_translate_bad_result(self): client = self._make_one(self.KEY) value = 'hvala ti' - conn = client.connection = _Connection({}) + conn = client._connection = _Connection({}) with self.assertRaises(ValueError): client.translate(value) @@ -274,7 +274,7 @@ def test_translate_defaults(self): 'translations': [translation], }, } - conn = client.connection = _Connection(data) + conn = client._connection = _Connection(data) result = client.translate(value) self.assertEqual(result, translation) @@ -310,7 +310,7 @@ def test_translate_multiple(self): 'translations': [translation1, translation2], }, } - conn = client.connection = _Connection(data) + conn = client._connection = _Connection(data) result = client.translate([value1, value2]) self.assertEqual(result, [translation1, translation2]) @@ -342,7 +342,7 @@ def test_translate_explicit(self): 'translations': [translation], }, } - conn = client.connection = _Connection(data) + conn = client._connection = _Connection(data) cid = '123' format_ = 'text' diff --git a/vision/google/cloud/vision/client.py b/vision/google/cloud/vision/client.py index 7bdd84b3a8f5..f7d0e3c5cc73 100644 --- a/vision/google/cloud/vision/client.py +++ b/vision/google/cloud/vision/client.py @@ -101,9 +101,8 @@ def annotate(self, image, features): request = VisionRequest(image, features) data = {'requests': [request.as_dict()]} - response = self.connection.api_request(method='POST', - path='/images:annotate', - data=data) + response = self._connection.api_request( + method='POST', path='/images:annotate', data=data) return response['responses'][0] diff --git a/vision/google/cloud/vision/connection.py b/vision/google/cloud/vision/connection.py index f1850d82a44b..0cf38b7b404f 100644 --- a/vision/google/cloud/vision/connection.py +++ b/vision/google/cloud/vision/connection.py @@ -16,10 +16,10 @@ """Create / interact with Google Cloud Vision connections.""" -from google.cloud import connection as base_connection +from google.cloud import _http -class Connection(base_connection.JSONConnection): +class Connection(_http.JSONConnection): """A connection to Google Cloud Vision via the JSON REST API. :type credentials: :class:`oauth2client.client.OAuth2Credentials` diff --git a/vision/unit_tests/test_client.py b/vision/unit_tests/test_client.py index 780aad4a5410..374fc352a1d0 100644 --- a/vision/unit_tests/test_client.py +++ b/vision/unit_tests/test_client.py @@ -61,7 +61,7 @@ def test_face_annotation(self): } credentials = _Credentials() client = self._make_one(project=PROJECT, credentials=credentials) - client.connection = _Connection(RETURNED) + client._connection = _Connection(RETURNED) features = [Feature(feature_type=FeatureTypes.FACE_DETECTION, max_results=3)] @@ -69,7 +69,7 @@ def test_face_annotation(self): response = client.annotate(image, features) self.assertEqual(REQUEST, - client.connection._requested[0]['data']) + client._connection._requested[0]['data']) self.assertTrue('faceAnnotations' in response) def test_image_with_client(self): @@ -87,13 +87,13 @@ def test_face_detection_from_source(self): RETURNED = FACE_DETECTION_RESPONSE credentials = _Credentials() client = self._make_one(project=PROJECT, credentials=credentials) - client.connection = _Connection(RETURNED) + client._connection = _Connection(RETURNED) image = client.image(source_uri=IMAGE_SOURCE) faces = image.detect_faces(limit=3) self.assertEqual(5, len(faces)) self.assertIsInstance(faces[0], Face) - image_request = client.connection._requested[0]['data']['requests'][0] + image_request = client._connection._requested[0]['data']['requests'][0] self.assertEqual(IMAGE_SOURCE, image_request['image']['source']['gcs_image_uri']) self.assertEqual(3, image_request['features'][0]['maxResults']) @@ -104,13 +104,13 @@ def test_face_detection_from_content(self): RETURNED = FACE_DETECTION_RESPONSE credentials = _Credentials() client = self._make_one(project=PROJECT, credentials=credentials) - client.connection = _Connection(RETURNED) + client._connection = _Connection(RETURNED) image = client.image(content=IMAGE_CONTENT) faces = image.detect_faces(limit=5) self.assertEqual(5, len(faces)) self.assertIsInstance(faces[0], Face) - image_request = client.connection._requested[0]['data']['requests'][0] + image_request = client._connection._requested[0]['data']['requests'][0] self.assertEqual(B64_IMAGE_CONTENT, image_request['image']['content']) @@ -123,13 +123,13 @@ def test_label_detection_from_source(self): credentials = _Credentials() client = self._make_one(project=PROJECT, credentials=credentials) - client.connection = _Connection(RETURNED) + client._connection = _Connection(RETURNED) image = client.image(source_uri=IMAGE_SOURCE) labels = image.detect_labels(limit=3) self.assertEqual(3, len(labels)) self.assertIsInstance(labels[0], EntityAnnotation) - image_request = client.connection._requested[0]['data']['requests'][0] + image_request = client._connection._requested[0]['data']['requests'][0] self.assertEqual(IMAGE_SOURCE, image_request['image']['source']['gcs_image_uri']) self.assertEqual(3, image_request['features'][0]['maxResults']) @@ -145,13 +145,13 @@ def test_landmark_detection_from_source(self): credentials = _Credentials() client = self._make_one(project=PROJECT, credentials=credentials) - client.connection = _Connection(RETURNED) + client._connection = _Connection(RETURNED) image = client.image(source_uri=IMAGE_SOURCE) landmarks = image.detect_landmarks(limit=3) self.assertEqual(2, len(landmarks)) self.assertIsInstance(landmarks[0], EntityAnnotation) - image_request = client.connection._requested[0]['data']['requests'][0] + image_request = client._connection._requested[0]['data']['requests'][0] self.assertEqual(IMAGE_SOURCE, image_request['image']['source']['gcs_image_uri']) self.assertEqual(3, image_request['features'][0]['maxResults']) @@ -167,13 +167,13 @@ def test_landmark_detection_from_content(self): credentials = _Credentials() client = self._make_one(project=PROJECT, credentials=credentials) - client.connection = _Connection(RETURNED) + client._connection = _Connection(RETURNED) image = client.image(content=IMAGE_CONTENT) landmarks = image.detect_landmarks(limit=5) self.assertEqual(2, len(landmarks)) self.assertIsInstance(landmarks[0], EntityAnnotation) - image_request = client.connection._requested[0]['data']['requests'][0] + image_request = client._connection._requested[0]['data']['requests'][0] self.assertEqual(B64_IMAGE_CONTENT, image_request['image']['content']) self.assertEqual(5, image_request['features'][0]['maxResults']) @@ -184,13 +184,13 @@ def test_logo_detection_from_source(self): RETURNED = LOGO_DETECTION_RESPONSE credentials = _Credentials() client = self._make_one(project=PROJECT, credentials=credentials) - client.connection = _Connection(RETURNED) + client._connection = _Connection(RETURNED) image = client.image(source_uri=IMAGE_SOURCE) logos = image.detect_logos(limit=3) self.assertEqual(2, len(logos)) self.assertIsInstance(logos[0], EntityAnnotation) - image_request = client.connection._requested[0]['data']['requests'][0] + image_request = client._connection._requested[0]['data']['requests'][0] self.assertEqual(IMAGE_SOURCE, image_request['image']['source']['gcs_image_uri']) self.assertEqual(3, image_request['features'][0]['maxResults']) @@ -201,13 +201,13 @@ def test_logo_detection_from_content(self): RETURNED = LOGO_DETECTION_RESPONSE credentials = _Credentials() client = self._make_one(project=PROJECT, credentials=credentials) - client.connection = _Connection(RETURNED) + client._connection = _Connection(RETURNED) image = client.image(content=IMAGE_CONTENT) logos = image.detect_logos(limit=5) self.assertEqual(2, len(logos)) self.assertIsInstance(logos[0], EntityAnnotation) - image_request = client.connection._requested[0]['data']['requests'][0] + image_request = client._connection._requested[0]['data']['requests'][0] self.assertEqual(B64_IMAGE_CONTENT, image_request['image']['content']) self.assertEqual(5, image_request['features'][0]['maxResults']) @@ -219,13 +219,13 @@ def test_text_detection_from_source(self): credentials = _Credentials() client = self._make_one(project=PROJECT, credentials=credentials) - client.connection = _Connection(RETURNED) + client._connection = _Connection(RETURNED) image = client.image(source_uri=IMAGE_SOURCE) text = image.detect_text(limit=3) self.assertEqual(3, len(text)) self.assertIsInstance(text[0], EntityAnnotation) - image_request = client.connection._requested[0]['data']['requests'][0] + image_request = client._connection._requested[0]['data']['requests'][0] self.assertEqual(IMAGE_SOURCE, image_request['image']['source']['gcs_image_uri']) self.assertEqual(3, image_request['features'][0]['maxResults']) @@ -241,12 +241,12 @@ def test_safe_search_detection_from_source(self): RETURNED = SAFE_SEARCH_DETECTION_RESPONSE credentials = _Credentials() client = self._make_one(project=PROJECT, credentials=credentials) - client.connection = _Connection(RETURNED) + client._connection = _Connection(RETURNED) image = client.image(source_uri=IMAGE_SOURCE) safe_search = image.detect_safe_search()[0] self.assertIsInstance(safe_search, SafeSearchAnnotation) - image_request = client.connection._requested[0]['data']['requests'][0] + image_request = client._connection._requested[0]['data']['requests'][0] self.assertEqual(IMAGE_SOURCE, image_request['image']['source']['gcs_image_uri']) self.assertEqual('VERY_UNLIKELY', safe_search.adult) @@ -261,12 +261,12 @@ def test_image_properties_detection_from_source(self): RETURNED = IMAGE_PROPERTIES_RESPONSE credentials = _Credentials() client = self._make_one(project=PROJECT, credentials=credentials) - client.connection = _Connection(RETURNED) + client._connection = _Connection(RETURNED) image = client.image(source_uri=IMAGE_SOURCE) image_properties = image.detect_properties()[0] self.assertIsInstance(image_properties, ImagePropertiesAnnotation) - image_request = client.connection._requested[0]['data']['requests'][0] + image_request = client._connection._requested[0]['data']['requests'][0] self.assertEqual(IMAGE_SOURCE, image_request['image']['source']['gcs_image_uri']) self.assertEqual(0.42258179, image_properties.colors[0].score)