annotate src/test/helpers.py @ 451:4f196e2d3781

plugin xep-0045: fixed missing return deferred
author Goffi <goffi@goffi.org>
date Thu, 05 Jan 2012 00:42:24 +0100
parents e4e9187e3b5b
children cf005701624b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
335
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/python
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
Goffi <goffi@goffi.org>
parents:
diff changeset
3
Goffi <goffi@goffi.org>
parents:
diff changeset
4 """
Goffi <goffi@goffi.org>
parents:
diff changeset
5 SAT: a jabber client
Goffi <goffi@goffi.org>
parents:
diff changeset
6 Copyright (C) 2009, 2010, 2011 Jérôme Poisson (goffi@goffi.org)
Goffi <goffi@goffi.org>
parents:
diff changeset
7
Goffi <goffi@goffi.org>
parents:
diff changeset
8 This program is free software: you can redistribute it and/or modify
Goffi <goffi@goffi.org>
parents:
diff changeset
9 it under the terms of the GNU General Public License as published by
Goffi <goffi@goffi.org>
parents:
diff changeset
10 the Free Software Foundation, either version 3 of the License, or
Goffi <goffi@goffi.org>
parents:
diff changeset
11 (at your option) any later version.
Goffi <goffi@goffi.org>
parents:
diff changeset
12
Goffi <goffi@goffi.org>
parents:
diff changeset
13 This program is distributed in the hope that it will be useful,
Goffi <goffi@goffi.org>
parents:
diff changeset
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
Goffi <goffi@goffi.org>
parents:
diff changeset
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Goffi <goffi@goffi.org>
parents:
diff changeset
16 GNU General Public License for more details.
Goffi <goffi@goffi.org>
parents:
diff changeset
17
Goffi <goffi@goffi.org>
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
Goffi <goffi@goffi.org>
parents:
diff changeset
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
Goffi <goffi@goffi.org>
parents:
diff changeset
20 """
Goffi <goffi@goffi.org>
parents:
diff changeset
21
Goffi <goffi@goffi.org>
parents:
diff changeset
22 import __builtin__
Goffi <goffi@goffi.org>
parents:
diff changeset
23 from twisted.words.protocols.jabber.jid import JID
Goffi <goffi@goffi.org>
parents:
diff changeset
24
Goffi <goffi@goffi.org>
parents:
diff changeset
25 TEST_JID_STR = u"test@example.org/SàT"
Goffi <goffi@goffi.org>
parents:
diff changeset
26 TEST_JID = JID(u"test@example.org/SàT")
Goffi <goffi@goffi.org>
parents:
diff changeset
27 TEST_PROFILE = 'test_profile'
Goffi <goffi@goffi.org>
parents:
diff changeset
28
Goffi <goffi@goffi.org>
parents:
diff changeset
29 class DifferentArgsException(Exception):
Goffi <goffi@goffi.org>
parents:
diff changeset
30 pass
Goffi <goffi@goffi.org>
parents:
diff changeset
31
Goffi <goffi@goffi.org>
parents:
diff changeset
32 class FakeSAT(object):
Goffi <goffi@goffi.org>
parents:
diff changeset
33 """Class to simulate a SAT instance"""
Goffi <goffi@goffi.org>
parents:
diff changeset
34
Goffi <goffi@goffi.org>
parents:
diff changeset
35 def __init__(self):
Goffi <goffi@goffi.org>
parents:
diff changeset
36 self.bridge = FakeBridge()
Goffi <goffi@goffi.org>
parents:
diff changeset
37 self.memory = FakeMemory()
Goffi <goffi@goffi.org>
parents:
diff changeset
38 self.trigger = FakeTriggerManager()
Goffi <goffi@goffi.org>
parents:
diff changeset
39
Goffi <goffi@goffi.org>
parents:
diff changeset
40
Goffi <goffi@goffi.org>
parents:
diff changeset
41 class FakeBridge(object):
Goffi <goffi@goffi.org>
parents:
diff changeset
42 """Class to simulate and test bridge calls"""
Goffi <goffi@goffi.org>
parents:
diff changeset
43
Goffi <goffi@goffi.org>
parents:
diff changeset
44 def expectCall(self, name, *check_args, **check_kwargs):
Goffi <goffi@goffi.org>
parents:
diff changeset
45 def checkCall(*args, **kwargs):
Goffi <goffi@goffi.org>
parents:
diff changeset
46 if args != check_args or kwargs != check_kwargs:
Goffi <goffi@goffi.org>
parents:
diff changeset
47 print "\n\n--------------------"
Goffi <goffi@goffi.org>
parents:
diff changeset
48 print "Args are not equals:"
Goffi <goffi@goffi.org>
parents:
diff changeset
49 print "args\n----\n%s (sent)\n%s (wanted)" % (args, check_args)
Goffi <goffi@goffi.org>
parents:
diff changeset
50 print "kwargs\n------\n%s (sent)\n%s (wanted)" % (kwargs, check_kwargs)
Goffi <goffi@goffi.org>
parents:
diff changeset
51 print "--------------------\n\n"
Goffi <goffi@goffi.org>
parents:
diff changeset
52 raise DifferentArgsException
Goffi <goffi@goffi.org>
parents:
diff changeset
53
Goffi <goffi@goffi.org>
parents:
diff changeset
54 setattr(self, name, checkCall)
Goffi <goffi@goffi.org>
parents:
diff changeset
55
Goffi <goffi@goffi.org>
parents:
diff changeset
56
Goffi <goffi@goffi.org>
parents:
diff changeset
57 class FakeMemory(object):
Goffi <goffi@goffi.org>
parents:
diff changeset
58 """Class to simulate and test memory object"""
Goffi <goffi@goffi.org>
parents:
diff changeset
59
Goffi <goffi@goffi.org>
parents:
diff changeset
60 def getProfileName(self, profile_key):
Goffi <goffi@goffi.org>
parents:
diff changeset
61 return profile_key
Goffi <goffi@goffi.org>
parents:
diff changeset
62
425
e4e9187e3b5b backend, bridge: asynchronous history
Goffi <goffi@goffi.org>
parents: 335
diff changeset
63 def addToHistory(self, from_jid, to_jid, message, timestamp=None, profile=None):
335
Goffi <goffi@goffi.org>
parents:
diff changeset
64 pass
Goffi <goffi@goffi.org>
parents:
diff changeset
65
Goffi <goffi@goffi.org>
parents:
diff changeset
66 def addContact(self, contact_jid, attributes, groups, profile_key='@DEFAULT@'):
Goffi <goffi@goffi.org>
parents:
diff changeset
67 pass
Goffi <goffi@goffi.org>
parents:
diff changeset
68
Goffi <goffi@goffi.org>
parents:
diff changeset
69 def addPresenceStatus(self, contact_jid, show, priority, statuses, profile_key='@DEFAULT@'):
Goffi <goffi@goffi.org>
parents:
diff changeset
70 pass
Goffi <goffi@goffi.org>
parents:
diff changeset
71
Goffi <goffi@goffi.org>
parents:
diff changeset
72 def addWaitingSub(self, type, contact_jid, profile_key):
Goffi <goffi@goffi.org>
parents:
diff changeset
73 pass
Goffi <goffi@goffi.org>
parents:
diff changeset
74
Goffi <goffi@goffi.org>
parents:
diff changeset
75 def delWaitingSub(self, contact_jid, profile_key):
Goffi <goffi@goffi.org>
parents:
diff changeset
76 pass
Goffi <goffi@goffi.org>
parents:
diff changeset
77
Goffi <goffi@goffi.org>
parents:
diff changeset
78 class FakeTriggerManager(object):
Goffi <goffi@goffi.org>
parents:
diff changeset
79
Goffi <goffi@goffi.org>
parents:
diff changeset
80 def add(self, point_name, callback):
Goffi <goffi@goffi.org>
parents:
diff changeset
81 pass
Goffi <goffi@goffi.org>
parents:
diff changeset
82
Goffi <goffi@goffi.org>
parents:
diff changeset
83 def point(self, point_name, *args, **kwargs):
Goffi <goffi@goffi.org>
parents:
diff changeset
84 """We always return true to continue the action"""
Goffi <goffi@goffi.org>
parents:
diff changeset
85 return True
Goffi <goffi@goffi.org>
parents:
diff changeset
86
Goffi <goffi@goffi.org>
parents:
diff changeset
87 class FakeParent(object):
Goffi <goffi@goffi.org>
parents:
diff changeset
88 def __init__(self):
Goffi <goffi@goffi.org>
parents:
diff changeset
89 self.profile = 'test_profile'
Goffi <goffi@goffi.org>
parents:
diff changeset
90 self.jid = TEST_JID
Goffi <goffi@goffi.org>
parents:
diff changeset
91
Goffi <goffi@goffi.org>
parents:
diff changeset
92 def _(text):
Goffi <goffi@goffi.org>
parents:
diff changeset
93 return text
Goffi <goffi@goffi.org>
parents:
diff changeset
94
Goffi <goffi@goffi.org>
parents:
diff changeset
95 __builtin__.__dict__['_'] = _