Skip to content

Commit 3252115

Browse files
committed
Add regression test for pubsub.api.list_topics.
1 parent 69c5537 commit 3252115

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

gcloud/pubsub/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from gcloud.connection import get_scoped_connection
3030
from gcloud.pubsub import _implicit_environ
3131
from gcloud.pubsub._implicit_environ import get_default_connection
32+
from gcloud.pubsub.api import list_topics
3233
from gcloud.pubsub.connection import Connection
3334

3435

regression/pubsub.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import time
16+
1517
import unittest2
1618

1719
from gcloud import _helpers
@@ -40,3 +42,23 @@ def test_create_topic(self):
4042
self.to_delete.append(topic)
4143
self.assertTrue(topic.exists())
4244
self.assertEqual(topic.name, new_topic_name)
45+
46+
def test_list_topics(self):
47+
topics_to_create = [
48+
'new%d' % (1000 * time.time(),),
49+
'newer%d' % (1000 * time.time(),),
50+
'newest%d' % (1000 * time.time(),),
51+
]
52+
created_topics = []
53+
for topic_name in topics_to_create:
54+
topic = Topic(topic_name)
55+
topic.create()
56+
self.to_delete.append(topic)
57+
58+
# Retrieve the topics.
59+
all_topics, _ = pubsub.list_topics()
60+
project_id = pubsub.get_default_project()
61+
created_topics = [topic for topic in all_topics
62+
if topic.name in topics_to_create and
63+
topic.project == project_id]
64+
self.assertEqual(len(created_topics), len(topics_to_create))

0 commit comments

Comments
 (0)