| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -29,6 +29,7 @@ | |||
| 29 | 29 | from gcloud.connection import get_scoped_connection | |
| 30 | 30 | from gcloud.pubsub import _implicit_environ | |
| 31 | 31 | from gcloud.pubsub._implicit_environ import get_default_connection | |
| 32 | + from gcloud.pubsub.api import list_subscriptions | ||
| 32 | 33 | from gcloud.pubsub.api import list_topics | |
| 33 | 34 | from gcloud.pubsub.connection import Connection | |
| 34 | 35 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -18,14 +18,15 @@ | |||
| 18 | 18 | ||
| 19 | 19 | from gcloud import _helpers | |
| 20 | 20 | from gcloud import pubsub | |
| 21 | + from gcloud.pubsub.subscription import Subscription | ||
| 21 | 22 | from gcloud.pubsub.topic import Topic | |
| 22 | 23 | ||
| 23 | 24 | ||
| 24 | 25 | _helpers._PROJECT_ENV_VAR_NAME = 'GCLOUD_TESTS_PROJECT_ID' | |
| 25 | 26 | pubsub.set_defaults() | |
| 26 | 27 | ||
| 27 | 28 | ||
| 28 | - class TestPubsubTopics(unittest2.TestCase): | ||
| 29 | + class TestPubsub(unittest2.TestCase): | ||
| 29 | 30 | ||
| 30 | 31 | def setUp(self): | |
| 31 | 32 | self.to_delete = [] | |
@@ -35,21 +36,20 @@ def tearDown(self): | |||
| 35 | 36 | doomed.delete() | |
| 36 | 37 | ||
| 37 | 38 | def test_create_topic(self): | |
| 38 | - new_topic_name = 'a-new-topic' | ||
| 39 | - topic = Topic(new_topic_name) | ||
| 39 | + TOPIC_NAME = 'a-new-topic' | ||
| 40 | + topic = Topic(TOPIC_NAME) | ||
| 40 | 41 | self.assertFalse(topic.exists()) | |
| 41 | 42 | topic.create() | |
| 42 | 43 | self.to_delete.append(topic) | |
| 43 | 44 | self.assertTrue(topic.exists()) | |
| 44 | - self.assertEqual(topic.name, new_topic_name) | ||
| 45 | + self.assertEqual(topic.name, TOPIC_NAME) | ||
| 45 | 46 | ||
| 46 | 47 | def test_list_topics(self): | |
| 47 | 48 | topics_to_create = [ | |
| 48 | 49 | 'new%d' % (1000 * time.time(),), | |
| 49 | 50 | 'newer%d' % (1000 * time.time(),), | |
| 50 | 51 | 'newest%d' % (1000 * time.time(),), | |
| 51 | 52 | ] | |
| 52 | - created_topics = [] | ||
| 53 | 53 | for topic_name in topics_to_create: | |
| 54 | 54 | topic = Topic(topic_name) | |
| 55 | 55 | topic.create() | |
@@ -58,7 +58,45 @@ def test_list_topics(self): | |||
| 58 | 58 | # Retrieve the topics. | |
| 59 | 59 | all_topics, _ = pubsub.list_topics() | |
| 60 | 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)) | ||
| 61 | + created = [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), len(topics_to_create)) | ||
| 65 | + | ||
| 66 | + def test_create_subscription(self): | ||
| 67 | + TOPIC_NAME = 'subscribe-me' | ||
| 68 | + topic = Topic(TOPIC_NAME) | ||
| 69 | + self.assertFalse(topic.exists()) | ||
| 70 | + topic.create() | ||
| 71 | + self.to_delete.append(topic) | ||
| 72 | + SUBSCRIPTION_NAME = 'subscribing-now' | ||
| 73 | + subscription = Subscription(SUBSCRIPTION_NAME, topic) | ||
| 74 | + self.assertFalse(subscription.exists()) | ||
| 75 | + subscription.create() | ||
| 76 | + self.to_delete.append(subscription) | ||
| 77 | + self.assertTrue(subscription.exists()) | ||
| 78 | + self.assertEqual(subscription.name, SUBSCRIPTION_NAME) | ||
| 79 | + self.assertTrue(subscription.topic is topic) | ||
| 80 | + | ||
| 81 | + def test_list_subscriptions(self): | ||
| 82 | + TOPIC_NAME = 'subscribe-me' | ||
| 83 | + topic = Topic(TOPIC_NAME) | ||
| 84 | + self.assertFalse(topic.exists()) | ||
| 85 | + topic.create() | ||
| 86 | + self.to_delete.append(topic) | ||
| 87 | + subscriptions_to_create = [ | ||
| 88 | + 'new%d' % (1000 * time.time(),), | ||
| 89 | + 'newer%d' % (1000 * time.time(),), | ||
| 90 | + 'newest%d' % (1000 * time.time(),), | ||
| 91 | + ] | ||
| 92 | + for subscription_name in subscriptions_to_create: | ||
| 93 | + subscription = Subscription(subscription_name, topic) | ||
| 94 | + subscription.create() | ||
| 95 | + self.to_delete.append(subscription) | ||
| 96 | + | ||
| 97 | + # Retrieve the subscriptions. | ||
| 98 | + all_subscriptions, _ = pubsub.list_subscriptions() | ||
| 99 | + created = [subscription for subscription in all_subscriptions | ||
| 100 | + if subscription.name in subscriptions_to_create and | ||
| 101 | + subscription.topic.name == TOPIC_NAME] | ||
| 102 | + self.assertEqual(len(created), len(subscriptions_to_create)) | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments