Skip to content

Commit 3121e40

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

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

gcloud/pubsub/subscription.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,17 @@ 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+
path = '/projects/%s/subscriptions/%s' % (project, self.name)
79+
if hasattr(self,"_path"):
80+
path = '/projects/%s/subscriptions/%s' % (project, self.name)
81+
return path
82+
83+
84+
@path.setter
85+
def path(self, project):
86+
"""URL path setter"""
87+
self._path = '/projects/%s/subscriptions/%s' % (project, self.name)
88+
7989

8090
def create(self, connection=None):
8191
"""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)