telepathy-rakia: use constants in more tests

Guillaume Desmottes gdesmott at kemper.freedesktop.org
Tue Oct 1 08:41:30 PDT 2013


Module: telepathy-rakia
Branch: master
Commit: af0d37d4aeb4cdf4e5de7cc08b0dc917381c1c2f
URL:    http://cgit.freedesktop.org/telepathy/telepathy-rakia/commit/?id=af0d37d4aeb4cdf4e5de7cc08b0dc917381c1c2f

Author: Guillaume Desmottes <guillaume.desmottes at collabora.co.uk>
Date:   Tue Oct  1 13:48:48 2013 +0200

use constants in more tests

https://bugs.freedesktop.org/show_bug.cgi?id=69995

---

 tests/twisted/test-debug.py                 |   12 ++---
 tests/twisted/test-register-sasl.py         |   11 ++---
 tests/twisted/text/initiate-requestotron.py |   66 ++++++++++-----------------
 3 files changed, 35 insertions(+), 54 deletions(-)

diff --git a/tests/twisted/test-debug.py b/tests/twisted/test-debug.py
index d0e5758..090e80d 100644
--- a/tests/twisted/test-debug.py
+++ b/tests/twisted/test-debug.py
@@ -9,8 +9,6 @@ from servicetest import assertEquals, sync_dbus
 from sofiatest import exec_test
 import constants as cs
 from config import DEBUGGING
-path = '/org/freedesktop/Telepathy/debug'
-iface = 'org.freedesktop.Telepathy.Debug'
 
 def test(q, bus, conn, stream):
     conn.Connect()
@@ -21,8 +19,8 @@ def test(q, bus, conn, stream):
     def new_message(timestamp, domain, level, string):
         messages.append((timestamp, domain, level, string))
 
-    debug = bus.get_object(conn.bus_name, path)
-    debug_iface = dbus.Interface(debug, iface)
+    debug = bus.get_object(conn.bus_name, cs.DEBUG_PATH)
+    debug_iface = dbus.Interface(debug, cs.DEBUG_IFACE)
     debug_iface.connect_to_signal('NewDebugMessage', new_message)
     props_iface = dbus.Interface(debug, cs.PROPERTIES_IFACE)
 
@@ -31,8 +29,8 @@ def test(q, bus, conn, stream):
     # Turn signalling on and generate some messages.
 
     assert len(messages) == 0
-    assert props_iface.Get(iface, 'Enabled') == False
-    props_iface.Set(iface, 'Enabled', True)
+    assert props_iface.Get(cs.DEBUG_IFACE, 'Enabled') == False
+    props_iface.Set(cs.DEBUG_IFACE, 'Enabled', True)
 
     channel_path = conn.RequestChannel(
         cs.CHANNEL_TYPE_TEXT, cs.HT_CONTACT, conn.GetSelfHandle(), True)
@@ -45,7 +43,7 @@ def test(q, bus, conn, stream):
 
     # Turn signalling off and check we don't get any more messages.
 
-    props_iface.Set(iface, 'Enabled', False)
+    props_iface.Set(cs.DEBUG_IFACE, 'Enabled', False)
     sync_dbus(bus, q, conn)
     snapshot = list(messages)
 
diff --git a/tests/twisted/test-register-sasl.py b/tests/twisted/test-register-sasl.py
index f4ef924..7678e52 100644
--- a/tests/twisted/test-register-sasl.py
+++ b/tests/twisted/test-register-sasl.py
@@ -5,6 +5,8 @@ Test SIP registration failure.
 import dbus
 
 from sofiatest import exec_test
+from servicetest import assertEquals
+import constants as cs
 
 def test(q, bus, conn, sip):
     conn.Connect()
@@ -14,13 +16,10 @@ def test(q, bus, conn, sip):
     
     nc = q.expect('dbus-signal', signal='NewChannels')
     (((path, props),),) = nc.args
-    assert props['org.freedesktop.Telepathy.Channel.ChannelType'] == \
-            'org.freedesktop.Telepathy.Channel.Type.ServerAuthentication'
-    assert props['org.freedesktop.Telepathy.Channel.Interface.SASLAuthentication.AvailableMechanisms'] == \
-            ['X-TELEPATHY-PASSWORD']
+    assertEquals(cs.CHANNEL_TYPE_SERVER_AUTHENTICATION, props[cs.CHANNEL_TYPE])
+    assertEquals(['X-TELEPATHY-PASSWORD'], props[cs.SASL_AVAILABLE_MECHANISMS])
     
-    chan = dbus.Interface(bus.get_object(conn._named_service, path),
-                          "org.freedesktop.Telepathy.Channel.Interface.SASLAuthentication")
+    chan = dbus.Interface(bus.get_object(conn._named_service, path), cs.CHANNEL_IFACE_SASL_AUTH)
     
     chan.StartMechanismWithData('X-TELEPATHY-PASSWORD', 'wrong password')
     chan.AcceptSASL()
diff --git a/tests/twisted/text/initiate-requestotron.py b/tests/twisted/text/initiate-requestotron.py
index e6531b3..ac94460 100644
--- a/tests/twisted/text/initiate-requestotron.py
+++ b/tests/twisted/text/initiate-requestotron.py
@@ -5,7 +5,8 @@ Test text channel initiated by me, using Requests.
 import dbus
 
 from sofiatest import exec_test
