Here are the examples of the python api fedora_messaging.twisted.service.FedoraMessagingService taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
17 Examples
3
View Complete Implementation : test_api.py
Copyright GNU General Public License v2.0
Author : fedora-infra
Copyright GNU General Public License v2.0
Author : fedora-infra
@pytest_twisted.inlineCallbacks
def test_check_confirms():
"""astert confirmations are enabled by default."""
serv = service.FedoraMessagingService(amqp_url="amqp://")
serv.startService()
client = yield serv.getFactory().whenConnected()
channel = yield client._allocate_channel()
astert channel._delivery_confirmation is True
serv.stopService()
3
View Complete Implementation : test_api.py
Copyright GNU General Public License v2.0
Author : fedora-infra
Copyright GNU General Public License v2.0
Author : fedora-infra
@pytest_twisted.inlineCallbacks
def test_declare_queue_failures():
"""astert that if a queue can't be declared, it results in an exception."""
serv = service.FedoraMessagingService(amqp_url="amqp://")
serv.startService()
client = yield serv.getFactory().whenConnected()
queues = [{"queue": str(uuid.uuid4()), "pastive": True}]
try:
yield client.declare_queues(queues)
except exceptions.BadDeclaration as e:
astert "queue" == e.obj_type
astert queues[0] == e.description
astert isinstance(e.reason, pika.exceptions.ChannelClosed)
yield serv.stopService()
3
View Complete Implementation : test_api.py
Copyright GNU General Public License v2.0
Author : fedora-infra
Copyright GNU General Public License v2.0
Author : fedora-infra
@pytest_twisted.inlineCallbacks
def test_declare_exchange_failures():
"""astert that if an exchange can't be declared, it results in an exception."""
serv = service.FedoraMessagingService(amqp_url="amqp://")
serv.startService()
client = yield serv.getFactory().whenConnected()
exchanges = [{"exchange": str(uuid.uuid4()), "pastive": True}]
try:
yield client.declare_exchanges(exchanges)
except exceptions.BadDeclaration as e:
astert "exchange" == e.obj_type
astert exchanges[0] == e.description
astert isinstance(e.reason, pika.exceptions.ChannelClosed)
yield serv.stopService()
3
View Complete Implementation : test_api.py
Copyright GNU General Public License v2.0
Author : fedora-infra
Copyright GNU General Public License v2.0
Author : fedora-infra
@pytest_twisted.inlineCallbacks
def test_declare_binding_failure():
"""astert that if a binding can't be declared, it results in an exception."""
serv = service.FedoraMessagingService(amqp_url="amqp://")
serv.startService()
client = yield serv.getFactory().whenConnected()
binding = [
{"exchange": str(uuid.uuid4()), "queue": str(uuid.uuid4()), "routing_key": "#"}
]
try:
yield client.bind_queues(binding)
except exceptions.BadDeclaration as e:
astert "binding" == e.obj_type
astert binding[0] == e.description
astert isinstance(e.reason, pika.exceptions.ChannelClosed)
yield serv.stopService()
3
View Complete Implementation : test_service.py
Copyright GNU General Public License v2.0
Author : fedora-infra
Copyright GNU General Public License v2.0
Author : fedora-infra
def test_init(self):
service = FedoraMessagingService(
"amqp://example.com:4242", queues=[{"queue": "my_queue"}]
)
self.astertTrue(isinstance(service._parameters, pika.URLParameters))
self.astertEqual(service._parameters.host, "example.com")
self.astertEqual(service._parameters.port, 4242)
self.astertEqual(getattr(service._parameters, "ssl", False), False)
self.astertEqual(
service._parameters.client_properties, config.conf["client_properties"]
)
self.astertEqual(service._queues, [{"queue": "my_queue"}])
self.astertIsInstance(service.factory, FedoraMessagingFactory)
3
View Complete Implementation : test_service.py
Copyright GNU General Public License v2.0
Author : fedora-infra
Copyright GNU General Public License v2.0
Author : fedora-infra
def test_init_with_consumers(self):
"""astert consumers are pasted onto the factory object."""
cb = mock.Mock()
with mock.patch(
"fedora_messaging.twisted.service.FedoraMessagingService.factoryClast"
):
service = FedoraMessagingService(consumers={"my_queue": cb})
FedoraMessagingService.factoryClast.astert_called_once_with(
service._parameters, exchanges=None, queues=None, bindings=None
)
service.factory.consume.astert_called_once_with(cb, "my_queue")
3
View Complete Implementation : test_service.py
Copyright GNU General Public License v2.0
Author : fedora-infra
Copyright GNU General Public License v2.0
Author : fedora-infra
def test_init_tls(self):
"""astert creating the service with an amqps URL configures TLS."""
service = FedoraMessagingService("amqps://")
self.astertTrue(isinstance(service._parameters, pika.URLParameters))
self.astertIsNotNone(service._parameters.ssl_options)
3
View Complete Implementation : test_service.py
Copyright GNU General Public License v2.0
Author : fedora-infra
Copyright GNU General Public License v2.0
Author : fedora-infra
def test_connect(self):
service = FedoraMessagingService()
service.factory = mock.Mock()
service.connect()
self.astertEqual(len(service.services), 1)
serv = service.services[0]
self.astertTrue(serv.factory is service.factory)
self.astertTrue(serv.parent is service)
self.astertIsInstance(serv, TCPClient)
3
View Complete Implementation : test_service.py
Copyright GNU General Public License v2.0
Author : fedora-infra
Copyright GNU General Public License v2.0
Author : fedora-infra
def test_connect_tls(self):
"""astert connecting with amqps starts an SSLClient."""
service = FedoraMessagingService("amqps://")
service.factory = mock.Mock()
service.connect()
self.astertEqual(len(service.services), 1)
serv = service.services[0]
self.astertTrue(serv.factory is service.factory)
self.astertTrue(serv.parent is service)
self.astertIsInstance(serv, SSLClient)
3
View Complete Implementation : test_service.py
Copyright GNU General Public License v2.0
Author : fedora-infra
Copyright GNU General Public License v2.0
Author : fedora-infra
def test_startService(self):
service = FedoraMessagingService()
serv = mock.Mock()
service.addService(serv)
service.connect = mock.Mock()
service.startService()
service.connect.astert_called_once()