class_docstr: Tests for merger/main.py:AlertMerger class
class_docstr_tok: ["Tests","for","merger\/main.py",":","AlertMerger","class"]
docstr: Alert Merger - Alert Collection - Complex Merge Groups
docstr_tok: ["Alert","Merger","-","Alert","Collection","-","Complex","Merge","Groups"]
code: def test_merge_groups_complex(self):
      """Alert Merger - Alert Collection - Complex Merge Groups"""
      alerts = [
          # Merge group 1 - key 'A' minutes 0-5
          Alert(
              "same_rule_name",
              {"key": "A"},
              set(),
              created=datetime(year=2000, month=1, day=1),
              merge_by_keys=["key"],
              merge_window=timedelta(minutes=5),
          ),
          Alert(
              "same_rule_name",
              {"key": "A"},
              set(),
              created=datetime(year=2000, month=1, day=1, minute=1),
              merge_by_keys=["key"],
              merge_window=timedelta(minutes=5),
          ),
          # Merge group 2 - Key B minutes 0-5
          Alert(
              "same_rule_name",
              {"key": "B"},
              set(),
              created=datetime(year=2000, month=1, day=1, minute=2),
              merge_by_keys=["key"],
              merge_window=timedelta(minutes=5),
          ),
          Alert(
              "same_rule_name",
              {"key": "B"},
              set(),
              created=datetime(
                  year=2000, month=1, day=1, minute=2, second=30
              ),
              merge_by_keys=["key"],
              merge_window=timedelta(minutes=5),
          ),
          Alert(
              "same_rule_name",
              {"key": "B"},
              set(),
              created=datetime(year=2000, month=1, day=1, minute=3),
              merge_by_keys=["key"],
              merge_window=timedelta(minutes=5),
          ),
          # Merge group 3 - Different merge keys
          Alert(
              "same_rule_name",
              {"key": "A", "other": "B"},
              set(),
              created=datetime(year=2000, month=1, day=1, minute=4),
              merge_by_keys=["key", "other"],
              merge_window=timedelta(minutes=5),
          ),
          Alert(
              "same_rule_name",
              {"key": "A", "other": "B"},
              set(),
              created=datetime(year=2000, month=1, day=1, minute=5),
              merge_by_keys=["key", "other"],
              merge_window=timedelta(minutes=5),
          ),
          # Merge group 4 - key A minutes 50-55
          Alert(
              "same_rule_name",
              {"key": "A"},
              set(),
              created=datetime(year=2000, month=1, day=1, minute=50),
              merge_by_keys=["key"],
              merge_window=timedelta(minutes=5),
          ),
          # This alert (created now) is too recent to fit in any merge group.
          Alert(
              "same_rule_name",
              {"key": "A"},
              set(),
              merge_by_keys=["key"],
              merge_window=timedelta(minutes=10),
          ),
      ]
  
      groups = main.AlertMerger._merge_groups(alerts)
      assert_equal(4, len(groups))
      assert_equal(alerts[0:2], groups[0].alerts)
      assert_equal(alerts[2:5], groups[1].alerts)
      assert_equal(alerts[5:7], groups[2].alerts)
      assert_equal([alerts[7]], groups[3].alerts)
  
imports: from datetime import datetime, timedelta
  import os
  from mock import ANY, call, patch, MagicMock
  from moto import mock_dynamodb2, mock_lambda
  from nose.tools import assert_equal, assert_false, assert_true
  from streamalert.alert_merger import main
  from streamalert.shared.alert import Alert
  from tests.unit.helpers.aws_mocks import create_lambda_function, setup_mock_alerts_table
label_desc: Use image node_id 6 for calling the TestAlertMerger obj's underlying member method code with example usage: obj.test_merge_groups_complex() without return types