summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorWill Thompson <will.thompson@collabora.co.uk>2009-03-23 11:08:04 (GMT)
committerWill Thompson <will.thompson@collabora.co.uk>2009-03-23 11:10:58 (GMT)
commit830a5c698d07059b47c4628affa2f9c28a45c280 (patch)
tree967347e24da41e804bd40c9215a06046089cdec6 /tests
parentadc30c1094b5719f7c61094938a704413838b0f6 (diff)
downloadtelepathy-haze-830a5c698d07059b47c4628affa2f9c28a45c280.tar.gz
telepathy-haze-830a5c698d07059b47c4628affa2f9c28a45c280.tar.xz
Steal test-text-delayed.py from Gabble.
Diffstat (limited to 'tests')
-rw-r--r--tests/twisted/Makefile.am1
-rw-r--r--tests/twisted/text/test-text-delayed.py60
2 files changed, 61 insertions, 0 deletions
diff --git a/tests/twisted/Makefile.am b/tests/twisted/Makefile.am
index 4d85717..21719d8 100644
--- a/tests/twisted/Makefile.am
+++ b/tests/twisted/Makefile.am
@@ -7,6 +7,7 @@ TWISTED_TESTS = \
text/initiate-requestotron.py \
text/initiate.py \
text/respawn.py \
+ text/test-text-delayed.py \
text/test-text-no-body.py \
text/test-text.py
diff --git a/tests/twisted/text/test-text-delayed.py b/tests/twisted/text/test-text-delayed.py
new file mode 100644
index 0000000..f2c1a94
--- /dev/null
+++ b/tests/twisted/text/test-text-delayed.py
@@ -0,0 +1,60 @@
+
+"""
+Test receiving delayed (offline) messages on a text channel.
+"""
+
+import datetime
+
+from twisted.words.xish import domish
+
+from hazetest import exec_test
+from servicetest import EventPattern
+
+def test(q, bus, conn, stream):
+ conn.Connect()
+ q.expect('dbus-signal', signal='StatusChanged', args=[0, 1])
+
+ m = domish.Element((None, 'message'))
+ m['from'] = 'foo@bar.com'
+ m['type'] = 'chat'
+ m.addElement('body', content='hello')
+
+ # add timestamp information
+ x = m.addElement(('jabber:x:delay', 'x'))
+ x['stamp'] = '20070517T16:15:01'
+
+ stream.send(m)
+
+ event = q.expect('dbus-signal', signal='NewChannel')
+ assert event.args[1] == u'org.freedesktop.Telepathy.Channel.Type.Text'
+ # check that handle type == contact handle
+ assert event.args[2] == 1
+ jid = conn.InspectHandles(1, [event.args[3]])[0]
+ assert jid == 'foo@bar.com'
+
+ received, message_received = q.expect_many(
+ EventPattern('dbus-signal', signal='Received'),
+ EventPattern('dbus-signal', signal='MessageReceived'),
+ )
+
+ old_signal_time = str(datetime.datetime.utcfromtimestamp(received.args[1]))
+ assert old_signal_time == '2007-05-17 16:15:01', old_signal_time
+ assert received.args[5] == 'hello'
+
+ message = message_received.args[0]
+ header = message[0]
+ message_sent_timestamp = header['message-sent']
+ new_signal_time = str(datetime.datetime.utcfromtimestamp(message_sent_timestamp))
+ assert new_signal_time == '2007-05-17 16:15:01', (headers, new_signal_time)
+ message_received_timestamp = header['message-received']
+ assert message_received_timestamp > message_sent_timestamp, headers
+
+ assert message[1]['content'] == 'hello', message
+
+
+ conn.Disconnect()
+ q.expect('dbus-signal', signal='StatusChanged', args=[2, 1])
+
+if __name__ == '__main__':
+ exec_test(test)
+