Ejemplo n.º 1
0
def test_getlocation_term_fail_invalid_op():
    term = get_getlocation_term()
    term.left.op = 'invalid'
    with pytest.raises(RuntimeError) as excinfo:
        check_term(term, ['nebula', 'HTTP_DYNAMIC'], '')

    assert excinfo.value.message == '左表达式>>(invalid)不是正确的操作符'
Ejemplo n.º 2
0
def test_getlocation_term_fail_invalid_location_value():
    term = get_getlocation_term()
    term.left.location_value = ['not_exist']
    with pytest.raises(RuntimeError) as excinfo:
        check_term(term, ['nebula', 'HTTP_DYNAMIC'], '')

    assert excinfo.value.message == '左表达式>>事件(HTTP_DYNAMIC)不包含字段(not_exist)'
Ejemplo n.º 3
0
def test_event_term_fail_invalid_event():
    term = get_event_term()
    term.left.event = ['nebula', 'not_exsit']

    with pytest.raises(RuntimeError) as excinfo:
        check_term(term, ['nebula', 'ACCOUNT_LOGIN'], '')
    assert excinfo.value.message == '左表达式>>事件(not_exsit)定义配置不存在'
Ejemplo n.º 4
0
def test_getlocation_term_fail_inconsistent_trigger():
    term = get_getlocation_term()
    term.left.source_event_field = 'nebula.ACCOUNT_LOGIN.c_ip'
    with pytest.raises(RuntimeError) as excinfo:
        check_term(term, ['nebula', 'HTTP_DYNAMIC'], '')

    assert excinfo.value.message == '左表达式>>getlocation的来源事件(ACCOUNT_LOGIN)与触发事件(HTTP_DYNAMIC)不一致'
Ejemplo n.º 5
0
def test_getlocation_term_fail_invalid_field_type():
    term = get_getlocation_term()
    term.left.source_event_field = 'nebula.HTTP_DYNAMIC.status'
    with pytest.raises(RuntimeError) as excinfo:
        check_term(term, ['nebula', 'HTTP_DYNAMIC'], '')

    assert excinfo.value.message == '左表达式>>getlocation的来源字段(status)不是字符串类型'
Ejemplo n.º 6
0
def test_general_term_fail_wrong_scope():
    term = get_general_term()
    term.scope = 'invalid'

    with pytest.raises(RuntimeError) as excinfo:
        check_term(term, ['nebula', 'ACCOUNT_LOGIN'], '')
    assert excinfo.value.message == '条款的适用类型错误'
Ejemplo n.º 7
0
def test_general_term_fail_null_remark():
    term = get_general_term()
    term.remark = None

    with pytest.raises(RuntimeError) as excinfo:
        check_term(term, ['nebula', 'ACCOUNT_LOGIN'], '')
    assert excinfo.value.message == '条款描述为空'
Ejemplo n.º 8
0
def test_count_term_fail_null_operand():
    term = get_count_term()
    term.left.operand = []

    with pytest.raises(RuntimeError) as excinfo:
        check_term(term, ['nebula', 'HTTP_DYNAMIC'], '')
    assert excinfo.value.message == '左表达式>>算法(count)缺少统计对象'
Ejemplo n.º 9
0
def test_event_term_fail_invalid_field():
    term = get_event_term()
    term.left.field = 'not_exsit'

    with pytest.raises(RuntimeError) as excinfo:
        check_term(term, ['nebula', 'ACCOUNT_LOGIN'], '')
    assert excinfo.value.message == '左表达式>>事件(ACCOUNT_LOGIN)不包含字段(not_exsit)'
Ejemplo n.º 10
0
def test_general_term_fail_wrong_number():
    term = get_general_term()
    term.op = '=='
    term.right.value = 'a'
    with pytest.raises(RuntimeError) as excinfo:
        check_term(term, ['nebula', 'ACCOUNT_LOGIN'], '')
    assert excinfo.value.message == '(a)不是合理的数字'
Ejemplo n.º 11
0
def test_getlocation_term_fail_invalid_field():
    term = get_getlocation_term()
    term.left.source_event_field = 'nebula.HTTP_DYNAMIC.not_exist'
    with pytest.raises(RuntimeError) as excinfo:
        check_term(term, ['nebula', 'HTTP_DYNAMIC'], '')

    assert excinfo.value.message == '左表达式>>事件(HTTP_DYNAMIC)不包含字段(not_exist)'
Ejemplo n.º 12
0
def test_getvariable_term_fail_invalid_variable():
    term = get_getvariable_term()
    term.left.variable = ['nebula', 'not_exist']

    with pytest.raises(RuntimeError) as excinfo:
        check_term(term, ['nebula', 'ACCOUNT_LOGIN'], '')
    assert excinfo.value.message == '左表达式>>变量(not_exist)定义配置不存在'
