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