[telepathy-gabble/master] Convert Content() in JingleTest2 to take transports and descriptions separately.

Mike Ruprecht mike.ruprecht at collabora.co.uk
Tue Dec 29 05:35:32 PST 2009


---
 tests/twisted/jingle/accept-extra-stream.py        |    8 ++--
 tests/twisted/jingle/hold-av.py                    |    4 +-
 tests/twisted/jingle/jingletest2.py                |   40 ++++++++++---------
 .../twisted/jingle/test-content-adding-removal.py  |    2 +-
 tests/twisted/jingle/test-content-complex.py       |   22 +++++-----
 tests/twisted/jingle/test-description-info.py      |   12 +++---
 tests/twisted/jingle/test-incoming-iceudp.py       |    4 +-
 tests/twisted/jingle/test-outgoing-iceudp.py       |    8 ++--
 8 files changed, 51 insertions(+), 49 deletions(-)

diff --git a/tests/twisted/jingle/accept-extra-stream.py b/tests/twisted/jingle/accept-extra-stream.py
index e459c55..a32ff66 100644
--- a/tests/twisted/jingle/accept-extra-stream.py
+++ b/tests/twisted/jingle/accept-extra-stream.py
@@ -23,11 +23,11 @@ def test(q, bus, conn, stream):
     # Remote end calls us
     node = jp.SetIq(jt2.peer, jt2.jid, [
         jp.Jingle(jt2.sid, jt2.peer, 'session-initiate', [
-            jp.Content('audiostream', 'initiator', 'both', [
+            jp.Content('audiostream', 'initiator', 'both',
                 jp.Description('audio', [
                     jp.PayloadType(name, str(rate), str(id)) for
                         (name, id, rate) in jt2.audio_codecs ]),
-            jp.TransportGoogleP2P() ]) ]) ])
+            jp.TransportGoogleP2P()) ]) ])
     stream.send(jp.xml(node))
 
     nc = q.expect('dbus-signal', signal='NewChannel')
@@ -108,11 +108,11 @@ def test(q, bus, conn, stream):
     # Foo would like to gaze upon our beautiful complexion
     node = jp.SetIq(jt2.peer, jt2.jid, [
         jp.Jingle(jt2.sid, jt2.peer, 'content-add', [
-            jp.Content('videostream', 'initiator', 'both', [
+            jp.Content('videostream', 'initiator', 'both',
                 jp.Description('video', [
                     jp.PayloadType(name, str(rate), str(id)) for
                         (name, id, rate) in jt2.video_codecs ]),
-            jp.TransportGoogleP2P() ]) ]) ])
+            jp.TransportGoogleP2P()) ]) ])
     stream.send(jp.xml(node))
 
     added, nsh = q.expect_many(
diff --git a/tests/twisted/jingle/hold-av.py b/tests/twisted/jingle/hold-av.py
index 6e09901..f66fab9 100644
--- a/tests/twisted/jingle/hold-av.py
+++ b/tests/twisted/jingle/hold-av.py
@@ -55,11 +55,11 @@ def mutable_stream_tests(jp, jt, q, bus, conn, stream, chan, handle):
 
     node = jp.SetIq(jt.peer, jt.jid, [
         jp.Jingle(jt.sid, jt.peer, 'content-add', [
-            jp.Content('videostream', 'initiator', 'both', [
+            jp.Content('videostream', 'initiator', 'both',
                 jp.Description('video', [
                     jp.PayloadType(name, str(rate), str(id)) for
                         (name, id, rate) in jt.video_codecs ]),
-            jp.TransportGoogleP2P() ]) ]) ])
+            jp.TransportGoogleP2P()) ]) ])
     stream.send(jp.xml(node))
 
     e = q.expect('dbus-signal', signal='NewStreamHandler')
diff --git a/tests/twisted/jingle/jingletest2.py b/tests/twisted/jingle/jingletest2.py
index 145c8cb..13d5165 100644
--- a/tests/twisted/jingle/jingletest2.py
+++ b/tests/twisted/jingle/jingletest2.py
@@ -237,17 +237,16 @@ class GtalkProtocol03(JingleProtocol):
         return p
 
     # Gtalk has only one content, and <content> node is implicit
-    def Content(self, name, creator, senders, children):
+    def Content(self, name, creator, senders, description=None, transport=None):
         # Normally <content> has <description> and <transport>, but we only
         # use <description> unless <transport> has candidates.
-        assert len(children) == 2
-        assert children[1] != None
-        assert children[1][3] != None
+        assert description != None
+        assert transport != None
 
         # if <transport> has children return those children (candidates)
-        if len(children[1][3]) > 0:
-            return children[1][3][0]
-        return children[0]
+        if len(transport[3]) > 0:
+            return transport[3][0]
+        return description
 
     def Description(self, type, children):
         if type == 'audio':
