Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion gcloud/pubsub/subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def __init__(self, name, topic, ack_deadline=None, push_endpoint=None):
self.topic = topic
self.ack_deadline = ack_deadline
self.push_endpoint = push_endpoint
self._path = None

@classmethod
def from_api_repr(cls, resource, topics=None):
Expand Down Expand Up @@ -75,7 +76,15 @@ 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)
path = '/projects/%s/subscriptions/%s' % (project, self.name)
if self._path is not None:
path = self._path
return 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
13 changes: 13 additions & 0 deletions gcloud/pubsub/test_subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,19 @@ 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'
PROJECT2 = 'PROJECT2'
SUB_NAME = 'sub_name'
SUB_PATH = '/projects/%s/subscriptions/%s' % (PROJECT, SUB_NAME)
SUB_PATH2 = '/projects/%s/subscriptions/%s' % (PROJECT2, SUB_NAME)
TOPIC_NAME = 'topic_name'
topic = _Topic(TOPIC_NAME, project=PROJECT)
subscription = self._makeOne(SUB_NAME, topic)
self.assertEqual(SUB_PATH, subscription.path)
subscription.path = PROJECT2
self.assertEqual(SUB_PATH2, subscription.path)


class _Connection(object):

Expand Down