1919from gcloud import _helpers
2020from gcloud import pubsub
2121from gcloud .pubsub .subscription import Subscription
22- from gcloud .pubsub .topic import Topic
2322
2423
2524_helpers ._PROJECT_ENV_VAR_NAME = 'GCLOUD_TESTS_PROJECT_ID'
26- pubsub .set_defaults ()
25+ CLIENT = pubsub .Client ()
2726
2827
2928class TestPubsub (unittest2 .TestCase ):
@@ -37,7 +36,7 @@ def tearDown(self):
3736
3837 def test_create_topic (self ):
3938 TOPIC_NAME = 'a-new-topic'
40- topic = Topic (TOPIC_NAME )
39+ topic = CLIENT . topic (TOPIC_NAME )
4140 self .assertFalse (topic .exists ())
4241 topic .create ()
4342 self .to_delete .append (topic )
@@ -51,21 +50,20 @@ def test_list_topics(self):
5150 'newest%d' % (1000 * time .time (),),
5251 ]
5352 for topic_name in topics_to_create :
54- topic = Topic (topic_name )
53+ topic = CLIENT . topic (topic_name )
5554 topic .create ()
5655 self .to_delete .append (topic )
5756
5857 # Retrieve the topics.
59- all_topics , _ = pubsub .list_topics ()
60- project = pubsub .get_default_project ()
58+ all_topics , _ = CLIENT .list_topics ()
6159 created = [topic for topic in all_topics
6260 if topic .name in topics_to_create and
63- topic .project == project ]
61+ topic .project == CLIENT . project ]
6462 self .assertEqual (len (created ), len (topics_to_create ))
6563
6664 def test_create_subscription (self ):
6765 TOPIC_NAME = 'subscribe-me'
68- topic = Topic (TOPIC_NAME )
66+ topic = CLIENT . topic (TOPIC_NAME )
6967 self .assertFalse (topic .exists ())
7068 topic .create ()
7169 self .to_delete .append (topic )
@@ -80,7 +78,7 @@ def test_create_subscription(self):
8078
8179 def test_list_subscriptions (self ):
8280 TOPIC_NAME = 'subscribe-me'
83- topic = Topic (TOPIC_NAME )
81+ topic = CLIENT . topic (TOPIC_NAME )
8482 self .assertFalse (topic .exists ())
8583 topic .create ()
8684 self .to_delete .append (topic )
@@ -95,15 +93,15 @@ def test_list_subscriptions(self):
9593 self .to_delete .append (subscription )
9694
9795 # Retrieve the subscriptions.
98- all_subscriptions , _ = pubsub .list_subscriptions ()
96+ all_subscriptions , _ = CLIENT .list_subscriptions ()
9997 created = [subscription for subscription in all_subscriptions
10098 if subscription .name in subscriptions_to_create and
10199 subscription .topic .name == TOPIC_NAME ]
102100 self .assertEqual (len (created ), len (subscriptions_to_create ))
103101
104102 def test_message_pull_mode_e2e (self ):
105103 TOPIC_NAME = 'subscribe-me'
106- topic = Topic (TOPIC_NAME , timestamp_messages = True )
104+ topic = CLIENT . topic (TOPIC_NAME , timestamp_messages = True )
107105 self .assertFalse (topic .exists ())
108106 topic .create ()
109107 self .to_delete .append (topic )
0 commit comments