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