Beispiel #1
0
 def test_publish_generic_error(self):
     # Check that the correct exception is raised when the publication has
     # failed for an unknown reason, and that the connection state is reset.
     self.publisher._connection.is_open = False
     self.publisher_channel_publish.side_effect = pika_errs.AMQPError()
     self.assertRaises(ConnectionException, self.publisher.publish, self.message)
     self.assertEqual(self.publisher._connection, None)
     self.assertEqual(self.publisher._channel, None)
 def test_publish_generic_error(self):
     # Check that the correct exception is raised when the publication has
     # failed for an unknown reason, and that the connection is closed.
     self.publisher._connection.is_open = False
     self.publisher._channel.publish.side_effect = pika_errs.AMQPError()
     self.assertRaises(ConnectionException, self.publisher.publish, self.message)
     self.publisher._connection.is_open = True
     self.assertRaises(ConnectionException, self.publisher.publish, self.message)
     self.publisher._connection.close.assert_called_once()
 def test_publish_reconnect_failed_generic_error(self):
     # The publisher must try to re-establish a connection on publish, and
     # close the connection if it can't be established.
     self.publisher._channel.publish.side_effect = pika_errs.ConnectionClosed(
         200, "I wanted to")
     connection_class_mock = mock.Mock()
     connection_mock = mock.Mock()
     connection_class_mock.return_value = connection_mock
     connection_mock.channel.side_effect = pika_errs.AMQPError()
     with mock.patch("fedora_messaging._session.pika.BlockingConnection",
                     connection_class_mock):
         self.assertRaises(ConnectionException, self.publisher.publish,
                           self.message)
     # Check that the connection was reestablished
     connection_class_mock.assert_called_with(self.publisher._parameters)
     self.assertEqual(self.publisher._connection, connection_mock)
     connection_mock.close.assert_called_once()