mirror of https://github.com/celery/kombu.git
Unittests for kombu.connection
This commit is contained in:
parent
9a4074b568
commit
87913821bb
|
@ -12,6 +12,7 @@ from itertools import count
|
|||
|
||||
from amqplib import client_0_8 as amqp
|
||||
from amqplib.client_0_8.exceptions import AMQPChannelException
|
||||
from amqplib.client_0_8.channel import Channel
|
||||
|
||||
from kombu.backends.base import BaseMessage, BaseBackend
|
||||
|
||||
|
@ -148,7 +149,7 @@ class Message(BaseMessage):
|
|||
super(Message, self).__init__(backend, **kwargs)
|
||||
|
||||
|
||||
class Channel(amqp.Channel):
|
||||
class Channel(Channel):
|
||||
Message = Message
|
||||
|
||||
def prepare_message(self, message_data, priority=None,
|
||||
|
|
|
@ -2,6 +2,7 @@ from kombu.backends import get_backend_cls
|
|||
|
||||
|
||||
class BrokerConnection(object):
|
||||
port = None
|
||||
|
||||
def __init__(self, hostname="localhost", userid="guest",
|
||||
password="guest", virtual_host="/", port=None, **kwargs):
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
import unittest2 as unittest
|
||||
|
||||
from kombu.backends.base import BaseBackend
|
||||
from kombu.connection import BrokerConnection
|
||||
|
||||
|
||||
class Channel(object):
|
||||
open = True
|
||||
|
||||
|
||||
class Connection(object):
|
||||
connected = True
|
||||
|
||||
def channel(self):
|
||||
return Channel()
|
||||
|
||||
|
||||
class Backend(BaseBackend):
|
||||
|
||||
def establish_connection(self):
|
||||
return Connection()
|
||||
|
||||
def create_channel(self, connection):
|
||||
return connection.channel()
|
||||
|
||||
def drain_events(self, connection, **kwargs):
|
||||
return "event"
|
||||
|
||||
def close_connection(self, connection):
|
||||
connection.connected = False
|
||||
|
||||
|
||||
class test_Connection(unittest.TestCase):
|
||||
|
||||
def test_establish_connection(self):
|
||||
conn = BrokerConnection(port=5672, backend_cls=Backend)
|
||||
conn.connect()
|
||||
self.assertTrue(conn.connection.connected)
|
||||
self.assertEqual(conn.host, "localhost:5672")
|
||||
channel = conn.channel()
|
||||
self.assertTrue(channel.open)
|
||||
self.assertEqual(conn.drain_events(), "event")
|
||||
_connection = conn.connection
|
||||
conn.close()
|
||||
self.assertFalse(_connection.connected)
|
||||
self.assertIsInstance(conn.backend, Backend)
|
Loading…
Reference in New Issue