@@ -326,8 +325,9 @@ class GtalkProtocol04(JingleProtocol):
             { 'type': action, 'initiator': initiator, 'id': sid }, children)
 
     # hacky: parent Jingle node should just pick up our children
-    def Content(self, name, creator, senders, children):
-        return ('dummy-content', None, {}, children)
+    def Content(self, name, creator, senders, description=None, transport=None):
+        return ('dummy-content', None, {},
+            [node for node in [description, transport] if node != None])
 
     def Description(self, type, children):
         return ('description', ns.GOOGLE_SESSION_PHONE, {}, children)
@@ -358,11 +358,12 @@ class JingleProtocol015(JingleProtocol):
             { 'action': action, 'initiator': initiator, 'sid': sid }, children)
 
     # Note: senders weren't mandatory in this dialect
-    def Content(self, name, creator, senders, children):
+    def Content(self, name, creator, senders, description=None, transport=None):
         attribs = { 'name': name, 'creator': creator }
         if senders:
             attribs['senders'] = senders
-        return ('content', None, attribs, children)
+        return ('content', None, attribs,
+            [node for node in [description, transport] if node != None])
 
     def Description(self, type, children):
         if type == 'audio':
@@ -414,11 +415,12 @@ class JingleProtocol031(JingleProtocol):
         return ('jingle', ns.JINGLE,
             { 'action': action, 'initiator': initiator, 'sid': sid }, children)
 
-    def Content(self, name, creator, senders, children):
+    def Content(self, name, creator, senders, description=None, transport=None):
         if not senders:
             senders = 'both'
         return ('content', None,
-            { 'name': name, 'creator': creator, 'senders': senders }, children)
+            { 'name': name, 'creator': creator, 'senders': senders },
+            [node for node in [description, transport] if node != None])
 
     def Description(self, type, children):
         return ('description', ns.JINGLE_RTP, { 'media': type }, children)
@@ -564,9 +566,9 @@ class JingleTest2:
                 payload = []
 
             contents.append(
-                jp.Content('stream0', 'initiator', 'both', [
+                jp.Content('stream0', 'initiator', 'both',
                     jp.Description('video', payload),
-                    jp.TransportGoogleP2P(transports) ])
+                    jp.TransportGoogleP2P(transports))
              )
         else:
             def mk_content(name, media, codecs):
@@ -578,9 +580,9 @@ class JingleTest2:
                     payload = []
 
                 contents.append(
-                    jp.Content(name, 'initiator', 'both', [
+                    jp.Content(name, 'initiator', 'both',
                         jp.Description(media, payload),
-                    jp.TransportGoogleP2P(transports) ])
+                    jp.TransportGoogleP2P(transports))
                 )
 
             for name in self.audio_names:
@@ -637,11 +639,11 @@ class JingleTest2:
         # Remote end finally accepts
         node = jp.SetIq(self.peer, self.jid, [
             jp.Jingle(self.sid, self.peer, 'content-accept', [
-                jp.Content(c['name'], c['creator'], c['senders'], [
+                jp.Content(c['name'], c['creator'], c['senders'],
                     jp.Description(media, [
                         jp.PayloadType(name, str(rate), str(id)) for
                             (name, id, rate) in codecs ]),
-                jp.TransportGoogleP2P() ]) ]) ])
+                jp.TransportGoogleP2P()) ]) ])
         self.stream.send(jp.xml(node))
 
     def terminate(self, reason=None, text=""):
diff --git a/tests/twisted/jingle/test-content-adding-removal.py b/tests/twisted/jingle/test-content-adding-removal.py
index 12aa4d6..2ae5fb2 100644
--- a/tests/twisted/jingle/test-content-adding-removal.py
+++ b/tests/twisted/jingle/test-content-adding-removal.py
@@ -127,7 +127,7 @@ def test(jp, q, bus, conn, stream, peer_removes_final_content):
         # session-terminate.
         node = jp.SetIq(jt.peer, jt.jid, [
             jp.Jingle(jt.sid, jt.peer, 'content-remove', [
-                jp.Content(c['name'], c['creator'], c['senders'], []) ]) ])
+                jp.Content(c['name'], c['creator'], c['senders']) ]) ])
         stream.send(jp.xml(node))
     else:
         # The Telepathy client removes the second stream; Gabble should
