diff --git a/gcloud/pubsub/subscription.py b/gcloud/pubsub/subscription.py index 51154f5bb239c..bc169eea53b4e 100644 --- a/gcloud/pubsub/subscription.py +++ b/gcloud/pubsub/subscription.py @@ -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 diff --git a/gcloud/pubsub/test_subscription.py b/gcloud/pubsub/test_subscription.py index 45d2a97ead348..4878c1c281b4a 100644 --- a/gcloud/pubsub/test_subscription.py +++ b/gcloud/pubsub/test_subscription.py @@ -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):