Пример #1
0
async def test_tell_invalid_response(mock_connection, response_invalid, spam):
    mock_connection.side_effect = [response_invalid]

    client = Client(host='localhost')
    with pytest.raises(BadResponse):
        response = await client.tell(MessageClassOption.spam, spam,
                                     ActionOption(local=True, remote=True))
Пример #2
0
    def __init__(self, action=None):
        '''_SetRemoveBase constructor.

        Parameters
        ----------
        action : :class:`aiospamc.options.ActionOption`, optional
            Actions to be done on local or remote.
        '''

        self.action = action or ActionOption(local=False, remote=False)
Пример #3
0
class TestSet:
    def test_field_name(self):
        set_ = Set()

        assert set_.field_name() == 'Set'

    def test_repr(self):
        set_ = Set(ActionOption(local=True, remote=True))

        assert repr(
            set_) == 'Set(action=ActionOption(local=True, remote=True))'

    @pytest.mark.parametrize('test_input,expected', [
        (ActionOption(local=True, remote=False), b'Set: local\r\n'),
        (ActionOption(local=False, remote=True), b'Set: remote\r\n'),
        (ActionOption(local=True, remote=True), b'Set: local, remote\r\n'),
        (ActionOption(local=False, remote=False), b''),
    ])
    def test_bytes(self, test_input, expected):
        set_ = Set(test_input)

        assert bytes(set_) == expected
Пример #4
0
class TestRemove:
    def test_field_name(self):
        remove = Remove()

        assert remove.field_name() == 'Remove'

    def test_repr(self):
        remove = Remove(ActionOption(local=True, remote=True))

        assert repr(
            remove) == 'Remove(action=ActionOption(local=True, remote=True))'

    @pytest.mark.parametrize('test_input,expected', [
        (ActionOption(local=True, remote=False), b'Remove: local\r\n'),
        (ActionOption(local=False, remote=True), b'Remove: remote\r\n'),
        (ActionOption(local=True, remote=True), b'Remove: local, remote\r\n'),
        (ActionOption(local=False, remote=False), b''),
    ])
    def test_bytes(self, test_input, expected):
        remove = Remove(test_input)

        assert bytes(remove) == expected
Пример #5
0
    def test_repr(self):
        remove = Remove(ActionOption(local=True, remote=True))

        assert repr(
            remove) == 'Remove(action=ActionOption(local=True, remote=True))'
Пример #6
0
    def test_repr(self):
        did_set = DidSet(ActionOption(local=True, remote=True))

        assert repr(
            did_set) == 'DidSet(action=ActionOption(local=True, remote=True))'
Пример #7
0
    def test_user_value(self):
        _set_remove = _SetRemoveBase(ActionOption(True, True))

        assert _set_remove.action == ActionOption(True, True)
Пример #8
0
def test_repr():
    did_remove = DidRemove(ActionOption(local=True, remote=True))

    assert repr(did_remove
                ) == 'DidRemove(action=ActionOption(local=True, remote=True))'
Пример #9
0
async def test_tell_valid_response(mock_connection, spam):
    client = Client(host='localhost')
    response = await client.tell(MessageClassOption.spam, spam,
                                 ActionOption(local=True, remote=True))

    assert isinstance(response, Response)
Пример #10
0
async def test_tell_connection_refused(spam):
    client = Client(host='localhost')
    with pytest.raises(AIOSpamcConnectionFailed):
        response = await client.tell(MessageClassOption.spam, spam,
                                     ActionOption(local=True, remote=True))
Пример #11
0
                                     ActionOption(local=True, remote=True))


@pytest.mark.asyncio
async def test_tell_valid_response(mock_connection, spam):
    client = Client(host='localhost')
    response = await client.tell(MessageClassOption.spam, spam,
                                 ActionOption(local=True, remote=True))

    assert isinstance(response, Response)


@pytest.mark.asyncio
@pytest.mark.parametrize('set_,remove,message_class', [
    (None, None, MessageClassOption.spam),
    (None, ActionOption(local=True, remote=True), MessageClassOption.spam),
    (ActionOption(local=True, remote=True), None, MessageClassOption.spam),
    (ActionOption(local=True, remote=True),
     ActionOption(local=True, remote=True), MessageClassOption.spam),
    (None, None, MessageClassOption.ham),
    (None, ActionOption(local=True, remote=True), MessageClassOption.ham),
    (ActionOption(local=True, remote=True), None, MessageClassOption.ham),
    (ActionOption(local=True, remote=True),
     ActionOption(local=True, remote=True), MessageClassOption.ham),
])
@patch('aiospamc.client.Client.send')
async def test_tell_valid_request(mock_connection, set_, remove, message_class,
                                  spam):
    client = Client(host='localhost')

    response = await client.tell(message_class, spam, set_, remove)
Пример #12
0
def test_repr():
    did_set = Set(ActionOption(local=True, remote=True))

    assert repr(did_set) == 'Set(action=ActionOption(local=True, remote=True))'
