[next] telepathy-gabble: tests: tolerate some different error conditions

Simon McVittie smcv at kemper.freedesktop.org
Wed May 7 02:18:40 PDT 2014


Module: telepathy-gabble
Branch: next
Commit: 092cf3ba582eecc6e4905ef64be7ec2dc6e89175
URL:    http://cgit.freedesktop.org/telepathy/telepathy-gabble/commit/?id=092cf3ba582eecc6e4905ef64be7ec2dc6e89175

Author: Simon McVittie <simon.mcvittie at collabora.co.uk>
Date:   Fri Apr 11 13:40:51 2014 +0100

tests: tolerate some different error conditions

If we let GDBusObjectSkeleton manage our interfaces, and only add
interfaces when we know they're supported, then method calls to
unimplemented interfaces will fail with UnknownMethod rather
than NotImplemented. Similarly, Properties.Get() fails with
InvalidArgs rather than quietly returning whatever we told it to.

---

 tests/twisted/constants.py         |    1 +
 tests/twisted/mail-notification.py |   51 +++++++++++++++++++++++++-----------
 2 files changed, 37 insertions(+), 15 deletions(-)

diff --git a/tests/twisted/constants.py b/tests/twisted/constants.py
index fe81ded..577d81a 100644
--- a/tests/twisted/constants.py
+++ b/tests/twisted/constants.py
@@ -244,6 +244,7 @@ SOFTWARE_UPGRADE_REQUIRED = ERROR + '.SoftwareUpgradeRequired'
 
 BANNED = ERROR + '.Channel.Banned'
 
+DBUS_ERROR_INVALID_ARGS = 'org.freedesktop.DBus.Error.InvalidArgs'
 DBUS_ERROR_UNKNOWN_METHOD = 'org.freedesktop.DBus.Error.UnknownMethod'
 DBUS_ERROR_NO_REPLY = 'org.freedesktop.DBus.Error.NoReply'
 
diff --git a/tests/twisted/mail-notification.py b/tests/twisted/mail-notification.py
index 2150b2b..c2d84de 100644
--- a/tests/twisted/mail-notification.py
+++ b/tests/twisted/mail-notification.py
@@ -4,7 +4,7 @@ Test Connection.Interface.MailNotification
 
 from twisted.words.xish import domish
 from gabbletest import exec_test, make_result_iq, GoogleXmlStream
-from servicetest import EventPattern
+from servicetest import EventPattern, assertContains
 
 import constants as cs
 import ns
@@ -14,20 +14,35 @@ def check_properties_empty(conn, expected_flags=0):
     """Check that all mail notification properties are empty and that
        mail notification flags match the expected flags"""
 
-    flags = conn.Get(
-            cs.CONN_IFACE_MAIL_NOTIFICATION, 'MailNotificationFlags',
-            dbus_interface=cs.PROPERTIES_IFACE)
-    assert flags == expected_flags
+    try:
+        flags = conn.Get(
+                cs.CONN_IFACE_MAIL_NOTIFICATION, 'MailNotificationFlags',
+                dbus_interface=cs.PROPERTIES_IFACE)
+    except dbus.DBusException as e:
+        assertContains(e.get_dbus_name(), (cs.NOT_IMPLEMENTED,
+            cs.DBUS_ERROR_INVALID_ARGS))
+    else:
+        assert flags == expected_flags
 
-    mail_count = conn.Get(
-            cs.CONN_IFACE_MAIL_NOTIFICATION, 'UnreadMailCount',
-            dbus_interface=cs.PROPERTIES_IFACE)
-    assert mail_count == 0
+    try:
+        mail_count = conn.Get(
+                cs.CONN_IFACE_MAIL_NOTIFICATION, 'UnreadMailCount',
+                dbus_interface=cs.PROPERTIES_IFACE)
+    except dbus.DBusException as e:
+        assertContains(e.get_dbus_name(), (cs.NOT_IMPLEMENTED,
+            cs.DBUS_ERROR_INVALID_ARGS))
+    else:
+        assert mail_count == 0
 
-    unread_mails = conn.Get(
-            cs.CONN_IFACE_MAIL_NOTIFICATION, 'UnreadMails',
-            dbus_interface=cs.PROPERTIES_IFACE)
-    assert len(unread_mails) == 0
+    try:
+        unread_mails = conn.Get(
+                cs.CONN_IFACE_MAIL_NOTIFICATION, 'UnreadMails',
+                dbus_interface=cs.PROPERTIES_IFACE)
+    except dbus.DBusException as e:
+        assertContains(e.get_dbus_name(), (cs.NOT_IMPLEMENTED,
+            cs.DBUS_ERROR_INVALID_ARGS))
+    else:
+        assert mail_count == 0
 
 
 def test_google_featured(q, bus, conn, stream):
@@ -317,12 +332,18 @@ def test_no_google_featured(q, bus, conn, stream):
     try:
         conn.MailNotification.RequestInboxURL()
     except dbus.DBusException, e:
-        assert e.get_dbus_name() == cs.NOT_IMPLEMENTED
+        assertContains(e.get_dbus_name(), (cs.NOT_IMPLEMENTED,
+            cs.DBUS_ERROR_UNKNOWN_METHOD))
+    else:
+        raise AssertionError('RequestInboxURL should have failed')
 
     try:
         conn.MailNotification.RequestMailURL("1", "http://test.com/mail")
     except dbus.DBusException, e:
-        assert e.get_dbus_name() == cs.NOT_IMPLEMENTED
+        assertContains(e.get_dbus_name(), (cs.NOT_IMPLEMENTED,
+            cs.DBUS_ERROR_UNKNOWN_METHOD))
+    else:
+        raise AssertionError('RequestMailURL should have failed')
 
     # Make sure all properties return with empty or 0 data including
     # MailNotificationFlags



More information about the telepathy-commits mailing list