Skip to content

Commit c206638

Browse files
committed
Addressing review comments in PR #910.
In particular: - Renaming `with_service_...` methods to `from_service_...` on `pubsub.Client`. - Updating docstring for `http` on `pubsub.Client` to describe the default behavior when no value is passed. - Making `client` a required / positional argument in `pubsub.Topic` (and ditching a test in the process). - Renaming `test_make_topic` as `test_topic`.
1 parent 29f35d0 commit c206638

File tree

6 files changed

+16
-51
lines changed

6 files changed

+16
-51
lines changed

docs/pubsub-usage.rst

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ Authorization / Configuration
1212

1313
- The authentication credentials can be implicitly determined from the
1414
environment or directly via
15-
:meth:`with_service_account_json <gcloud.pubsub.client.Client.with_service_account_json>`
15+
:meth:`from_service_account_json <gcloud.pubsub.client.Client.from_service_account_json>`
1616
and
17-
:meth:`with_service_account_p12 <gcloud.pubsub.client.Client.with_service_account_p12>`.
17+
:meth:`from_service_account_p12 <gcloud.pubsub.client.Client.from_service_account_p12>`.
1818

1919
- After setting ``GOOGLE_APPLICATION_CREDENTIALS`` and ``GCLOUD_PROJECT``
2020
environment variables, create a :class:`Client <gcloud.pubsub.client.Client>`
@@ -131,7 +131,8 @@ Create a new pull subscription for a topic with a non-default ACK deadline:
131131
>>> from gcloud import pubsub
132132
>>> client = pubsub.Client()
133133
>>> topic = client.topic('topic_name')
134-
>>> subscription = pubsub.Subscription('subscription_name', ack_deadline=90)
134+
>>> subscription = pubsub.Subscription('subscription_name', topic,
135+
... ack_deadline=90)
135136
>>> subscription.create() # API request
136137

137138
Create a new push subscription for a topic:
@@ -142,7 +143,7 @@ Create a new push subscription for a topic:
142143
>>> ENDPOINT = 'https://example.com/hook'
143144
>>> client = pubsub.Client()
144145
>>> topic = client.topic('topic_name')
145-
>>> subscription = pubsub.Subscription('subscription_name',
146+
>>> subscription = pubsub.Subscription('subscription_name', topic,
146147
... push_endpoint=ENDPOINT)
147148
>>> subscription.create() # API request
148149

gcloud/pubsub/_testing.py

Lines changed: 0 additions & 33 deletions
This file was deleted.

gcloud/pubsub/client.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ class Client(object):
4040
from the environment.
4141
4242
:type http: :class:`httplib2.Http` or class that defines ``request()``.
43-
:param http: An optional HTTP object to make requests.
43+
:param http: An optional HTTP object to make requests. If not passed, an
44+
``http`` object is created that is bound to the
45+
``credentials`` for the current object.
4446
4547
:raises: :class:`ValueError` if the project is neither passed in nor
4648
set in the environment.
@@ -58,7 +60,7 @@ def __init__(self, project=None, credentials=None, http=None):
5860
self.connection = Connection(credentials=credentials, http=http)
5961

6062
@classmethod
61-
def with_service_account_json(cls, json_credentials_path, project=None):
63+
def from_service_account_json(cls, json_credentials_path, project=None):
6264
"""Factory to retrieve JSON credentials while creating client.
6365
6466
:type json_credentials_path: string
@@ -81,7 +83,7 @@ def with_service_account_json(cls, json_credentials_path, project=None):
8183
return cls(project=project, credentials=credentials)
8284

8385
@classmethod
84-
def with_service_account_p12(cls, client_email, private_key_path,
86+
def from_service_account_p12(cls, client_email, private_key_path,
8587
project=None):
8688
"""Factory to retrieve P12 credentials while creating client.
8789

gcloud/pubsub/test_client.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def test_ctor_explicit(self):
8282
self.assertTrue(client_obj.connection._credentials is CREDS)
8383
self.assertEqual(CREDS._scopes, SCOPE)
8484

85-
def test_with_service_account_json(self):
85+
def test_from_service_account_json(self):
8686
from gcloud._testing import _Monkey
8787
from gcloud.pubsub import client
8888
from gcloud.pubsub.connection import Connection
@@ -98,15 +98,15 @@ def mock_creds(arg1):
9898

9999
BOGUS_ARG = object()
100100
with _Monkey(client, get_for_service_account_json=mock_creds):
101-
client_obj = KLASS.with_service_account_json(
101+
client_obj = KLASS.from_service_account_json(
102102
BOGUS_ARG, project=PROJECT)
103103

104104
self.assertEqual(client_obj.project, PROJECT)
105105
self.assertTrue(isinstance(client_obj.connection, Connection))
106106
self.assertTrue(client_obj.connection._credentials is CREDS)
107107
self.assertEqual(_CALLED, [(BOGUS_ARG,)])
108108

109-
def test_with_service_account_p12(self):
109+
def test_from_service_account_p12(self):
110110
from gcloud._testing import _Monkey
111111
from gcloud.pubsub import client
112112
from gcloud.pubsub.connection import Connection
@@ -123,7 +123,7 @@ def mock_creds(arg1, arg2):
123123
BOGUS_ARG1 = object()
124124
BOGUS_ARG2 = object()
125125
with _Monkey(client, get_for_service_account_p12=mock_creds):
126-
client_obj = KLASS.with_service_account_p12(
126+
client_obj = KLASS.from_service_account_p12(
127127
BOGUS_ARG1, BOGUS_ARG2, project=PROJECT)
128128

129129
self.assertEqual(client_obj.project, PROJECT)
@@ -302,7 +302,7 @@ def test_list_subscriptions_with_topic_name(self):
302302
% (PROJECT, TOPIC_NAME))
303303
self.assertEqual(req['query_params'], {})
304304

305-
def test_make_topic(self):
305+
def test_topic(self):
306306
PROJECT = 'PROJECT'
307307
TOPIC_NAME = 'TOPIC_NAME'
308308
CREDS = _Credentials()

gcloud/pubsub/test_topic.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ def _getTargetClass(self):
2424
def _makeOne(self, *args, **kw):
2525
return self._getTargetClass()(*args, **kw)
2626

27-
def test_ctor_wo_client(self):
28-
self.assertRaises(ValueError, self._makeOne, 'TOPIC_NAME', client=None)
29-
3027
def test_ctor_w_explicit_timestamp(self):
3128
TOPIC_NAME = 'topic_name'
3229
PROJECT = 'PROJECT'

gcloud/pubsub/topic.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,8 @@ class Topic(object):
4343
to the attributes of each published message:
4444
the value will be an RFC 3339 timestamp.
4545
"""
46-
def __init__(self, name, client=None, timestamp_messages=False):
46+
def __init__(self, name, client, timestamp_messages=False):
4747
self.name = name
48-
if client is None:
49-
raise ValueError('Topic constructor requires a client.')
5048
self._client = client
5149
self.timestamp_messages = timestamp_messages
5250

0 commit comments

Comments
 (0)