Example #1
0
def test_spam_bytes(value, score, threshold, expected):
    s = SpamValue(value=value, score=score, threshold=threshold)

    assert bytes(s) == expected
Example #2
0
def test_spam_repr(value, score, threshold, expected):
    s = SpamValue(value=value, score=score, threshold=threshold)

    assert repr(s) == 'SpamValue(value={}, score={}, threshold={})'.format(
        repr(value), repr(score), repr(threshold))
Example #3
0
def test_spam_str(value, score, threshold):
    s = SpamValue(value=value, score=score, threshold=threshold)

    assert str(s) == 'value={}, score={}, threshold={}'.format(
        str(value), str(score), str(threshold))
Example #4
0
    assert repr(u) == 'UserValue(name={})'.format(repr('username'))


def test_user_bytes():
    u = UserValue(name='username')

    assert bytes(u) == b'username'


@pytest.mark.parametrize('test_input', [
    GenericHeaderValue('value'),
    CompressValue(),
    ContentLengthValue(),
    SetOrRemoveValue(ActionOption(local=True, remote=False)),
    MessageClassValue(value=MessageClassOption.ham),
    SpamValue(),
    UserValue()
])
def test_equal(test_input):
    assert test_input == test_input


@pytest.mark.parametrize('test_input', [
    GenericHeaderValue('value'),
    CompressValue(),
    ContentLengthValue(),
    SetOrRemoveValue(ActionOption(local=True, remote=False)),
    MessageClassValue(value=MessageClassOption.ham),
    SpamValue(),
    UserValue()
])
Example #5
0
def spamassassin_response() -> Response:
    body = read_file("sa.txt").encode()
    headers = SpamcHeaders()
    headers["Spam"] = SpamValue(value=True, score=40, threshold=20)
    return Response(headers=headers, body=body)
def test_parse_xheader_success():
    result = parse_generic_header_value('value')

    assert isinstance(result, GenericHeaderValue)
    assert result.value == 'value'


@pytest.mark.parametrize('test_input,header,value', [
    [b'Compress: zlib', 'Compress', CompressValue(algorithm='zlib')],
    [b'Content-length: 42', 'Content-length', ContentLengthValue(length=42)],
    [b'DidRemove: local, remote', 'DidRemove', SetOrRemoveValue(action=ActionOption(local=True, remote=True))],
    [b'DidSet: local, remote', 'DidSet', SetOrRemoveValue(action=ActionOption(local=True, remote=True))],
    [b'Message-class: spam', 'Message-class', MessageClassValue(value=MessageClassOption.spam)],
    [b'Remove: local, remote', 'Remove', SetOrRemoveValue(action=ActionOption(local=True, remote=True))],
    [b'Set: local, remote', 'Set', SetOrRemoveValue(action=ActionOption(local=True, remote=True))],
    [b'Spam: True ; 40 / 20', 'Spam', SpamValue(value=True, score=40, threshold=20)],
    [b'User: username', 'User', UserValue(name='username')],
    [b'XHeader: x value', 'XHeader', GenericHeaderValue('x value')]
])
def test_parse_header_success(test_input, header, value):
    result = parse_header(test_input)

    assert result[0] == header
    assert result[1] == value


def test_parse_body_success():
    test_input = b'Test body'
    result = parse_body(test_input, len(test_input))

    assert result == test_input