Ejemplo n.º 13
0
def test_sbl_term_fail_invalid_ttl():
    term = get_sbl_term()

    term.left.ttl = -1
    with pytest.raises(RuntimeError) as excinfo:
        check_term(term, ['nebula', 'HTTP_DYNAMIC'], '')

    assert excinfo.value.message == '左表达式>>(-1)不是正确的ttl值'
Ejemplo n.º 14
0
def test_sbl_term_fail_invalid_check_type():
    term = get_sbl_term()

    term.left.check_type = 'invalid'
    with pytest.raises(RuntimeError) as excinfo:
        check_term(term, ['nebula', 'HTTP_DYNAMIC'], '')

    assert excinfo.value.message == '左表达式>>(invalid)不是正确的值类型'
Ejemplo n.º 15
0
def test_count_term_fail_invalid_algorithm():
    # algorithm
    term = get_count_term()
    term.left.algorithm = 'max'

    with pytest.raises(RuntimeError) as excinfo:
        check_term(term, ['nebula', 'HTTP_DYNAMIC'], '')
    assert excinfo.value.message == '左表达式>>不支持算法(max)'
Ejemplo n.º 16
0
def test_count_term_fail_invalid_interval():
    # interval
    term = get_count_term()
    term.left.interval = -1

    with pytest.raises(RuntimeError) as excinfo:
        check_term(term, ['nebula', 'HTTP_DYNAMIC'], '')
    assert excinfo.value.message == '左表达式>>(-1)不是正确的时间窗口值'
Ejemplo n.º 17
0
def test_general_term_fail_wrong_regex():
    term = get_event_term()
    term.left.field = 'uri_stem'
    term.op = 'regex'
    term.right.value = '('
    with pytest.raises(RuntimeError) as excinfo:
        check_term(term, ['nebula', 'ACCOUNT_LOGIN'], '')
    assert excinfo.value.message == '(()不是合理的正则表达式'
Ejemplo n.º 18
0
def test_getlocation_term_fail_multiple_location_value():
    term = get_getlocation_term()
    term.left.op = '='
    term.left.location_value = ['c_ip', 'did']
    with pytest.raises(RuntimeError) as excinfo:
        check_term(term, ['nebula', 'HTTP_DYNAMIC'], '')

    assert excinfo.value.message == '左表达式>>等于操作只支持一个变量'
Ejemplo n.º 19
0
def test_general_term_fail_wrong_op():
    term = get_general_term()
    term.op = 'regex'

    with pytest.raises(RuntimeError) as excinfo:
        check_term(term, ['nebula', 'ACCOUNT_LOGIN'], '')
    print excinfo.value.message
    assert excinfo.value.message == '类型(long)不支持操作(匹配正则)'
Ejemplo n.º 20
0
def test_only_support_one_dimension_now():
    # groupby
    term = get_count_term()
    term.left.groupby = ['c_ip', 'uid']

    with pytest.raises(RuntimeError) as excinfo:
        check_term(term, ['nebula', 'HTTP_DYNAMIC'], '')
    assert excinfo.value.message == '左表达式>>目前只支持单字段触发'

    term = get_count_term()
    term.left.trigger_fields = ['c_ip', 'uid']
    with pytest.raises(RuntimeError) as excinfo:
        check_term(term, ['nebula', 'HTTP_DYNAMIC'], '')
    assert excinfo.value.message == '左表达式>>目前只支持单字段触发'
Ejemplo n.º 21
0
def test_count_term_fail_invalid_field():
    # trigger fields
    term = get_count_term()
    term.left.trigger_fields = ['not_exsit']

    with pytest.raises(RuntimeError) as excinfo:
        check_term(term, ['nebula', 'HTTP_DYNAMIC'], '')
    assert excinfo.value.message == '左表达式>>事件(HTTP_DYNAMIC)不包含字段(not_exsit)'

    term = get_count_term()
    term.left.operand = ['not_exist']

    with pytest.raises(RuntimeError) as excinfo:
        check_term(term, ['nebula', 'HTTP_DYNAMIC'], '')
    assert excinfo.value.message == '左表达式>>事件(HTTP_DYNAMIC)不包含字段(not_exist)'
Ejemplo n.º 22
0
def test_getlocation_term_fail_null_location_value():
    # trigger event
    term = get_getlocation_term()

    term.left.location_value = []
    with pytest.raises(RuntimeError) as excinfo:
        check_term(term, ['nebula', 'HTTP_DYNAMIC'], '')

    assert excinfo.value.message == '左表达式>>getlocation缺乏参数配置'

    term = get_getlocation_term()
    term.left.location_value = [None]
    with pytest.raises(RuntimeError) as excinfo:
        check_term(term, ['nebula', 'HTTP_DYNAMIC'], '')

    assert excinfo.value.message == '左表达式>>getlocation缺乏参数配置'