-from servicetest import call_async, EventPattern
+from servicetest import call_async, EventPattern, assertEquals, assertContains
+import constants as cs
 
 def test(q, bus, conn, stream):
     conn.Connect()
@@ -20,28 +21,20 @@ def test(q, bus, conn, stream):
     event = q.expect('dbus-return', method='RequestHandles')
     foo_handle = event.value[0][0]
 
-    properties = conn.GetAll(
-            'org.freedesktop.Telepathy.Connection.Interface.Requests',
-            dbus_interface='org.freedesktop.DBus.Properties')
-    assert properties.get('Channels') == [], properties['Channels']
-    assert ({'org.freedesktop.Telepathy.Channel.ChannelType':
-                'org.freedesktop.Telepathy.Channel.Type.Text',
-             'org.freedesktop.Telepathy.Channel.TargetHandleType': 1,
-             },
-             ['org.freedesktop.Telepathy.Channel.TargetHandle',
-              'org.freedesktop.Telepathy.Channel.TargetID'
-             ],
-             ) in properties.get('RequestableChannelClasses'),\
-                     properties['RequestableChannelClasses']
-
-    requestotron = dbus.Interface(conn,
-            'org.freedesktop.Telepathy.Connection.Interface.Requests')
+    properties = conn.GetAll(cs.CONN_IFACE_REQUESTS,
+            dbus_interface=cs.PROPERTIES_IFACE)
+    assertEquals([], properties.get('Channels'))
+
+    assertContains(
+            ({ cs.CHANNEL_TYPE: cs.CHANNEL_TYPE_TEXT,
+               cs.TARGET_HANDLE_TYPE: cs.HT_CONTACT },
+             [ cs.TARGET_HANDLE, cs.TARGET_ID ]), properties['RequestableChannelClasses'])
+
+    requestotron = dbus.Interface(conn, cs.CONN_IFACE_REQUESTS)
     call_async(q, requestotron, 'CreateChannel',
-            { 'org.freedesktop.Telepathy.Channel.ChannelType':
-                'org.freedesktop.Telepathy.Channel.Type.Text',
-              'org.freedesktop.Telepathy.Channel.TargetHandleType': 1,
-              'org.freedesktop.Telepathy.Channel.TargetHandle': foo_handle,
-              })
+            { cs.CHANNEL_TYPE: cs.CHANNEL_TYPE_TEXT,
+              cs.TARGET_HANDLE_TYPE: cs.HT_CONTACT,
+              cs.TARGET_HANDLE: foo_handle })
 
     ret, old_sig, new_sig = q.expect_many(
         EventPattern('dbus-return', method='CreateChannel'),
@@ -51,24 +44,17 @@ def test(q, bus, conn, stream):
 
     assert len(ret.value) == 2
     emitted_props = ret.value[1]
-    assert emitted_props['org.freedesktop.Telepathy.Channel.ChannelType'] ==\
-            'org.freedesktop.Telepathy.Channel.Type.Text'
-    assert emitted_props['org.freedesktop.Telepathy.Channel.'
-            'TargetHandleType'] == 1
-    assert emitted_props['org.freedesktop.Telepathy.Channel.TargetHandle'] ==\
-            foo_handle
-    assert emitted_props['org.freedesktop.Telepathy.Channel.TargetID'] == uri
-    assert emitted_props['org.freedesktop.Telepathy.Channel.'
-            'Requested'] == True
-    assert emitted_props['org.freedesktop.Telepathy.Channel.'
-            'InitiatorHandle'] == self_handle
-    assert emitted_props['org.freedesktop.Telepathy.Channel.'
-            'InitiatorID'] == self_uri
+    assertEquals(cs.CHANNEL_TYPE_TEXT, emitted_props[cs.CHANNEL_TYPE])
+    assertEquals(cs.HT_CONTACT, emitted_props[cs.TARGET_HANDLE_TYPE])
+    assertEquals(foo_handle, emitted_props[cs.TARGET_HANDLE])
+    assertEquals(uri, emitted_props[cs.TARGET_ID])
+    assertEquals(True, emitted_props[cs.REQUESTED])
+    assertEquals(self_handle, emitted_props[cs.INITIATOR_HANDLE])
+    assertEquals(self_uri, emitted_props[cs.INITIATOR_ID])
 
     assert old_sig.args[0] == ret.value[0]
-    assert old_sig.args[1] == u'org.freedesktop.Telepathy.Channel.Type.Text'
-    # check that handle type == contact handle
-    assert old_sig.args[2] == 1
+    assert old_sig.args[1] == cs.CHANNEL_TYPE_TEXT
+    assert old_sig.args[2] == cs.HT_CONTACT
     assert old_sig.args[3] == foo_handle
     assert old_sig.args[4] == True      # suppress handler
 
@@ -78,9 +64,7 @@ def test(q, bus, conn, stream):
     assert new_sig.args[0][0][0] == ret.value[0]
     assert new_sig.args[0][0][1] == ret.value[1]
 
-    properties = conn.GetAll(
-            'org.freedesktop.Telepathy.Connection.Interface.Requests',
-            dbus_interface='org.freedesktop.DBus.Properties')
+    properties = conn.GetAll(cs.CONN_IFACE_REQUESTS, dbus_interface=cs.PROPERTIES_IFACE)
 
     assert new_sig.args[0][0] in properties['Channels'], \
             (new_sig.args[0][0], properties['Channels'])



More information about the telepathy-commits mailing list