@pytest.fixture
def ea():
    test_args = mock.Mock()
    test_args.config = 'test_config'
    test_args.rule = None
    test_args.debug = False
    test_args.es_debug_trace = None
    test_args.silence = False
    test_args.timeout = datetime.timedelta(seconds=0)
    test_args.end = None
    _conf = {'args': test_args, 'debug': False, 'rules_loader': 'test', 'rules_folder': 'rules', 'run_every': datetime.timedelta(minutes=10), 'buffer_time': datetime.timedelta(minutes=5), 'alert_time_limit': datetime.timedelta(hours=24), 'es_client': config.ESClient(es_host='es', es_port=12345, es_password='', es_username='', es_conn_timeout=1234, es_url_prefix='es/test', es_send_get_body_as='GET'), 'mail_settings': config.MailSettings(notify_email=[]), 'writeback_index': 'wb', 'writeback_alias': 'wb_a', 'max_query_size': 10000, 'old_query_limit': datetime.timedelta(weeks=1), 'disable_rules_on_error': False, 'scroll_keepalive': '30s'}
    conf = config.Config(**_conf)
    rules = {'testrule': {'name': 'testrule', 'es_host': '', 'es_port': 14900, 'index': 'idx', 'filter': [], 'include': ['@timestamp'], 'aggregation': datetime.timedelta(0), 'realert': datetime.timedelta(0), 'processed_hits': {}, 'timestamp_field': '@timestamp', 'match_enhancements': [], 'rule_file': 'blah.yaml', 'max_query_size': 10000, 'ts_to_dt': ts_to_dt, 'dt_to_ts': dt_to_ts, '_source_enabled': True, 'run_every': datetime.timedelta(seconds=15)}}
    elastalert.elastalert.elasticsearch_client = mock_es_client

    class mock_rule_loader(object):
        required_globals = frozenset([])

        def __init__(self, conf):
            self.base_config = conf
            self.load_configuration = mock.Mock()

        def load(self, args):
            return rules

        def get_hashes(self, args):
            return {}

        def load_rule(self, str: str):
            return {}
    with mock.patch('elastalert.elastalert.BackgroundScheduler'):
        with mock.patch('elastalert.elastalert.config.Config.load_config') as load_config:
            with mock.patch('elastalert.elastalert.loader_mapping') as loader_mapping, mock.patch('elastalert.elastalert.config.configure_logging'):
                loader_mapping.get.return_value = mock_rule_loader
                load_config.return_value = conf
                ea = elastalert.elastalert.ElastAlerter(['--pin_rules'])
    rules['testrule']['alert'] = [mock_alert()]
    ea.rule_es = mock_es_client()
    ea.rule_es.is_atleastsixtwo.return_value = True
    ea.rule_es.is_atleastfive.return_value = True
    ea.rule_es.index.return_value = {'_id': 'ABCD', 'created': True}
    ea.rules['testrule']['type'] = mock_ruletype(rules['testrule'], ea.rule_es)
    ea.testrule = ea.rules['testrule']['type']
    ea.conf = conf
    ea.writeback_es = mock_es_client()
    ea.writeback_es.is_atleastsixtwo.return_value = True
    ea.writeback_es.is_atleastfive.return_value = True
    ea.writeback_es.search.return_value = {'hits': {'total': {'value': '0'}, 'hits': []}}
    ea.writeback_es.deprecated_search.return_value = {'hits': {'hits': []}}
    ea.writeback_es.index.return_value = {'_id': 'ABCD', 'created': True}
    ea.es = mock_es_client()
    ea.es.index.return_value = {'_id': 'ABCD', 'created': True}
    ea.thread_data.num_hits = 0
    ea.thread_data.num_dupes = 0
    return ea
@pytest.fixture
def ea():
    test_args = mock.Mock()
    test_args.config = 'test_config'
    test_args.rule = None
    test_args.debug = False
    test_args.es_debug_trace = None
    test_args.silence = False
    test_args.timeout = datetime.timedelta(seconds=0)
    test_args.end = None
    _conf = {'args': test_args, 'debug': False, 'rules_loader': 'test', 'rules_folder': 'rules', 'run_every': datetime.timedelta(minutes=10), 'buffer_time': datetime.timedelta(minutes=5), 'alert_time_limit': datetime.timedelta(hours=24), 'es_client': config.ESClient(es_host='es', es_port=12345, es_password=, es_username=, es_conn_timeout=1234, es_url_prefix='es/test', es_send_get_body_as='GET'), 'mail_settings': config.MailSettings(notify_email=[]), 'writeback_index': 'wb', 'writeback_alias': 'wb_a', 'max_query_size': 10000, 'old_query_limit': datetime.timedelta(weeks=1), 'disable_rules_on_error': False, 'scroll_keepalive': '30s'}
    conf = config.Config(**_conf)
    rules = {'testrule': {'name': 'testrule', 'es_host': , 'es_port': 14900, 'index': 'idx', 'filter': [], 'include': ['@timestamp'], 'aggregation': datetime.timedelta(0), 'realert': datetime.timedelta(0), 'processed_hits': {}, 'timestamp_field': '@timestamp', 'match_enhancements': [], 'rule_file': 'blah.yaml', 'max_query_size': 10000, 'ts_to_dt': ts_to_dt, 'dt_to_ts': dt_to_ts, '_source_enabled': True, 'run_every': datetime.timedelta(seconds=15)}}
    elastalert.elastalert.elasticsearch_client = mock_es_client

    class mock_rule_loader(object):
        required_globals = frozenset([])

        def __init__(self, conf):
            self.base_config = conf
            self.load_configuration = mock.Mock()

        def load(self, args):
            return rules

        def get_hashes(self, args):
            return {}

        def load_rule(self, str: str):
            return {}
    with mock.patch('elastalert.elastalert.BackgroundScheduler'):
        with mock.patch('elastalert.elastalert.config.Config.load_config') as load_config:
            with mock.patch('elastalert.elastalert.loader_mapping') as loader_mapping, mock.patch('elastalert.elastalert.config.configure_logging'):
                loader_mapping.get.return_value = mock_rule_loader
                load_config.return_value = conf
                ea = elastalert.elastalert.ElastAlerter(['--pin_rules'])
    rules['testrule']['alert'] = [mock_alert()]
    ea.rule_es = mock_es_client()
    ea.rule_es.is_atleastsixtwo.return_value = True
    ea.rule_es.is_atleastfive.return_value = True
    ea.rule_es.index.return_value = {'_id': 'ABCD', 'created': True}
    ea.rules['testrule']['type'] = mock_ruletype(rules['testrule'], ea.rule_es)
    ea.testrule = ea.rules['testrule']['type']
    ea.conf = conf
    ea.writeback_es = mock_es_client()
    ea.writeback_es.is_atleastsixtwo.return_value = True
    ea.writeback_es.is_atleastfive.return_value = True
    ea.writeback_es.search.return_value = {'hits': {'total': {'value': '0'}, 'hits': []}}
    ea.writeback_es.deprecated_search.return_value = {'hits': {'hits': []}}
    ea.writeback_es.index.return_value = {'_id': 'ABCD', 'created': True}
    ea.es = mock_es_client()
    ea.es.index.return_value = {'_id': 'ABCD', 'created': True}
    ea.thread_data.num_hits = 0
    ea.thread_data.num_dupes = 0
    return ea