Exemple #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']]))
Exemple #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']]))
Exemple #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"]]))
Exemple #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
Exemple #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
Exemple #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")
Exemple #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")
Exemple #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
Exemple #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
Exemple #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')
Exemple #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')
Exemple #12
0
def test_operator_ignores_non_oper_user():
    client = stub(operators=['me'])
    assert operator.operator(client, '#bots', 'sduncan', 'do something', '', '') in operator.nopes
Exemple #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
Exemple #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')
Exemple #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')
Exemple #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