webfaction and repo.or.cz deployment done
[worddb.git] / libs / openid / test / support.py
blobdbf8881e556802a542e0c481209045a95d71d71b
1 from openid import message
2 from openid import oidutil
4 class OpenIDTestMixin(object):
5 def failUnlessOpenIDValueEquals(self, msg, key, expected, ns=None):
6 if ns is None:
7 ns = message.OPENID_NS
9 actual = msg.getArg(ns, key)
10 error_format = 'Wrong value for openid.%s: expected=%s, actual=%s'
11 error_message = error_format % (key, expected, actual)
12 self.failUnlessEqual(expected, actual, error_message)
14 def failIfOpenIDKeyExists(self, msg, key, ns=None):
15 if ns is None:
16 ns = message.OPENID_NS
18 actual = msg.getArg(ns, key)
19 error_message = 'openid.%s unexpectedly present: %s' % (key, actual)
20 self.failIf(actual is not None, error_message)
22 class CatchLogs(object):
23 def setUp(self):
24 self.old_logger = oidutil.log
25 oidutil.log = self.gotLogMessage
26 self.messages = []
28 def gotLogMessage(self, message):
29 self.messages.append(message)
31 def tearDown(self):
32 oidutil.log = self.old_logger
34 def failUnlessLogMatches(self, *prefixes):
35 """
36 Check that the log messages contained in self.messages have
37 prefixes in *prefixes. Raise AssertionError if not, or if the
38 number of prefixes is different than the number of log
39 messages.
40 """
41 assert len(prefixes) == len(self.messages), \
42 "Expected log prefixes %r, got %r" % (prefixes,
43 self.messages)
45 for prefix, message in zip(prefixes, self.messages):
46 assert message.startswith(prefix), \
47 "Expected log prefixes %r, got %r" % (prefixes,
48 self.messages)
50 def failUnlessLogEmpty(self):
51 self.failUnlessLogMatches()