2121from gcloud import pubsub
2222
2323
24+ DEFAULT_TOPIC_NAME = 'subscribe-me%d' % (1000 * time .time (),)
25+
26+
2427class Config (object ):
2528 """Run-time configuration to be modified at set-up.
2629
@@ -45,13 +48,13 @@ def tearDown(self):
4548 doomed .delete ()
4649
4750 def test_create_topic (self ):
48- TOPIC_NAME = 'a-new-topic'
49- topic = Config .CLIENT .topic (TOPIC_NAME )
51+ topic_name = 'a-new-topic%d' % ( 1000 * time . time (),)
52+ topic = Config .CLIENT .topic (topic_name )
5053 self .assertFalse (topic .exists ())
5154 topic .create ()
5255 self .to_delete .append (topic )
5356 self .assertTrue (topic .exists ())
54- self .assertEqual (topic .name , TOPIC_NAME )
57+ self .assertEqual (topic .name , topic_name )
5558
5659 def test_list_topics (self ):
5760 topics_to_create = [
@@ -72,8 +75,7 @@ def test_list_topics(self):
7275 self .assertEqual (len (created ), len (topics_to_create ))
7376
7477 def test_create_subscription_defaults (self ):
75- TOPIC_NAME = 'subscribe-me'
76- topic = Config .CLIENT .topic (TOPIC_NAME )
78+ topic = Config .CLIENT .topic (DEFAULT_TOPIC_NAME )
7779 self .assertFalse (topic .exists ())
7880 topic .create ()
7981 self .to_delete .append (topic )
@@ -87,8 +89,7 @@ def test_create_subscription_defaults(self):
8789 self .assertTrue (subscription .topic is topic )
8890
8991 def test_create_subscription_w_ack_deadline (self ):
90- TOPIC_NAME = 'subscribe-me'
91- topic = Config .CLIENT .topic (TOPIC_NAME )
92+ topic = Config .CLIENT .topic (DEFAULT_TOPIC_NAME )
9293 self .assertFalse (topic .exists ())
9394 topic .create ()
9495 self .to_delete .append (topic )
@@ -103,8 +104,7 @@ def test_create_subscription_w_ack_deadline(self):
103104 self .assertTrue (subscription .topic is topic )
104105
105106 def test_list_subscriptions (self ):
106- TOPIC_NAME = 'subscribe-me'
107- topic = Config .CLIENT .topic (TOPIC_NAME )
107+ topic = Config .CLIENT .topic (DEFAULT_TOPIC_NAME )
108108 self .assertFalse (topic .exists ())
109109 topic .create ()
110110 self .to_delete .append (topic )
@@ -122,12 +122,12 @@ def test_list_subscriptions(self):
122122 all_subscriptions , _ = Config .CLIENT .list_subscriptions ()
123123 created = [subscription for subscription in all_subscriptions
124124 if subscription .name in subscriptions_to_create and
125- subscription .topic .name == TOPIC_NAME ]
125+ subscription .topic .name == DEFAULT_TOPIC_NAME ]
126126 self .assertEqual (len (created ), len (subscriptions_to_create ))
127127
128128 def test_message_pull_mode_e2e (self ):
129- TOPIC_NAME = 'subscribe-me'
130- topic = Config . CLIENT . topic ( TOPIC_NAME , timestamp_messages = True )
129+ topic = Config . CLIENT . topic ( DEFAULT_TOPIC_NAME ,
130+ timestamp_messages = True )
131131 self .assertFalse (topic .exists ())
132132 topic .create ()
133133 self .to_delete .append (topic )
0 commit comments