Skip to content

Commit

Permalink
Adding the ability to set Subscription path
Browse files Browse the repository at this point in the history
  • Loading branch information
philquinn committed Jun 8, 2015
1 parent 3e86aae commit cd8460a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
11 changes: 10 additions & 1 deletion gcloud/pubsub/subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,16 @@ def from_api_repr(cls, resource, topics=None):
def path(self):
"""URL path for the subscription's APIs"""
project = self.topic.project
return '/projects/%s/subscriptions/%s' % (project, self.name)
if self._path is None:
self._path = '/projects/%s/subscriptions/%s' % (project, self.name)
return self._path


@path.setter
def path(self, project):
"""URL path setter"""
self._path = '/projects/%s/subscriptions/%s' % (project, self.name)


def create(self, connection=None):
"""API call: create the subscription via a PUT request
Expand Down
14 changes: 14 additions & 0 deletions gcloud/pubsub/test_subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,20 @@ def test_delete_w_explicit_connection(self):
self.assertEqual(req['method'], 'DELETE')
self.assertEqual(req['path'], '/%s' % SUB_PATH)

def test_set_path_property(self):
PROJECT = 'PROJECT'
NEW_PROJECT = 'NEW_PROJECT'
SUB_NAME = 'sub_name'
SUB_PATH = '/projects/%s/subscriptions/%s' % (PROJECT, SUB_NAME)
NEW_SUB_PATH = '/projects/%s/subscriptions/%s' % (NEW_PROJECT, SUB_NAME)
TOPIC_NAME = 'topic_name'
conn = _Connection({})
topic = _Topic(TOPIC_NAME, project=PROJECT)
subscription = self._makeOne(SUB_NAME, topic)
self.assertEqual(SUB_PATH ,subscription.path)
subscription.path = NEW_PROJECT
self.assertEqual(NEW_SUB_PATH, subscription.path)


class _Connection(object):

Expand Down

0 comments on commit cd8460a

Please sign in to comment.