annotate jabberbot/_tests/test_xmppbot.py @ 5106:fecbfc7f341d

twikidraw/anywikidraw: reduce code duplication, make code more similar
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 13 Sep 2009 17:47:59 +0200
parents 72f1ea5f29b6
children
rev   line source
2642
9db0237b056f Add first tests for the xmpp bot.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
1 # -*- coding: iso-8859-1 -*-
9db0237b056f Add first tests for the xmpp bot.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
2 """
9db0237b056f Add first tests for the xmpp bot.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
3 MoinMoin - tests for the XMPP component
9db0237b056f Add first tests for the xmpp bot.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
4
9db0237b056f Add first tests for the xmpp bot.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
5 @copyright: 2007 by Karol Nowak <grywacz@gmail.com>
9db0237b056f Add first tests for the xmpp bot.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
6 @license: GNU GPL, see COPYING for details.
9db0237b056f Add first tests for the xmpp bot.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
7 """
9db0237b056f Add first tests for the xmpp bot.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
8
2703
558a527c0ec7 tests: added py module import, cosmetic other changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2680
diff changeset
9 import py
2642
9db0237b056f Add first tests for the xmpp bot.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
10 from Queue import Queue
9db0237b056f Add first tests for the xmpp bot.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
11
2680
6e9a4e333f76 Skip xmpp bot test if pyxmpp is not installed.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2645
diff changeset
12 try:
6e9a4e333f76 Skip xmpp bot test if pyxmpp is not installed.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2645
diff changeset
13 import pyxmpp
2839
72f1ea5f29b6 Skip tests properly when libxml2 is not installed.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2703
diff changeset
14 from jabberbot.xmppbot import XMPPBot
2680
6e9a4e333f76 Skip xmpp bot test if pyxmpp is not installed.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2645
diff changeset
15 except ImportError:
6e9a4e333f76 Skip xmpp bot test if pyxmpp is not installed.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2645
diff changeset
16 py.test.skip("Skipping jabber bot tests - pyxmpp is not installed")
6e9a4e333f76 Skip xmpp bot test if pyxmpp is not installed.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2645
diff changeset
17
2642
9db0237b056f Add first tests for the xmpp bot.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
18 import jabberbot.commands as commands
9db0237b056f Add first tests for the xmpp bot.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
19 from jabberbot.config import BotConfig
9db0237b056f Add first tests for the xmpp bot.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
20
9db0237b056f Add first tests for the xmpp bot.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
21 class TestXMPPBotCommands:
9db0237b056f Add first tests for the xmpp bot.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
22 """Various tests for the XMPP bot receiving commands from Wiki"""
2645
3f499601e702 Whitespace fixes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2642
diff changeset
23
2642
9db0237b056f Add first tests for the xmpp bot.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
24 def setup_class(self):
9db0237b056f Add first tests for the xmpp bot.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
25 self.from_xmlrpc = Queue()
9db0237b056f Add first tests for the xmpp bot.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
26 self.to_xmlrpc = Queue()
9db0237b056f Add first tests for the xmpp bot.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
27 self.bot = XMPPBot(BotConfig, self.from_xmlrpc, self.to_xmlrpc)
2645
3f499601e702 Whitespace fixes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2642
diff changeset
28
2642
9db0237b056f Add first tests for the xmpp bot.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
29 def setup_method(self, method):
9db0237b056f Add first tests for the xmpp bot.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
30 self.called = False
9db0237b056f Add first tests for the xmpp bot.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
31 self.bot.send_message = self.dummy_method
9db0237b056f Add first tests for the xmpp bot.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
32 self.bot.ask_for_subscription = self.dummy_method
9db0237b056f Add first tests for the xmpp bot.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
33 self.bot.remove_subscription = self.dummy_method
2645
3f499601e702 Whitespace fixes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2642
diff changeset
34
2642
9db0237b056f Add first tests for the xmpp bot.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
35 def dummy_method(self, *args, **kwargs):
9db0237b056f Add first tests for the xmpp bot.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
36 self.called = True
2645
3f499601e702 Whitespace fixes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2642
diff changeset
37
2642
9db0237b056f Add first tests for the xmpp bot.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
38 def testNotificationCommand(self):
9db0237b056f Add first tests for the xmpp bot.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
39 """Check if send_message is triggered for tested commands"""
2645
3f499601e702 Whitespace fixes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2642
diff changeset
40
2642
9db0237b056f Add first tests for the xmpp bot.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
41 data = {'text': 'Some notification', 'subject': 'It is optional', 'url_list': []}
9db0237b056f Add first tests for the xmpp bot.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
42 cmds = []
9db0237b056f Add first tests for the xmpp bot.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
43 cmds.append(commands.NotificationCommand(["dude@example.com"], data, True))
9db0237b056f Add first tests for the xmpp bot.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
44 cmds.append(commands.NotificationCommandI18n(["dude@example.com"], data, True))
9db0237b056f Add first tests for the xmpp bot.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
45 cmds.append(commands.GetPage("dude@example.com", "TestPage"))
9db0237b056f Add first tests for the xmpp bot.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
46 cmds.append(commands.GetPageHTML("dude@example.com", "TestPage"))
2645
3f499601e702 Whitespace fixes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2642
diff changeset
47
2642
9db0237b056f Add first tests for the xmpp bot.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
48 tmp_cmd = commands.GetPageList("dude@example.com")
9db0237b056f Add first tests for the xmpp bot.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
49 tmp_cmd.data = ""
9db0237b056f Add first tests for the xmpp bot.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
50 cmds.append(tmp_cmd)
2645
3f499601e702 Whitespace fixes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2642
diff changeset
51
2642
9db0237b056f Add first tests for the xmpp bot.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
52 tmp_cmd = commands.GetPageInfo("dude@example.com", "TestPage")
9db0237b056f Add first tests for the xmpp bot.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
53 tmp_cmd.data = {'author': 'dude', 'lastModified': '200708060T34350', 'version': 42}
9db0237b056f Add first tests for the xmpp bot.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
54 cmds.append(tmp_cmd)
9db0237b056f Add first tests for the xmpp bot.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
55
9db0237b056f Add first tests for the xmpp bot.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
56 for cmd in cmds:
9db0237b056f Add first tests for the xmpp bot.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
57 self.called = False
9db0237b056f Add first tests for the xmpp bot.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
58 self.bot.handle_command(cmd)
9db0237b056f Add first tests for the xmpp bot.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
59 if not self.called:
2645
3f499601e702 Whitespace fixes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2642
diff changeset
60 print "The bot should send a notification when %s arrives!" % (cmd.__class__.__name__, )
2642
9db0237b056f Add first tests for the xmpp bot.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
61 raise Exception()
2645
3f499601e702 Whitespace fixes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2642
diff changeset
62
2642
9db0237b056f Add first tests for the xmpp bot.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
63 def testRosterCommands(self):
9db0237b056f Add first tests for the xmpp bot.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
64 """Test if appropriate functions are called for (Add|Remove)JIDFromRosterCommand"""
2645
3f499601e702 Whitespace fixes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2642
diff changeset
65
2642
9db0237b056f Add first tests for the xmpp bot.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
66 command = commands.AddJIDToRosterCommand("dude@example.com")
9db0237b056f Add first tests for the xmpp bot.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
67 self.bot.handle_command(command)
2645
3f499601e702 Whitespace fixes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2642
diff changeset
68
2642
9db0237b056f Add first tests for the xmpp bot.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
69 if not self.called:
9db0237b056f Add first tests for the xmpp bot.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
70 print "The bot should do something when AddJIDToRosterCommand arrives!"
9db0237b056f Add first tests for the xmpp bot.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
71 raise Exception()
2645
3f499601e702 Whitespace fixes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2642
diff changeset
72
2642
9db0237b056f Add first tests for the xmpp bot.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
73 self.called = False
9db0237b056f Add first tests for the xmpp bot.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
74 command = commands.RemoveJIDFromRosterCommand("dude@example.com")
9db0237b056f Add first tests for the xmpp bot.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
75 self.bot.handle_command(command)
2645
3f499601e702 Whitespace fixes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2642
diff changeset
76
2642
9db0237b056f Add first tests for the xmpp bot.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
77 if not self.called:
9db0237b056f Add first tests for the xmpp bot.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
78 print "The bot should do something when RemoveJIDFromRosterCommand arrives!"
9db0237b056f Add first tests for the xmpp bot.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
79 raise Exception()
2645
3f499601e702 Whitespace fixes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2642
diff changeset
80
2642
9db0237b056f Add first tests for the xmpp bot.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
81 def testInternalHelp(self):
9db0237b056f Add first tests for the xmpp bot.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
82 """Check if there's help for every known command"""
2645
3f499601e702 Whitespace fixes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2642
diff changeset
83
2642
9db0237b056f Add first tests for the xmpp bot.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
84 commands = self.bot.internal_commands + self.bot.xmlrpc_commands.values()
9db0237b056f Add first tests for the xmpp bot.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
85 for cmd in commands:
2645
3f499601e702 Whitespace fixes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2642
diff changeset
86 print "There should be help on %s command!" % (cmd, )
2642
9db0237b056f Add first tests for the xmpp bot.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
87 assert self.bot.help_on("dude@example.com", cmd)