Skip to content

Commit

Permalink
Addressing review comments in PR #910.
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
dhermes committed Jun 17, 2015
1 parent 29f35d0 commit c206638
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 51 deletions.
9 changes: 5 additions & 4 deletions docs/pubsub-usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ Authorization / Configuration

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

- After setting ``GOOGLE_APPLICATION_CREDENTIALS`` and ``GCLOUD_PROJECT``
environment variables, create a :class:`Client <gcloud.pubsub.client.Client>`
Expand Down Expand Up @@ -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:
Expand All @@ -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

Expand Down
33 changes: 0 additions & 33 deletions gcloud/pubsub/_testing.py

This file was deleted.

8 changes: 5 additions & 3 deletions gcloud/pubsub/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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.
Expand Down
10 changes: 5 additions & 5 deletions gcloud/pubsub/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -98,15 +98,15 @@ 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)
self.assertTrue(isinstance(client_obj.connection, Connection))
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
Expand All @@ -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)
Expand Down Expand Up @@ -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()
Expand Down
3 changes: 0 additions & 3 deletions gcloud/pubsub/test_topic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
4 changes: 1 addition & 3 deletions gcloud/pubsub/topic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit c206638

Please sign in to comment.