Exemple #1
0
def test_parser_spam_value_success(data, value, score, threshold):
    p = Parser(data)
    result = p.spam_value()

    assert result['value'] is value
    assert result['score'] == pytest.approx(score)
    assert result['threshold'] == pytest.approx(threshold)
Exemple #2
0
def test_parser_skip(func):
    p = Parser(b'data')

    p.test = func
    p.skip(p.test)

    assert p.test.called
Exemple #3
0
def test_parser_headers():
    p = Parser(
        b'Content-length : 42\r\nUser : username\r\nCustom : header\r\nInvalidHeader\r\n'
    )

    result = p.headers()
    expected = (ContentLength, User, XHeader)

    for parsed_header, expected_header in zip(result, expected):
        assert isinstance(parsed_header, expected_header)
Exemple #4
0
def test_parser_request(data):
    p = Parser(data)

    assert isinstance(p.request(), Request)
Exemple #5
0
def test_parser_spamd_protocol():
    p = Parser(b'SPAMD')

    assert p.spamd_protocol() == 'SPAMD'
Exemple #6
0
def test_parser_consume_fail():
    p = Parser(b'data')

    with pytest.raises(ParseError):
        p.consume(rb'invalid')
Exemple #7
0
def test_parser_compress_value_fail():
    p = Parser(b'invalid')

    with pytest.raises(ParseError):
        p.compress_value()
Exemple #8
0
def test_parser_advance():
    p = Parser(b'data')
    p.advance(3)

    assert p.index == 3
Exemple #9
0
def test_parser_message_class_value_success(data, expected):
    p = Parser(data)
    result = p.message_class_value()

    assert result == expected
Exemple #10
0
def test_parser_user_value_success():
    p = Parser(b' user-name_123 ')

    assert p.user_value() == "user-name_123"
Exemple #11
0
def test_parser_response(data):
    p = Parser(data)

    assert isinstance(p.response(), Response)
Exemple #12
0
def test_parser_content_length_value_success(data, expected):
    p = Parser(data)
    result = p.content_length_value()

    assert result == expected
Exemple #13
0
def test_parser_spam_value_fail():
    p = Parser(b'invalid')

    with pytest.raises(ParseError):
        p.spam_value()
Exemple #14
0
def test_parser_set_remove_value_fail():
    p = Parser(b'invalid')

    with pytest.raises(ParseError):
        p.set_remove_value()
Exemple #15
0
def test_parser_set_remove_value_success(data, expected):
    p = Parser(data)
    result = p.set_remove_value()

    assert isinstance(result, ActionOption)
    assert result == expected
Exemple #16
0
def test_parser_message_class_value_fail():
    p = Parser(b'invalid')

    with pytest.raises(ParseError):
        p.message_class_value()
Exemple #17
0
def test_parser_status_code(data, expected):
    p = Parser(data)

    assert p.status_code() == expected
Exemple #18
0
def test_parser_header(data, expected):
    p = Parser(data)
    result = p.header()

    assert isinstance(result, expected)
Exemple #19
0
def test_parser_message():
    p = Parser(b'This is a message\r\n')

    assert p.message() == 'This is a message'
Exemple #20
0
def test_parser_end(index, expected):
    p = Parser(b'data')
    p.index = index

    assert p.end() == expected
Exemple #21
0
def test_parser_instantiates_with_string():
    p = Parser(b'data')

    assert 'p' in locals()
    assert p.string == b'data'
    assert p.index == 0
Exemple #22
0
def test_parser_match_fail():
    p = Parser(b'data')

    assert p.match(rb'invalid') is None
Exemple #23
0
def test_parser_current():
    p = Parser(b'data')

    assert p.current() == b'data'
Exemple #24
0
def test_parser_content_length_value_fail():
    p = Parser(b'abcdef')

    with pytest.raises(ParseError):
        p.content_length_value()
Exemple #25
0
def test_parser_match_success():
    p = Parser(b'data')

    assert p.match(rb'data').group() == b'data'
Exemple #26
0
def test_parser_spamc_protocol():
    p = Parser(b'SPAMC')

    assert p.spamc_protocol() == "SPAMC"
Exemple #27
0
def test_parser_consume_success():
    p = Parser(b'data')
    result = p.consume(rb'data')

    assert result
    assert p.index == 4
Exemple #28
0
def test_parser_instantiates():
    p = Parser()

    assert 'p' in locals()
    assert p.string == b''
    assert p.index == 0
Exemple #29
0
def test_parser_method(data, expected):
    p = Parser(data)

    assert p.method() == expected
Exemple #30
0
def test_parser_compress_value_success(data):
    p = Parser(data)
    result = p.compress_value()

    assert result == "zlib"