Esempio n. 1
0
    def test_create_broadcast_cursor(self):
        import pymongo

        with patch.object(pymongo, 'version_tuple', (2, )):
            self.channel._create_broadcast_cursor(
                'fanout_exchange', 'foo', '*', 'foobar',
            )

            self.assert_collection_accessed('messages.broadcast')
            self.assert_operation_called_with(
                'broadcast', 'find',
                tailable=True,
                query={'queue': 'fanout_exchange'},
                sort=[('$natural', pymongo.ASCENDING)],
            )

        if pymongo.version_tuple >= (3, ):
            self.channel._create_broadcast_cursor(
                'fanout_exchange1', 'foo', '*', 'foobar',
            )

            self.assert_collection_accessed('messages.broadcast')
            self.assert_operation_called_with(
                'broadcast', 'find',
                cursor_type=pymongo.CursorType.TAILABLE,
                filter={'queue': 'fanout_exchange1'},
                sort=[('$natural', pymongo.ASCENDING)],
            )
Esempio n. 2
0
    def test_create_broadcast_cursor(self):
        import pymongo

        with patch.object(pymongo, 'version_tuple', (2, )):
            self.channel._create_broadcast_cursor(
                'fanout_exchange', 'foo', '*', 'foobar',
            )

            self.assert_collection_accessed('messages.broadcast')
            self.assert_operation_called_with(
                'broadcast', 'find',
                tailable=True,
                query={'queue': 'fanout_exchange'},
                sort=[('$natural', pymongo.ASCENDING)],
            )

        if pymongo.version_tuple >= (3, ):
            self.channel._create_broadcast_cursor(
                'fanout_exchange1', 'foo', '*', 'foobar',
            )

            self.assert_collection_accessed('messages.broadcast')
            self.assert_operation_called_with(
                'broadcast', 'find',
                cursor_type=pymongo.CursorType.TAILABLE,
                filter={'queue': 'fanout_exchange1'},
                sort=[('$natural', pymongo.ASCENDING)],
            )
Esempio n. 3
0
    def test_method_called(self):
        from kombu.transport.redis import SentinelChannel

        with patch.object(SentinelChannel, '_sentinel_managed_pool') as patched:
            connection = Connection('sentinel://localhost:65534/', transport_options={
                'master_name': 'not_important'
            })

            connection.channel()
            self.assertTrue(patched.called)
Esempio n. 4
0
    def test_getting_master_from_sentinel(self):
        from redis.sentinel import Sentinel

        with patch.object(Sentinel, '__new__') as patched:
            connection = Connection('sentinel://localhost:65534/', transport_options={
                'master_name': 'not_important'
            })

            connection.channel()
            self.assertTrue(patched)

            sentinel_obj = patched.return_value
            self.assertTrue(sentinel_obj.master_for.called, 'master_for was not called')
            sentinel_obj.master_for.assert_called_with('not_important', ANY)
            self.assertTrue(sentinel_obj.master_for().connection_pool.get_connection.called, 'get_connection on redis connection pool was not called')