Ejemplo n.º 23
0
def test_count_term_fail_invalid_event():
    # trigger event
    term = get_count_term()
    term.left.source_event = ['nebula', 'not_exsit']

    with pytest.raises(RuntimeError) as excinfo:
        check_term(term, ['nebula', 'HTTP_DYNAMIC'], '')
    assert excinfo.value.message == '左表达式>>事件(not_exsit)定义配置不存在'

    # source event
    term = get_count_term()
    term.left.source_event = ['nebula', 'not_exsit']

    with pytest.raises(RuntimeError) as excinfo:
        check_term(term, ['nebula', 'HTTP_DYNAMIC'], '')
    assert excinfo.value.message == '左表达式>>事件(not_exsit)定义配置不存在'
Ejemplo n.º 24
0
def test_count_term_fail_invalid_groupby():
    # groupby
    term = get_count_term()
    term.left.groupby = ['not_exist']

    with pytest.raises(RuntimeError) as excinfo:
        check_term(term, ['nebula', 'HTTP_DYNAMIC'], '')
    assert excinfo.value.message == '左表达式>>事件(HTTP_DYNAMIC)不包含字段(not_exist)'

    # groupby != trigger
    term = get_count_term()
    term.left.groupby = ['c_ip']
    term.left.trigger_fields = ['c_ip', 'uid']

    with pytest.raises(RuntimeError) as excinfo:
        check_term(term, ['nebula', 'HTTP_DYNAMIC'], '')
    assert excinfo.value.message == '左表达式>>目前只支持单字段触发'
Ejemplo n.º 25
0
def test_count_term_fail_invalid_condition():
    # condition
    term = get_count_term()
    term.left.condition.append({'left': 'not_exist', 'op': '==', 'right': '0'})

    with pytest.raises(RuntimeError) as excinfo:
        check_term(term, ['nebula', 'HTTP_DYNAMIC'], '')
    assert excinfo.value.message == '左表达式>>事件(HTTP_DYNAMIC)不包含字段(not_exist)'

    term = get_count_term()
    term.left.condition.append({'left': 'c_ip', 'op': '>', 'right': '0'})

    with pytest.raises(RuntimeError) as excinfo:
        check_term(term, ['nebula', 'HTTP_DYNAMIC'], '')
    assert excinfo.value.message == '左表达式>>类型(string)不支持操作(大于)'

    term = get_count_term()
    term.left.condition.append({'left': 'status', 'op': '>', 'right': 'a'})

    with pytest.raises(RuntimeError) as excinfo:
        check_term(term, ['nebula', 'HTTP_DYNAMIC'], '')
    assert excinfo.value.message == '左表达式>>(a)不是合理的数字'

    term = get_count_term()
    term.left.condition.append({
        'left': 'uri_stem',
        'op': 'regex',
        'right': '('
    })

    with pytest.raises(RuntimeError) as excinfo:
        check_term(term, ['nebula', 'HTTP_DYNAMIC'], '')
    assert excinfo.value.message == '左表达式>>(()不是合理的正则表达式'

    term = get_count_term()
    term.left.condition.append({
        'left': 'status',
        'op': 'between',
        'right': '1'
    })

    with pytest.raises(RuntimeError) as excinfo:
        check_term(term, ['nebula', 'HTTP_DYNAMIC'], '')
    assert excinfo.value.message == '左表达式>>介于需要逗号分隔的两个数字'

    term = get_count_term()
    term.left.condition.append({
        'left': 'status',
        'op': 'between',
        'right': '1,a'
    })

    with pytest.raises(RuntimeError) as excinfo:
        check_term(term, ['nebula', 'HTTP_DYNAMIC'], '')
    assert excinfo.value.message == '左表达式>>(a)不是合理的数字'
Ejemplo n.º 26
0
def test_general_term_success():
    check_term(get_general_term(), ['nebula', 'ACCOUNT_LOGIN'], '')
Ejemplo n.º 27
0
def test_count_term_fail_inconsistent_trigger():
    term = get_count_term()
    with pytest.raises(RuntimeError) as excinfo:
        check_term(term, ['nebula', 'ACCOUNT_LOGIN'], '')
    assert excinfo.value.message == '左表达式>>触发事件不一致'
Ejemplo n.º 28
0
def test_count_term_fail_null_trigger_field():
    term = get_count_term()
    term.left.trigger_fields = []
    with pytest.raises(RuntimeError) as excinfo:
        check_term(term, ['nebula', 'HTTP_DYNAMIC'], '')
    assert excinfo.value.message == '左表达式>>触发字段为空'
Ejemplo n.º 29
0
def test_sbl_term_success():
    check_term(get_sbl_term(), ['nebula', 'HTTP_DYNAMIC'], '')
Ejemplo n.º 30
0
def test_getlocation_term_success():
    check_term(get_getlocation_term(), ['nebula', 'HTTP_DYNAMIC'], '')