def test_success(self, circuits_app, icdx_uuid, expected_results):
        """ Test calling with sample values for the parameters """
        function_params = {"icdx_uuid": icdx_uuid}
        # Mock acquiring the config options, all config options are set to '10' or 10
        with patch.object(ICDXHelper,
                          "get_config_option",
                          lambda x, y, z=None: "10",
                          True):
            # Mock both the AMQP connection and the channel
            with patch('pika.BlockingConnection') as mock_block, \
                    patch.object(pika.BlockingConnection, 'channel') as mock_block_channel:
                # Mock the actual AMQP call
                with patch.object(AmqpFacade, 'call') as mock_amqp:
                    mock_amqp.return_value = mocked_call(payload=json.dumps({
                        "id":
                        0,
                        "uuid":
                        icdx_uuid
                    }),
                                                         success=True,
                                                         operation='get_event')

                    mock_block.return_value = mock.Mock()
                    mock_block_channel.return_value = mock.Mock()
                    results = call_icdx_get_event_function(
                        circuits_app, function_params)
                    assert (results['success'] == True)
    def test_payload_validation(self, circuits_app, icdx_search_request,
                                expected_results):
        """ Test calling with sample values for the parameters """
        function_params = {"icdx_search_request": icdx_search_request}
        # Mock acquiring the config options, all config options are set to '10' or 10
        with patch.object(ICDXHelper,
                          "get_config_option",
                          lambda x, y, z=None: "10",
                          True):
            # Mock both the AMQP connection and the channel
            with patch('pika.BlockingConnection') as mock_block, \
                    patch.object(pika.BlockingConnection, 'channel') as mock_block_channel:
                # Mock the actual AMQP call
                with patch.object(AmqpFacade, 'call') as mock_amqp:
                    if "id" not in json.loads(icdx_search_request['content']):
                        '''
                        If the "ID" attribute is missing from the payload
                        The function will return rather than raise an exception
                        but empty results are returned 
                        '''

                        mock_amqp.return_value = mocked_call(
                            payload=json.dumps(icdx_search_request['content']),
                            success=False,
                            operation='find_events')

                        mock_block.return_value = mock.Mock()
                        mock_block_channel.return_value = mock.Mock()
                        results = call_icdx_find_events_function(
                            circuits_app, function_params)
                        assert (results['success'] == False)
                        assert (results['content']['num_of_results'] == 0)
                        # Keys are duplicated to preserve backward compat, also check this value
                        assert (results['num_of_results'] == 0)

                    else:
                        mock_amqp.return_value = mocked_call(
                            payload=json.dumps(icdx_search_request['content']),
                            success=False,
                            operation='find_events')

                        mock_block.return_value = mock.Mock()
                        mock_block_channel.return_value = mock.Mock()
                        results = call_icdx_find_events_function(
                            circuits_app, function_params)
                        assert (results['success'] == False)
    def test_payload_validation(self, circuits_app):
        """ Test calling with sample values for the parameters """
        function_params = {
        }
        # Mock acquiring the config options, all config options are set to '10' or 10
        with patch.object(ICDXHelper, "get_config_option", lambda x, y,z=None: "10", True):
            # Mock both the AMQP connection and the channel
            with patch('pika.BlockingConnection') as mock_block, \
                    patch.object(pika.BlockingConnection, 'channel') as mock_block_channel:
                # Mock the actual AMQP call
                with patch.object(AmqpFacade, 'call') as mock_amqp:
                    # Expect the mocked_call to fail as input is not valid JSON
                    with pytest.raises(ValueError):
                        mock_amqp.return_value = mocked_call(self, payload=None, success=False)

                        mock_block.return_value = mock.Mock()
                        mock_block_channel.return_value = mock.Mock()