diff --git a/tests/twisted/jingle/test-content-complex.py b/tests/twisted/jingle/test-content-complex.py
index 9f97561..bd95313 100644
--- a/tests/twisted/jingle/test-content-complex.py
+++ b/tests/twisted/jingle/test-content-complex.py
@@ -99,11 +99,11 @@ def worker(jp, q, bus, conn, stream):
     # Remote end tries to create a content we can't handle
     node = jp.SetIq(jt2.peer, jt2.jid, [
         jp.Jingle(jt2.sid, jt2.peer, 'content-add', [
-            jp.Content('bogus', 'initiator', 'both', [
+            jp.Content('bogus', 'initiator', 'both',
                 jp.Description('hologram', [
                     jp.PayloadType(name, str(rate), str(id)) for
                         (name, id, rate) in jt2.audio_codecs ]),
-            jp.TransportGoogleP2P() ]) ]) ])
+            jp.TransportGoogleP2P()) ]) ])
     stream.send(jp.xml(node))
 
     # In older Jingle, this is a separate namespace, which isn't
@@ -125,11 +125,11 @@ def worker(jp, q, bus, conn, stream):
     # Remote end then tries to create a content with a name it's already used
     node = jp.SetIq(jt2.peer, jt2.jid, [
         jp.Jingle(jt2.sid, jt2.peer, 'content-add', [
-            jp.Content(jt2.audio_names[0], 'initiator', 'both', [
+            jp.Content(jt2.audio_names[0], 'initiator', 'both',
                 jp.Description('audio', [
                     jp.PayloadType(name, str(rate), str(id)) for
                         (name, id, rate) in jt2.audio_codecs ]),
-            jp.TransportGoogleP2P() ]) ]) ])
+            jp.TransportGoogleP2P()) ]) ])
     stream.send(jp.xml(node))
 
     # Gabble should return error (content already exists)
@@ -164,7 +164,7 @@ def worker(jp, q, bus, conn, stream):
     # Remote end rejects the first stream we tried to add.
     node = jp.SetIq(jt2.peer, jt2.jid, [
         jp.Jingle(jt2.sid, jt2.peer, 'content-reject', [
-            jp.Content(c['name'], c['creator'], c['senders'], []) ]) ])
+            jp.Content(c['name'], c['creator'], c['senders']) ]) ])
     stream.send(jp.xml(node))
 
     # Gabble removes the stream
@@ -175,11 +175,11 @@ def worker(jp, q, bus, conn, stream):
     # just added
     node = jp.SetIq(jt2.peer, jt2.jid, [
         jp.Jingle(jt2.sid, jt2.peer, 'content-add', [
-            jp.Content(d['name'], 'initiator', 'both', [
+            jp.Content(d['name'], 'initiator', 'both',
                 jp.Description('audio', [
                     jp.PayloadType(name, str(rate), str(id)) for
                         (name, id, rate) in jt2.audio_codecs ]),
-            jp.TransportGoogleP2P() ]) ]) ])
+            jp.TransportGoogleP2P()) ]) ])
     stream.send(jp.xml(node))
 
     # Because stream names are namespaced by creator, Gabble should be okay
@@ -193,7 +193,7 @@ def worker(jp, q, bus, conn, stream):
     # it tried to add.
     node = jp.SetIq(jt2.peer, jt2.jid, [
         jp.Jingle(jt2.sid, jt2.peer, 'content-remove', [
-            jp.Content(d['name'], 'initiator', d['senders'], []) ]) ])
+            jp.Content(d['name'], 'initiator', d['senders']) ]) ])
     stream.send(jp.xml(node))
 
     q.expect_many(
@@ -211,11 +211,11 @@ def worker(jp, q, bus, conn, stream):
     #    called 'foo' existed any more.
     node = jp.SetIq(jt2.peer, jt2.jid, [
         jp.Jingle(jt2.sid, jt2.peer, 'content-accept', [
-            jp.Content(d['name'], d['creator'], d['senders'], [
+            jp.Content(d['name'], d['creator'], d['senders'],
                 jp.Description('video', [
                     jp.PayloadType(name, str(rate), str(id)) for
                         (name, id, rate) in jt2.audio_codecs ]),
-            jp.TransportGoogleP2P() ]) ]) ])
+            jp.TransportGoogleP2P()) ]) ])
     stream.send(jp.xml(node))
 
     # We get remote codecs
@@ -233,7 +233,7 @@ def worker(jp, q, bus, conn, stream):
     # ...but before it's acked the peer sends its own content-remove...
     node = jp.SetIq(jt2.peer, jt2.jid, [
         jp.Jingle(jt2.sid, jt2.peer, 'content-remove', [
-            jp.Content(c['name'], c['creator'], c['senders'], []) ]) ])
+            jp.Content(c['name'], c['creator'], c['senders']) ]) ])
     stream.send(jp.xml(node))
 
     # ...and we don't want Gabble to break when that happens.
