예제 #1
0
def test_event_hash_variant(infile):
    with open(os.path.join(_fixture_path, infile + '.json')) as f:
        input = json.load(f)
    with open(os.path.join(_fixture_path, infile + '.out')) as f:
        refval = f.read().decode('utf-8').rstrip()

    mgr = EventManager(data=input)
    mgr.normalize()
    evt = Event(data=mgr.get_data())

    rv = []
    for (key, value) in sorted(evt.get_grouping_variants().items()):
        if rv:
            rv.append('-' * 74)
        rv.append('%s:' % key)
        dump_variant(value, rv, 1)
    output = '\n'.join(rv)
    if not refval:
        log(output)
    log(repr(evt.get_hashes()))

    assert sorted(evt.get_hashes()) == sorted(
        filter(None,
               [x.get_hash() for x in evt.get_grouping_variants().values()]))

    assert refval == output
예제 #2
0
def test_event_hash_variant(config_name, test_name):
    with open(os.path.join(_fixture_path, config_name,
                           test_name + '.json')) as f:
        input = json.load(f)
    try:
        with open(os.path.join(_fixture_path, config_name,
                               test_name + '.out')) as f:
            refval = f.read().decode('utf-8').rstrip()
    except IOError:
        refval = ''

    mgr = EventManager(data=input)
    mgr.normalize()
    data = mgr.get_data()
    evt = Event(data=data, platform=data['platform'])

    rv = []
    for (key, value) in sorted(evt.get_grouping_variants().items()):
        if rv:
            rv.append('-' * 74)
        rv.append('%s:' % key)
        dump_variant(value, rv, 1)
    output = '\n'.join(rv)
    if not refval:
        log(output)
    log(repr(evt.get_hashes()))

    assert refval == output
예제 #3
0
def test_event_hash_variant(insta_snapshot, testcase):
    with open(os.path.join(_fixture_path, testcase + '.json')) as f:
        input = json.load(f)

    config = FingerprintingRules.from_json({
        'rules': input.pop('_fingerprinting_rules'),
        'version': 1,
    })
    mgr = EventManager(data=input)
    mgr.normalize()
    data = mgr.get_data()

    data.setdefault('fingerprint', ['{{ default }}'])
    apply_server_fingerprinting(data, config)

    evt = Event(data=data, platform=data['platform'])

    def dump_variant(v):
        rv = v.as_dict()
        for key in 'component', 'description', 'hash', 'config':
            rv.pop(key, None)
        return rv

    insta_snapshot({
        'config': config.to_json(),
        'fingerprint': data['fingerprint'],
        'variants': {k: dump_variant(v)
                     for (k, v) in evt.get_grouping_variants().items()},
    })
예제 #4
0
def test_event_hash_variant(insta_snapshot, testcase):
    with open(os.path.join(_fixture_path, testcase + ".json")) as f:
        input = json.load(f)

    config = FingerprintingRules.from_json(
        {"rules": input.pop("_fingerprinting_rules"), "version": 1}
    )
    mgr = EventManager(data=input)
    mgr.normalize()
    data = mgr.get_data()

    data.setdefault("fingerprint", ["{{ default }}"])
    apply_server_fingerprinting(data, config)

    evt = Event(data=data, platform=data["platform"])

    def dump_variant(v):
        rv = v.as_dict()
        for key in "component", "description", "hash", "config":
            rv.pop(key, None)
        return rv

    insta_snapshot(
        {
            "config": config.to_json(),
            "fingerprint": data["fingerprint"],
            "variants": {k: dump_variant(v) for (k, v) in evt.get_grouping_variants().items()},
        }
    )
예제 #5
0
def test_event_hash_variant(insta_snapshot, config_name, test_name, log):
    with open(os.path.join(_fixture_path, test_name + '.json')) as f:
        input = json.load(f)

    # Cutomize grouping config from the _grouping config
    grouping_config = get_default_grouping_config_dict(config_name)
    grouping_info = input.pop('_grouping', None) or {}
    enhancement_base = grouping_info.get('enhancement_base')
    enhancements = grouping_info.get('enhancements')
    if enhancement_base or enhancements:
        enhancement_bases = [enhancement_base] if enhancement_base else []
        e = Enhancements.from_config_string(enhancements or '',
                                            bases=enhancement_bases)
        grouping_config['enhancements'] = e.dumps()

    # Noramlize the event
    mgr = EventManager(data=input, grouping_config=grouping_config)
    mgr.normalize()
    data = mgr.get_data()

    # Normalize the stacktrace for grouping.  This normally happens in
    # save()
    normalize_stacktraces_for_grouping(data,
                                       load_grouping_config(grouping_config))
    evt = Event(data=data, platform=data['platform'])

    # Make sure we don't need to touch the DB here because this would
    # break stuff later on.
    evt.project = None

    rv = []
    for (key, value) in sorted(evt.get_grouping_variants().items()):
        if rv:
            rv.append('-' * 74)
        rv.append('%s:' % key)
        dump_variant(value, rv, 1)
    output = '\n'.join(rv)
    log(repr(evt.get_hashes()))

    assert evt.get_grouping_config() == grouping_config

    insta_snapshot(output)
예제 #6
0
def test_event_hash_variant(insta_snapshot, config_name, test_name, log):
    with open(os.path.join(_fixture_path, config_name,
                           test_name + '.json')) as f:
        input = json.load(f)

    mgr = EventManager(data=input)
    mgr.normalize()
    data = mgr.get_data()
    evt = Event(data=data, platform=data['platform'])

    rv = []
    for (key, value) in sorted(evt.get_grouping_variants().items()):
        if rv:
            rv.append('-' * 74)
        rv.append('%s:' % key)
        dump_variant(value, rv, 1)
    output = '\n'.join(rv)
    log(repr(evt.get_hashes()))

    insta_snapshot(output)