diff --git a/docs/pubsub-usage.rst b/docs/pubsub-usage.rst index 6ea045e0d393..4ef7355425ec 100644 --- a/docs/pubsub-usage.rst +++ b/docs/pubsub-usage.rst @@ -12,9 +12,9 @@ Authorization / Configuration - The authentication credentials can be implicitly determined from the environment or directly via - :meth:`with_service_account_json ` + :meth:`from_service_account_json ` and - :meth:`with_service_account_p12 `. + :meth:`from_service_account_p12 `. - After setting ``GOOGLE_APPLICATION_CREDENTIALS`` and ``GCLOUD_PROJECT`` environment variables, create a :class:`Client ` @@ -131,7 +131,8 @@ Create a new pull subscription for a topic with a non-default ACK deadline: >>> from gcloud import pubsub >>> client = pubsub.Client() >>> topic = client.topic('topic_name') - >>> subscription = pubsub.Subscription('subscription_name', ack_deadline=90) + >>> subscription = pubsub.Subscription('subscription_name', topic, + ... ack_deadline=90) >>> subscription.create() # API request Create a new push subscription for a topic: @@ -142,7 +143,7 @@ Create a new push subscription for a topic: >>> ENDPOINT = 'https://example.com/hook' >>> client = pubsub.Client() >>> topic = client.topic('topic_name') - >>> subscription = pubsub.Subscription('subscription_name', + >>> subscription = pubsub.Subscription('subscription_name', topic, ... push_endpoint=ENDPOINT) >>> subscription.create() # API request diff --git a/gcloud/pubsub/_testing.py b/gcloud/pubsub/_testing.py deleted file mode 100644 index 26a69ec95a3a..000000000000 --- a/gcloud/pubsub/_testing.py +++ /dev/null @@ -1,33 +0,0 @@ -# Copyright 2014 Google Inc. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Shared pubsub testing utilities.""" - -from gcloud._testing import _Monkey -from gcloud.pubsub import _implicit_environ -from gcloud.pubsub._implicit_environ import _DefaultsContainer - - -def _monkey_defaults(*args, **kwargs): - mock_defaults = _DefaultsContainer(*args, **kwargs) - return _Monkey(_implicit_environ, _DEFAULTS=mock_defaults) - - -def _setup_defaults(test_case, *args, **kwargs): - test_case._replaced_defaults = _implicit_environ._DEFAULTS - _implicit_environ._DEFAULTS = _DefaultsContainer(*args, **kwargs) - - -def _tear_down_defaults(test_case): - _implicit_environ._DEFAULTS = test_case._replaced_defaults diff --git a/gcloud/pubsub/client.py b/gcloud/pubsub/client.py index 526937c16188..cca81da176c6 100644 --- a/gcloud/pubsub/client.py +++ b/gcloud/pubsub/client.py @@ -40,7 +40,9 @@ class Client(object): from the environment. :type http: :class:`httplib2.Http` or class that defines ``request()``. - :param http: An optional HTTP object to make requests. + :param http: An optional HTTP object to make requests. If not passed, an + ``http`` object is created that is bound to the + ``credentials`` for the current object. :raises: :class:`ValueError` if the project is neither passed in nor set in the environment. @@ -58,7 +60,7 @@ def __init__(self, project=None, credentials=None, http=None): self.connection = Connection(credentials=credentials, http=http) @classmethod - def with_service_account_json(cls, json_credentials_path, project=None): + def from_service_account_json(cls, json_credentials_path, project=None): """Factory to retrieve JSON credentials while creating client. :type json_credentials_path: string @@ -81,7 +83,7 @@ def with_service_account_json(cls, json_credentials_path, project=None): return cls(project=project, credentials=credentials) @classmethod - def with_service_account_p12(cls, client_email, private_key_path, + def from_service_account_p12(cls, client_email, private_key_path, project=None): """Factory to retrieve P12 credentials while creating client. diff --git a/gcloud/pubsub/test_client.py b/gcloud/pubsub/test_client.py index f2eb1ad25712..f0f1d30a81be 100644 --- a/gcloud/pubsub/test_client.py +++ b/gcloud/pubsub/test_client.py @@ -82,7 +82,7 @@ def test_ctor_explicit(self): self.assertTrue(client_obj.connection._credentials is CREDS) self.assertEqual(CREDS._scopes, SCOPE) - def test_with_service_account_json(self): + def test_from_service_account_json(self): from gcloud._testing import _Monkey from gcloud.pubsub import client from gcloud.pubsub.connection import Connection @@ -98,7 +98,7 @@ def mock_creds(arg1): BOGUS_ARG = object() with _Monkey(client, get_for_service_account_json=mock_creds): - client_obj = KLASS.with_service_account_json( + client_obj = KLASS.from_service_account_json( BOGUS_ARG, project=PROJECT) self.assertEqual(client_obj.project, PROJECT) @@ -106,7 +106,7 @@ def mock_creds(arg1): self.assertTrue(client_obj.connection._credentials is CREDS) self.assertEqual(_CALLED, [(BOGUS_ARG,)]) - def test_with_service_account_p12(self): + def test_from_service_account_p12(self): from gcloud._testing import _Monkey from gcloud.pubsub import client from gcloud.pubsub.connection import Connection @@ -123,7 +123,7 @@ def mock_creds(arg1, arg2): BOGUS_ARG1 = object() BOGUS_ARG2 = object() with _Monkey(client, get_for_service_account_p12=mock_creds): - client_obj = KLASS.with_service_account_p12( + client_obj = KLASS.from_service_account_p12( BOGUS_ARG1, BOGUS_ARG2, project=PROJECT) self.assertEqual(client_obj.project, PROJECT) @@ -302,7 +302,7 @@ def test_list_subscriptions_with_topic_name(self): % (PROJECT, TOPIC_NAME)) self.assertEqual(req['query_params'], {}) - def test_make_topic(self): + def test_topic(self): PROJECT = 'PROJECT' TOPIC_NAME = 'TOPIC_NAME' CREDS = _Credentials() diff --git a/gcloud/pubsub/test_topic.py b/gcloud/pubsub/test_topic.py index 1f2c77fc150f..4d4942db6a23 100644 --- a/gcloud/pubsub/test_topic.py +++ b/gcloud/pubsub/test_topic.py @@ -24,9 +24,6 @@ def _getTargetClass(self): def _makeOne(self, *args, **kw): return self._getTargetClass()(*args, **kw) - def test_ctor_wo_client(self): - self.assertRaises(ValueError, self._makeOne, 'TOPIC_NAME', client=None) - def test_ctor_w_explicit_timestamp(self): TOPIC_NAME = 'topic_name' PROJECT = 'PROJECT' diff --git a/gcloud/pubsub/topic.py b/gcloud/pubsub/topic.py index 9fe448e44573..9a0af105747d 100644 --- a/gcloud/pubsub/topic.py +++ b/gcloud/pubsub/topic.py @@ -43,10 +43,8 @@ class Topic(object): to the attributes of each published message: the value will be an RFC 3339 timestamp. """ - def __init__(self, name, client=None, timestamp_messages=False): + def __init__(self, name, client, timestamp_messages=False): self.name = name - if client is None: - raise ValueError('Topic constructor requires a client.') self._client = client self.timestamp_messages = timestamp_messages