def test_destroy_queue_with_http_errors(self, client): disconnect_consumers_mock = Mock(side_effect=HTTPError({}, status=500)) clear_queue_mock = Mock(side_effect=HTTPError({}, status=500)) delete_queue = Mock(side_effect=HTTPError({}, status=500)) client.disconnect_consumers = disconnect_consumers_mock client.clear_queue = clear_queue_mock client.delete_queue = delete_queue client.destroy_queue("queue_name", True) assert disconnect_consumers_mock.called is True assert clear_queue_mock.called is True assert delete_queue.called is True
def test_clear_queue_404_http_exception(self): self.clients["pyrabbit"].clear_queue = Mock( side_effect=HTTPError({}, 404, "Reason")) self.assertRaises(bg_utils.bg_thrift.InvalidSystem, self.handler.clearQueue, "queue_name") self.clients["pyrabbit"].clear_queue.assert_called_once_with( "queue_name")
def test_remove_system_errors_2(self, system_mock): fake_system = MagicMock(version="0.0.1") type(fake_system).name = PropertyMock(return_value="name") fake_system.instances = [ Mock( name="default", queue_info={ "admin": { "name": "admin_queue" }, "request": { "name": "request_queue" }, }, ) ] system_mock.objects.get = Mock(return_value=fake_system) fake_plugin = Mock(unique_name="name[default]-0.0.1") self.registry.get_plugins_by_system.return_value = [fake_plugin] self.clients["pyrabbit"].disconnect_consumers.side_effect = Exception self.clients["pyrabbit"].clear_queue.side_effect = Exception self.clients["pyrabbit"].delete_queue.side_effect = HTTPError({}, 400, "Reason") self.handler.removeSystem("id") self.assertTrue(fake_system.deep_delete.called)
def test_get_queue_size_bad_exception(self, client, pyrabbit_client): pyrabbit_client.get_queue.side_effect = HTTPError({}, status=500, reason="something") with pytest.raises(HTTPError): client.get_queue_size("queue")
def test_clear_queue_other_http_exception(self): self.clients["pyrabbit"].clear_queue = Mock( side_effect=HTTPError({}, 500, "Reason")) self.assertRaises(HTTPError, self.handler.clearQueue, "queue_name")