示例#1
0
def test_operator_handles_subcmd(add_autojoin, remove_autojoin, reload_plugin):
    add_autojoin.return_value = 'add_autojoin'
    remove_autojoin.return_value = 'remove_autojoin'
    reload_plugin.return_value = 'reload_plugin'

    client = Mock(operators=['me'])
    args = [client, '#bots', 'me', 'message', 'operator']

    # Client commands
    for cmd in ('join', 'leave'):
        client.reset_mock()
        operator.operator(*(args + [[cmd, '#foo']]))
        getattr(client, cmd).assert_called_with('#foo')

    # Autojoin add/remove
    assert 'add_autojoin' == operator.operator(
        *(args + [['autojoin', 'add', '#foo']]))
    assert 'remove_autojoin' == operator.operator(
        *(args + [['autojoin', 'remove', '#foo']]))

    # The feature that shall not be named
    operator.operator(*(args +
                        [['nsa', '#other_chan', 'unicode', 'snowman', u'☃']]))
    client.msg.assert_called_with('#other_chan', u'unicode snowman ☃')

    assert 'reload_plugin' == operator.operator(*(args + [['reload', 'foo']]))
示例#2
0
def test_operator_handles_subcmd(add_autojoin, remove_autojoin, reload_plugin):
    add_autojoin.return_value = 'add_autojoin'
    remove_autojoin.return_value = 'remove_autojoin'
    reload_plugin.return_value = 'reload_plugin'

    client = Mock(operators=['me'])
    args = [client, '#bots', 'me', 'message', 'operator']

    # Client commands
    for cmd in ('join', 'leave'):
        client.reset_mock()
        operator.operator(*(args + [[cmd, '#foo']]))
        getattr(client, cmd).assert_called_with('#foo')

    # Autojoin add/remove
    assert 'add_autojoin' == operator.operator(*(args + [['autojoin', 'add', '#foo']]))
    assert 'remove_autojoin' == operator.operator(*(args + [['autojoin', 'remove', '#foo']]))

    # The feature that shall not be named
    operator.operator(*(args + [['nsa', '#other_chan', 'unicode', 'snowman', u'☃']]))
    client.msg.assert_called_with('#other_chan', u'unicode snowman ☃')

    assert 'reload_plugin' == operator.operator(*(args + [['reload', 'foo']]))
示例#3
0
def test_operator_handles_subcmd(add_autojoin, remove_autojoin, reload_plugin):
    add_autojoin.return_value = "add_autojoin"
    remove_autojoin.return_value = "remove_autojoin"
    reload_plugin.return_value = "reload_plugin"

    client = Mock(operators=["me"])
    args = [client, "#bots", "me", "message", "operator"]

    # Client commands
    for cmd in ("join", "leave"):
        client.reset_mock()
        assert operator.operator(*(args + [[cmd, "#foo"]])) is None
        getattr(client, cmd).assert_called_with("#foo")

    # Autojoin add/remove
    assert "add_autojoin" == operator.operator(*(args + [["autojoin", "add", "#foo"]]))
    assert "remove_autojoin" == operator.operator(*(args + [["autojoin", "remove", "#foo"]]))

    # The feature that shall not be named
    operator.operator(*(args + [["nsa", "#other_chan", "unicode", "snowman", u"☃"]]))
    client.msg.assert_called_with("#other_chan", u"unicode snowman ☃")

    assert "reload_plugin" == operator.operator(*(args + [["reload", "foo"]]))
示例#4
0
def test_operator_ignores_non_oper_user():
    client = stub(operators=["me"])
    formatted_nopes = map(lambda s: s.format(nick="sduncan"), operator.nopes)
    assert operator.operator(client, "#bots", "sduncan", "do something", "", "") in formatted_nopes
示例#5
0
def test_operator_leave_ignores_invalid_channel():
    client = Mock(operators=["me"])
    operator.operator(client, "#bots", "me", "do something", "op", ["leave", "foo"])
    assert not client.leave.called
示例#6
0
def test_operator_leave_calls_client_leave():
    client = Mock(operators=["me"])
    operator.operator(client, "#bots", "me", "do something", "op", ["leave", "#foo"])
    client.leave.assert_called_with("#foo")
示例#7
0
def test_operator_join_calls_client_join():
    client = Mock(operators=["me"])
    operator.operator(client, "#bots", "me", "do something", "op", ["join", "#foo"])
    client.join.assert_called_with("#foo")
示例#8
0
def test_operator_ignores_non_oper_user():
    client = stub(operators=['me'])
    formatted_nopes = map(lambda s: s.format(nick='sduncan'), operator.nopes)
    assert operator.operator(client, '#bots', 'sduncan', 'do something', '',
                             '') in formatted_nopes
示例#9
0
def test_operator_leave_ignores_invalid_channel():
    client = Mock(operators=['me'])
    operator.operator(client, '#bots', 'me', 'do something', 'op',
                      ['leave', 'foo'])
    assert not client.leave.called
示例#10
0
def test_operator_leave_calls_client_leave():
    client = Mock(operators=['me'])
    operator.operator(client, '#bots', 'me', 'do something', 'op',
                      ['leave', '#foo'])
    client.leave.assert_called_with('#foo')
示例#11
0
def test_operator_join_calls_client_join():
    client = Mock(operators=['me'])
    operator.operator(client, '#bots', 'me', 'do something', 'op',
                      ['join', '#foo'])
    client.join.assert_called_with('#foo')
示例#12
0
def test_operator_ignores_non_oper_user():
    client = stub(operators=['me'])
    assert operator.operator(client, '#bots', 'sduncan', 'do something', '', '') in operator.nopes
示例#13
0
def test_operator_leave_ignores_invalid_channel():
    client = Mock(operators=['me'])
    operator.operator(client, '#bots', 'me', 'do something', 'op', ['leave', 'foo'])
    assert not client.leave.called
示例#14
0
def test_operator_leave_calls_client_leave():
    client = Mock(operators=['me'])
    operator.operator(client, '#bots', 'me', 'do something', 'op', ['leave', '#foo'])
    client.leave.assert_called_with('#foo')
示例#15
0
def test_operator_join_calls_client_join():
    client = Mock(operators=['me'])
    operator.operator(client, '#bots', 'me', 'do something', 'op', ['join', '#foo'])
    client.join.assert_called_with('#foo')
示例#16
0
def test_operator_ignores_non_oper_user():
    client = stub(operators=['me'])
    formatted_nopes = map(lambda s: s.format(nick='sduncan'), operator.nopes)
    assert operator.operator(client, '#bots', 'sduncan', 'do something', '', '') in formatted_nopes