From 3a85283277a3c1a8b7e47f231bc8b3f562f1db7b Mon Sep 17 00:00:00 2001 From: Debarshi Ray Date: Mon, 25 Apr 2011 22:49:45 +0300 Subject: [PATCH] Test to cover RequestContactInfo Fixes: https://bugs.freedesktop.org/34796 --- tests/twisted/Makefile.am | 1 + tests/twisted/messages/contactinfo-request.py | 70 +++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 0 deletions(-) create mode 100644 tests/twisted/messages/contactinfo-request.py diff --git a/tests/twisted/Makefile.am b/tests/twisted/Makefile.am index 6b61303..338d03e 100644 --- a/tests/twisted/Makefile.am +++ b/tests/twisted/Makefile.am @@ -12,6 +12,7 @@ TWISTED_TESTS = \ channels/requests-muc.py \ channels/muc-channel-topic.py \ messages/accept-invalid-nicks.py \ + messages/contactinfo-request.py \ messages/messages-iface.py \ messages/message-order.py \ messages/leading-space.py \ diff --git a/tests/twisted/messages/contactinfo-request.py b/tests/twisted/messages/contactinfo-request.py new file mode 100644 index 0000000..de54d81 --- /dev/null +++ b/tests/twisted/messages/contactinfo-request.py @@ -0,0 +1,70 @@ + +""" +Test RequestContactInfo implementation +""" + +from idletest import exec_test +from servicetest import EventPattern, assertEquals, call_async +from constants import * +import dbus + +CHANNEL_NAMES = ['#idletest0', '#idletest1'] + +def validate_vcard(vcard): + channel_names = [] + for (name, parameters, value) in vcard: + if name == 'fn': + assertEquals('Test User', value[0]) + elif name == 'x-irc-channel': + channel_names.append(value[0]) + elif name == 'x-idle-time': + assertEquals('42', value[0]) # fake value + elif name == 'nickname': + assertEquals('test', value[0]) + elif name == 'x-presence-type': + assertEquals(PRESENCE_AVAILABLE, int(value[0])) + elif name == 'x-presence-status-identifier': + assertEquals('available', value[0]) + assertEquals(CHANNEL_NAMES, channel_names) + +def test(q, bus, conn, stream): + conn.Connect() + q.expect_many( + EventPattern('dbus-signal', signal='StatusChanged', args=[1, 1]), + EventPattern('irc-connected')) + q.expect('dbus-signal', signal='SelfHandleChanged', + args=[1L]) + q.expect('dbus-signal', signal='StatusChanged', args=[0, 1]) + + self_handle = conn.GetSelfHandle() + + room_handles = conn.RequestHandles(HT_ROOM, CHANNEL_NAMES) + for room_handle in room_handles: + call_async(q, conn, 'RequestChannel', CHANNEL_TYPE_TEXT, HT_ROOM, room_handle, True) + q.expect('dbus-return', method='RequestChannel') + q.expect('dbus-signal', signal='NewChannels') + + contact_info = dbus.Interface(conn, CONN_IFACE_CONTACT_INFO) + + # The test server alternatively returns success and RPL_TRYAGAIN in + # response to WHOIS queries. The first WHOIS query is issued as part of the + # handshake when the connection is initially made. So this one is going to + # return a RPL_TRYAGAIN resulting in a SERVICE_BUSY error. + call_async(q, contact_info, 'RequestContactInfo', self_handle) + event = q.expect('dbus-error', method='RequestContactInfo') + assertEquals(SERVICE_BUSY, event.name) + + call_async(q, contact_info, 'RequestContactInfo', self_handle) + event = q.expect('dbus-return', method='RequestContactInfo') + vcard = event.value[0] + + validate_vcard(vcard) + + call_async(q, conn, 'Disconnect') + q.expect_many( + EventPattern('dbus-return', method='Disconnect'), + EventPattern('dbus-signal', signal='StatusChanged', args=[2, 1])) + return True + +if __name__ == '__main__': + exec_test(test) -- 1.7.4.4