Exemplo n.º 1
0
    def test_create_subscription(self):
        pubsub = Mock()
        pubsub.topic.return_value = Mock()
        q = BroadcastQueue(pubsub)

        sub = Mock()
        sub.exists.return_value = False

        # Test to make sure it creates a unique (non-shared) subscription.
        with patch('gcloud.pubsub.Subscription') as SubscriptionMock:
            SubscriptionMock.return_value = sub
            rsub = q._get_or_create_subscription()

            assert rsub == sub
            assert 'worker' in SubscriptionMock.call_args[0][0]
            assert 'broadcast' in SubscriptionMock.call_args[0][0]
            assert sub.exists.called
            assert sub.create.called

        # Test reusing existing
        with patch('gcloud.pubsub.Subscription') as SubscriptionMock:
            sub.reset_mock()
            SubscriptionMock.return_value = sub
            sub.exists.return_value = True
            rsub = q._get_or_create_subscription()

            assert rsub == sub
            assert not sub.create.called
Exemplo n.º 2
0
    def test_create_subscription(self):
        pubsub = Mock()
        pubsub.topic.return_value = Mock()
        q = BroadcastQueue(pubsub)

        sub = Mock()
        sub.exists.return_value = False

        # Test to make sure it creates a unique (non-shared) subscription.
        with patch('gcloud.pubsub.Subscription') as SubscriptionMock:
            SubscriptionMock.return_value = sub
            rsub = q._get_or_create_subscription()

            assert rsub == sub
            assert 'worker' in SubscriptionMock.call_args[0][0]
            assert 'broadcast' in SubscriptionMock.call_args[0][0]
            assert sub.exists.called
            assert sub.create.called

        # Test reusing existing
        with patch('gcloud.pubsub.Subscription') as SubscriptionMock:
            sub.reset_mock()
            SubscriptionMock.return_value = sub
            sub.exists.return_value = True
            rsub = q._get_or_create_subscription()

            assert rsub == sub
            assert not sub.create.called
Exemplo n.º 3
0
    def test_cleanup(self):
        # Broadcast queue should delete its own subscription, as it's not
        # shared.
        pubsub = Mock()
        pubsub.topic.return_value = Mock()
        q = BroadcastQueue(pubsub)
        q.subscription = Mock()
        q.cleanup()
        assert q.subscription.delete.called

        # test without subscription
        q.subscription = None
        q.cleanup()
Exemplo n.º 4
0
    def test_cleanup(self):
        # Broadcast queue should delete its own subscription, as it's not
        # shared.
        pubsub = Mock()
        pubsub.topic.return_value = Mock()
        q = BroadcastQueue(pubsub)
        q.subscription = Mock()
        q.cleanup()
        assert q.subscription.delete.called

        # test without subscription
        q.subscription = None
        q.cleanup()