Package openid :: Package test :: Module support
[frames] | no frames]

Source Code for Module openid.test.support

 1  from openid import message 
 2  from openid import oidutil 
 3   
4 -class OpenIDTestMixin(object):
5 - def failUnlessOpenIDValueEquals(self, msg, key, expected, ns=None):
6 if ns is None: 7 ns = message.OPENID_NS 8 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)
13
14 - def failIfOpenIDKeyExists(self, msg, key, ns=None):
15 if ns is None: 16 ns = message.OPENID_NS 17 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)
21
22 -class CatchLogs(object):
23 - def setUp(self):
24 self.old_logger = oidutil.log 25 oidutil.log = self.gotLogMessage 26 self.messages = []
27
28 - def gotLogMessage(self, message):
29 self.messages.append(message)
30
31 - def tearDown(self):
32 oidutil.log = self.old_logger
33
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) 44 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)
49
50 - def failUnlessLogEmpty(self):
52