view jabberbot/_tests/ @ 6041:a3900f360ad0

mail notification template string configuration: add examples
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sat, 01 Mar 2014 15:42:20 +0100
parents 72f1ea5f29b6
line wrap: on
line source

# -*- coding: iso-8859-1 -*-
    MoinMoin - tests for the XMPP component

    @copyright: 2007 by Karol Nowak <>
    @license: GNU GPL, see COPYING for details.

import py
from Queue import Queue

    import pyxmpp
    from jabberbot.xmppbot import XMPPBot
except ImportError:
    py.test.skip("Skipping jabber bot tests - pyxmpp is not installed")

import jabberbot.commands as commands
from jabberbot.config import BotConfig

class TestXMPPBotCommands:
    """Various tests for the XMPP bot receiving commands from Wiki"""

    def setup_class(self):
        self.from_xmlrpc = Queue()
        self.to_xmlrpc = Queue() = XMPPBot(BotConfig, self.from_xmlrpc, self.to_xmlrpc)

    def setup_method(self, method):
        self.called = False = self.dummy_method = self.dummy_method = self.dummy_method

    def dummy_method(self, *args, **kwargs):
        self.called = True

    def testNotificationCommand(self):
        """Check if send_message is triggered for tested commands"""

        data = {'text': 'Some notification', 'subject': 'It is optional', 'url_list': []}
        cmds = []
        cmds.append(commands.NotificationCommand([""], data, True))
        cmds.append(commands.NotificationCommandI18n([""], data, True))
        cmds.append(commands.GetPage("", "TestPage"))
        cmds.append(commands.GetPageHTML("", "TestPage"))

        tmp_cmd = commands.GetPageList("") = ""

        tmp_cmd = commands.GetPageInfo("", "TestPage") = {'author': 'dude', 'lastModified': '200708060T34350', 'version': 42}

        for cmd in cmds:
            self.called = False
            if not self.called:
                print "The bot should send a notification when %s arrives!" % (cmd.__class__.__name__, )
                raise Exception()

    def testRosterCommands(self):
        """Test if appropriate functions are called for (Add|Remove)JIDFromRosterCommand"""

        command = commands.AddJIDToRosterCommand("")

        if not self.called:
            print "The bot should do something when AddJIDToRosterCommand arrives!"
            raise Exception()

        self.called = False
        command = commands.RemoveJIDFromRosterCommand("")

        if not self.called:
            print "The bot should do something when RemoveJIDFromRosterCommand arrives!"
            raise Exception()

    def testInternalHelp(self):
        """Check if there's help for every known command"""

        commands = +
        for cmd in commands:
            print "There should be help on %s command!" % (cmd, )
            assert"", cmd)