1 | # Copyright (c) Twisted Matrix Laboratories. |
---|
2 | # Copyright (c) Ralph Meijer. |
---|
3 | # See LICENSE for details. |
---|
4 | |
---|
5 | """ |
---|
6 | Tests for L{wokkel.compat}. |
---|
7 | """ |
---|
8 | |
---|
9 | from __future__ import division, absolute_import |
---|
10 | |
---|
11 | from zope.interface import implementer |
---|
12 | from twisted.internet import task |
---|
13 | from twisted.internet.interfaces import IReactorTime |
---|
14 | from twisted.trial import unittest |
---|
15 | from twisted.words.protocols.jabber import xmlstream |
---|
16 | |
---|
17 | from wokkel.compat import IQ |
---|
18 | |
---|
19 | @implementer(IReactorTime) |
---|
20 | class FakeReactor(object): |
---|
21 | |
---|
22 | def __init__(self): |
---|
23 | self.clock = task.Clock() |
---|
24 | self.callLater = self.clock.callLater |
---|
25 | self.getDelayedCalls = self.clock.getDelayedCalls |
---|
26 | |
---|
27 | |
---|
28 | |
---|
29 | class IQTest(unittest.TestCase): |
---|
30 | """ |
---|
31 | Tests for L{IQ}. |
---|
32 | """ |
---|
33 | |
---|
34 | def setUp(self): |
---|
35 | self.reactor = FakeReactor() |
---|
36 | self.clock = self.reactor.clock |
---|
37 | |
---|
38 | |
---|
39 | def testRequestTimingOutEventDispatcher(self): |
---|
40 | """ |
---|
41 | Test that an iq request with a defined timeout times out. |
---|
42 | """ |
---|
43 | from twisted.words.xish import utility |
---|
44 | output = [] |
---|
45 | xs = utility.EventDispatcher() |
---|
46 | xs.send = output.append |
---|
47 | |
---|
48 | self.iq = IQ(xs, reactor=self.reactor) |
---|
49 | self.iq.timeout = 60 |
---|
50 | d = self.iq.send() |
---|
51 | self.assertFailure(d, xmlstream.TimeoutError) |
---|
52 | |
---|
53 | self.clock.pump([1, 60]) |
---|
54 | self.assertFalse(self.reactor.getDelayedCalls()) |
---|
55 | self.assertFalse(xs.iqDeferreds) |
---|
56 | return d |
---|