diff --git a/tests/twisted/jingle/test-description-info.py b/tests/twisted/jingle/test-description-info.py
index f705b27..3dbe7eb 100644
--- a/tests/twisted/jingle/test-description-info.py
+++ b/tests/twisted/jingle/test-description-info.py
@@ -60,8 +60,8 @@ def test(q, bus, conn, stream, send_early_description_info=False):
         """
         node = jp.SetIq(jt2.peer, jt2.jid, [
             jp.Jingle(jt2.sid, jt2.peer, 'description-info', [
-                jp.Content('stream1', 'initiator', 'both', [
-                    jp.Description('audio', [ ]) ]) ]) ])
+                jp.Content('stream1', 'initiator', 'both',
+                    jp.Description('audio', [ ])) ]) ])
         stream.send(jp.xml(node))
 
         sync_stream(q, stream)
@@ -166,9 +166,9 @@ def test(q, bus, conn, stream, send_early_description_info=False):
     # error back.
     node = jp.SetIq(jt2.peer, jt2.jid, [
         jp.Jingle(jt2.sid, jt2.peer, 'description-info', [
-            jp.Content(audio_content, 'initiator', 'both', [
+            jp.Content(audio_content, 'initiator', 'both',
                 jp.Description('audio', [
-                    jp.PayloadType('PCMU', '1600', '0') ]) ]) ]) ])
+                    jp.PayloadType('PCMU', '1600', '0') ])) ]) ])
     stream.send(jp.xml(node))
     q.expect('stream-iq', iq_type='error',
         predicate=lambda x: x.stanza['id'] == node[2]['id'])
@@ -182,10 +182,10 @@ def test(q, bus, conn, stream, send_early_description_info=False):
     c = new_codecs[2]
     node = jp.SetIq(jt2.peer, jt2.jid, [
         jp.Jingle(jt2.sid, jt2.peer, 'description-info', [
-            jp.Content(audio_content, 'initiator', 'both', [
+            jp.Content(audio_content, 'initiator', 'both',
                 jp.Description('audio', [
                     jp.PayloadType(c[0], str(c[2]), str(c[1]), c[3])
-                ]) ]) ]) ])
+                ])) ]) ])
     stream.send(jp.xml(node))
 
     # Gabble should patch its idea of the remote codecs with the update it just
diff --git a/tests/twisted/jingle/test-incoming-iceudp.py b/tests/twisted/jingle/test-incoming-iceudp.py
index 7cd2c5d..2e36548 100644
--- a/tests/twisted/jingle/test-incoming-iceudp.py
+++ b/tests/twisted/jingle/test-incoming-iceudp.py
@@ -23,11 +23,11 @@ def worker(jp, q, bus, conn, stream):
     # Remote end calls us
     node = jp.SetIq(jt2.peer, jt2.jid, [
         jp.Jingle(jt2.sid, jt2.peer, 'session-initiate', [
-            jp.Content('stream1', 'initiator', 'both', [
+            jp.Content('stream1', 'initiator', 'both',
                 jp.Description('audio', [
                     jp.PayloadType(name, str(rate), str(id)) for
                         (name, id, rate) in jt2.audio_codecs ]),
-            jp.TransportIceUdp() ]) ]) ])
+            jp.TransportIceUdp()) ]) ])
     stream.send(jp.xml(node))
 
     nc, e = q.expect_many(
diff --git a/tests/twisted/jingle/test-outgoing-iceudp.py b/tests/twisted/jingle/test-outgoing-iceudp.py
index 8805391..391f3d6 100644
--- a/tests/twisted/jingle/test-outgoing-iceudp.py
+++ b/tests/twisted/jingle/test-outgoing-iceudp.py
@@ -101,8 +101,8 @@ def worker(jp, q, bus, conn, stream):
 
     node = jp.SetIq(jt2.peer, jt2.jid, [
         jp.Jingle(jt2.sid, jt2.peer, 'transport-info', [
-            jp.Content('Audio', 'initiator', 'both', [
-                transport]) ]) ])
+            jp.Content('Audio', 'initiator', 'both',
+                transport = transport) ]) ])
     stream.send(jp.xml(node))
 
     candidate_e, result_e =  q.expect_many(
@@ -128,11 +128,11 @@ def worker(jp, q, bus, conn, stream):
     # This is what pidgin does.
     node = jp.SetIq(jt2.peer, jt2.jid, [
         jp.Jingle(jt2.sid, jt2.peer, 'session-accept', [
-            jp.Content('Audio', 'initiator', 'both', [
+            jp.Content('Audio', 'initiator', 'both',
                 jp.Description('audio', [
                     jp.PayloadType(name, str(rate), str(id)) for
                         (name, id, rate) in jt2.audio_codecs ]),
-                transport ]) ]) ])
+                transport) ]) ])
     stream.send(jp.xml(node))
 
     candidate_e, result_e = q.expect_many(
-- 
1.5.6.5




More information about the telepathy-commits mailing list