1 from openid
import message
2 from openid
import oidutil
4 class OpenIDTestMixin(object):
5 def failUnlessOpenIDValueEquals(self
, msg
, key
, expected
, ns
=None):
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):
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):
24 self
.old_logger
= oidutil
.log
25 oidutil
.log
= self
.gotLogMessage
28 def gotLogMessage(self
, message
):
29 self
.messages
.append(message
)
32 oidutil
.log
= self
.old_logger
34 def failUnlessLogMatches(self
, *prefixes
):
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
41 assert len(prefixes
) == len(self
.messages
), \
42 "Expected log prefixes %r, got %r" % (prefixes
,
45 for prefix
, message
in zip(prefixes
, self
.messages
):
46 assert message
.startswith(prefix
), \
47 "Expected log prefixes %r, got %r" % (prefixes
,
50 def failUnlessLogEmpty(self
):
51 self
.failUnlessLogMatches()