Пример #13
0
#!/usr/bin/env python3

import pytest

from aiospamc.headers import Set
from aiospamc.options import ActionOption


def test_repr():
    did_set = Set(ActionOption(local=True, remote=True))

    assert repr(did_set) == 'Set(action=ActionOption(local=True, remote=True))'


@pytest.mark.parametrize('test_input,expected', [
    (ActionOption(local=True, remote=False), b'Set: local\r\n'),
    (ActionOption(local=False, remote=True), b'Set: remote\r\n'),
    (ActionOption(local=True, remote=True), b'Set: local, remote\r\n'),
    (ActionOption(local=False, remote=False), b''),
])
def test_bytes(test_input, expected):
    did_set = Set(test_input)

    assert bytes(did_set) == expected
Пример #14
0
def test_parser_message_class_value_success(data, expected):
    p = Parser(data)
    result = p.message_class_value()

    assert result == expected


def test_parser_message_class_value_fail():
    p = Parser(b'invalid')

    with pytest.raises(ParseError):
        p.message_class_value()


@pytest.mark.parametrize('data,expected', [
    (b'local', ActionOption(local=True, remote=False)),
    (b'remote', ActionOption(local=False, remote=True)),
    (b'local, remote', ActionOption(local=True, remote=True)),
    (b'remote, local', ActionOption(local=True, remote=True)),
])
def test_parser_set_remove_value_success(data, expected):
    p = Parser(data)
    result = p.set_remove_value()

    assert isinstance(result, ActionOption)
    assert result == expected


def test_parser_set_remove_value_fail():
    p = Parser(b'invalid')
Пример #15
0
    def test_repr(self):
        set_ = Set(ActionOption(local=True, remote=True))

        assert repr(
            set_) == 'Set(action=ActionOption(local=True, remote=True))'
Пример #16
0
#!/usr/bin/env python3

import pytest

from aiospamc.headers import DidRemove
from aiospamc.options import ActionOption


def test_repr():
    did_remove = DidRemove(ActionOption(local=True, remote=True))

    assert repr(did_remove
                ) == 'DidRemove(action=ActionOption(local=True, remote=True))'


@pytest.mark.parametrize('test_input,expected', [
    (ActionOption(local=True, remote=False), b'DidRemove: local\r\n'),
    (ActionOption(local=False, remote=True), b'DidRemove: remote\r\n'),
    (ActionOption(local=True, remote=True), b'DidRemove: local, remote\r\n'),
    (ActionOption(local=False, remote=False), b''),
])
def test_bytes(test_input, expected):
    did_remove = DidRemove(test_input)

    assert bytes(did_remove) == expected
Пример #17
0
    def test_default_value(self):
        _set_remove = _SetRemoveBase()

        assert _set_remove.action == ActionOption(False, False)
Пример #18
0
    m = MessageClassValue(value=test_input)

    assert repr(m) == expected


@pytest.mark.parametrize(
    'test_input,expected',
    [[MessageClassOption.ham, b'ham'], [MessageClassOption.spam, b'spam']])
def test_message_class_bytes(test_input, expected):
    m = MessageClassValue(value=test_input)

    assert bytes(m) == expected


@pytest.mark.parametrize('test_input', [
    ActionOption(local=False, remote=False),
    ActionOption(local=True, remote=False),
    ActionOption(local=False, remote=True),
    ActionOption(local=True, remote=True)
])
def test_set_or_remove_str(test_input):
    s = SetOrRemoveValue(action=test_input)

    assert str(s) == 'local={}, remote={}'.format(test_input.local,
                                                  test_input.remote)


@pytest.mark.parametrize('test_input', [
    ActionOption(local=False, remote=False),
    ActionOption(local=True, remote=False),
    ActionOption(local=False, remote=True),
Пример #19
0
    assert result.value == expected


def test_parse_message_class_value_raises_parseerror():
    with pytest.raises(ParseError):
        parse_message_class_value('invalid')


@pytest.mark.parametrize('test_input,local_expected,remote_expected', [
    ['local, remote', True, True],
    ['remote, local', True, True],
    ['local', True, False],
    ['remote', False, True],
    ['', False, False],
    [ActionOption(local=True, remote=False), True, False]
])
def test_parse_set_remove_value_success(test_input, local_expected, remote_expected):
    result = parse_set_remove_value(test_input)

    assert result.action.local == local_expected
    assert result.action.remote == remote_expected


@pytest.mark.parametrize('test_input,value,score,threshold', [
    ['True ; 40.0 / 20.0', True, 40.0, 20.0],
    ['True ; -40.0 / 20.0', True, -40.0, 20.0],
    ['False ; 40.0 / 20.0', False, 40.0, 20.0],
    ['true ; 40.0 / 20.0', True, 40.0, 20.0],
    ['false ; 40.0 / 20.0', False, 40.0, 20.0],
    ['Yes ; 40.0 / 20.0', True, 40.0, 20.0],