Skip to content

Commit cd8460a

Browse files
committed
Adding the ability to set Subscription path
1 parent 3e86aae commit cd8460a

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

gcloud/pubsub/subscription.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,16 @@ def from_api_repr(cls, resource, topics=None):
7575
def path(self):
7676
"""URL path for the subscription's APIs"""
7777
project = self.topic.project
78-
return '/projects/%s/subscriptions/%s' % (project, self.name)
78+
if self._path is None:
79+
self._path = '/projects/%s/subscriptions/%s' % (project, self.name)
80+
return self._path
81+
82+
83+
@path.setter
84+
def path(self, project):
85+
"""URL path setter"""
86+
self._path = '/projects/%s/subscriptions/%s' % (project, self.name)
87+
7988

8089
def create(self, connection=None):
8190
"""API call: create the subscription via a PUT request

gcloud/pubsub/test_subscription.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,20 @@ def test_delete_w_explicit_connection(self):
456456
self.assertEqual(req['method'], 'DELETE')
457457
self.assertEqual(req['path'], '/%s' % SUB_PATH)
458458

459+
def test_set_path_property(self):
460+
PROJECT = 'PROJECT'
461+
NEW_PROJECT = 'NEW_PROJECT'
462+
SUB_NAME = 'sub_name'
463+
SUB_PATH = '/projects/%s/subscriptions/%s' % (PROJECT, SUB_NAME)
464+
NEW_SUB_PATH = '/projects/%s/subscriptions/%s' % (NEW_PROJECT, SUB_NAME)
465+
TOPIC_NAME = 'topic_name'
466+
conn = _Connection({})
467+
topic = _Topic(TOPIC_NAME, project=PROJECT)
468+
subscription = self._makeOne(SUB_NAME, topic)
469+
self.assertEqual(SUB_PATH ,subscription.path)
470+
subscription.path = NEW_PROJECT
471+
self.assertEqual(NEW_SUB_PATH, subscription.path)
472+
459473

460474
class _Connection(object):
461475

0 commit comments

Comments
 (0)