[telepathy-gabble/master] Test a couple of ways the search can fail

Will Thompson will.thompson at collabora.co.uk
Wed Aug 26 09:21:54 PDT 2009


---
 tests/twisted/constants.py                       |    1 +
 tests/twisted/search/ceci-nest-pas-un-serveur.py |   73 +++++++++++++++++++++-
 2 files changed, 73 insertions(+), 1 deletions(-)

diff --git a/tests/twisted/constants.py b/tests/twisted/constants.py
index 4a0f0eb..e4740e7 100644
--- a/tests/twisted/constants.py
+++ b/tests/twisted/constants.py
@@ -86,6 +86,7 @@ CONTACT_SEARCH_STATE = CHANNEL_TYPE_CONTACT_SEARCH + '.SearchState'
 SEARCH_NOT_STARTED = 0
 SEARCH_IN_PROGRESS = 1
 SEARCH_COMPLETED = 2
+SEARCH_FAILED = 3
 
 TUBE_CHANNEL_STATE_LOCAL_PENDING = 0
 TUBE_CHANNEL_STATE_REMOTE_PENDING = 1
diff --git a/tests/twisted/search/ceci-nest-pas-un-serveur.py b/tests/twisted/search/ceci-nest-pas-un-serveur.py
index 6e1ede9..3e926ba 100644
--- a/tests/twisted/search/ceci-nest-pas-un-serveur.py
+++ b/tests/twisted/search/ceci-nest-pas-un-serveur.py
@@ -8,7 +8,7 @@ import dbus
 from twisted.words.protocols.jabber.client import IQ
 
 from gabbletest import exec_test
-from servicetest import call_async, unwrap
+from servicetest import call_async, unwrap, make_channel_proxy, EventPattern
 
 from pprint import pformat
 
@@ -57,6 +57,75 @@ def returns_invalid_fields(q, stream, requests):
     event = q.expect('dbus-error', method='CreateChannel')
     assert event.error.get_dbus_name() == cs.NOT_AVAILABLE, event.error
 
+def returns_error_from_search(q, stream, conn, requests):
+    server = 'nofunforyou.localhost'
+    iq = call_create(q, requests, server)
+
+    result = IQ(stream, "result")
+    result["id"] = iq["id"]
+    query = result.addElement((ns.SEARCH, 'query'))
+    query.addElement("first")
+    stream.send(result)
+
+    event = q.expect('dbus-return', method='CreateChannel')
+    c = make_channel_proxy(conn, event.value[0], 'Channel')
+    c_search = dbus.Interface(c, cs.CHANNEL_TYPE_CONTACT_SEARCH)
+
+    call_async(q, c_search, 'Search', {'x-n-given': 'World of Goo'})
+    iq_event, _ = q.expect_many(
+        EventPattern('stream-iq', to=server, query_ns=ns.SEARCH),
+        EventPattern('dbus-signal', signal='SearchStateChanged'),
+        )
+    iq = iq_event.stanza
+    iq['type'] = 'error'
+    error = iq.addElement('error')
+    error['type'] = 'modify'
+    error.addElement((ns.STANZA, 'not-acceptable'))
+    error.addElement((ns.STANZA, 'text'), content="We don't believe in games here.")
+    stream.send(iq)
+
+    ssc = q.expect('dbus-signal', signal='SearchStateChanged')
+    new_state, reason, details = ssc.args
+
+    assert new_state == cs.SEARCH_FAILED, new_state
+    assert reason == cs.PERMISSION_DENIED, reason
+
+    c.Close()
+
+def returns_bees_from_search(q, stream, conn, requests):
+    server = 'hivemind.localhost'
+    iq = call_create(q, requests, server)
+
+    result = IQ(stream, "result")
+    result["id"] = iq["id"]
+    query = result.addElement((ns.SEARCH, 'query'))
+    query.addElement("nick")
+    stream.send(result)
+
+    event = q.expect('dbus-return', method='CreateChannel')
+    c = make_channel_proxy(conn, event.value[0], 'Channel')
+    c_search = dbus.Interface(c, cs.CHANNEL_TYPE_CONTACT_SEARCH)
+
+    call_async(q, c_search, 'Search', {'nickname': 'Buzzy'})
+    iq_event, _ = q.expect_many(
+        EventPattern('stream-iq', to=server, query_ns=ns.SEARCH),
+        EventPattern('dbus-signal', signal='SearchStateChanged'),
+        )
+    iq = iq_event.stanza
+
+    result = IQ(stream, 'result')
+    result['id'] = iq['id']
+    result.addElement((ns.SEARCH, 'bees')).addElement('bzzzzzzz')
+    stream.send(result)
+
+    ssc = q.expect('dbus-signal', signal='SearchStateChanged')
+    new_state, reason, details = ssc.args
+
+    assert new_state == cs.SEARCH_FAILED, new_state
+    assert reason == cs.NOT_AVAILABLE, reason
+
+    c.Close()
+
 def disconnected_before_reply(q, stream, conn, requests):
     iq = call_create(q, requests, 'slow.localhost')
 
@@ -73,6 +142,8 @@ def test(q, bus, conn, stream):
 
     not_a_search_server(q, stream, requests)
     returns_invalid_fields(q, stream, requests)
+    returns_error_from_search(q, stream, conn, requests)
+    returns_bees_from_search(q, stream, conn, requests)
     disconnected_before_reply(q, stream, conn, requests)
 
     q.expect('dbus-return', method='Disconnect')
-- 
1.5.6.5




More information about the telepathy-commits mailing list