[telepathy-gabble/telepathy-gabble-0.8] Reduce content-naming assumptions in Jingle tests

Will Thompson will.thompson at collabora.co.uk
Wed Sep 2 10:12:35 PDT 2009


Now that we extract the stream names from session-initiate, let's fill them
in in incoming_call() too, and then generate_contents() can use those
rather than hard-coding stream1 and stream2.
---
 tests/twisted/jingle/hold-av.py                    |    2 +-
 tests/twisted/jingle/jingletest2.py                |   53 ++++++++++---------
 .../twisted/jingle/test-content-adding-removal.py  |    2 +-
 tests/twisted/jingle/test-content-complex.py       |    3 +-
 tests/twisted/jingle/test-description-info.py      |   10 +++-
 5 files changed, 38 insertions(+), 32 deletions(-)

diff --git a/tests/twisted/jingle/hold-av.py b/tests/twisted/jingle/hold-av.py
index 44db6d1..f59cd4e 100644
--- a/tests/twisted/jingle/hold-av.py
+++ b/tests/twisted/jingle/hold-av.py
@@ -165,7 +165,7 @@ def test(jp, q, bus, conn, stream):
     stream.send(make_result_iq(stream, e.stanza))
 
     jt.parse_session_initiate(e.query)
-    jt.accept(with_video=True)
+    jt.accept()
 
     q.expect('stream-iq', iq_type='result')
 
diff --git a/tests/twisted/jingle/jingletest2.py b/tests/twisted/jingle/jingletest2.py
index 829c84b..b8a07f9 100644
--- a/tests/twisted/jingle/jingletest2.py
+++ b/tests/twisted/jingle/jingletest2.py
@@ -486,35 +486,19 @@ class JingleTest2:
         # Force Gabble to process the caps before doing any more Jingling
         sync_stream(self.q, self.stream)
 
-    def generate_contents (self, audio = True, video = False):
-        assert audio or video
+    def generate_contents(self):
+        assert len(self.audio_names + self.video_names) > 0
 
         jp = self.jp
 
-        assert not video or jp.can_do_video()
+        assert len(self.video_names) == 0 or jp.can_do_video()
 
         contents = []
 
-        if jp.seperate_contents() or not audio or not video:
-            assert audio or video
-            if audio:
-                contents.append(
-                    jp.Content('stream1', 'initiator', 'both', [
-                        jp.Description('audio', [
-                            jp.PayloadType(name, str(rate), str(id)) for
-                            (name, id, rate) in self.audio_codecs ]),
-                    jp.TransportGoogleP2P() ])
-                )
-            if video:
-                contents.append(
-                    jp.Content('stream2', 'initiator', 'both', [
-                        jp.Description('video', [
-                            jp.PayloadType(name, str(rate), str(id)) for
-                            (name, id, rate) in self.video_codecs ]),
-                    jp.TransportGoogleP2P() ])
-                )
-        else:
+        if not jp.seperate_contents() and self.video_names:
             assert jp.can_do_video()
+            assert self.audio_names
+
             contents.append(
                 jp.Content('stream0', 'initiator', 'both', [
                     jp.Description('video', [
@@ -526,12 +510,31 @@ class JingleTest2:
                         ),
                     jp.TransportGoogleP2P() ])
              )
+        else:
+            def mk_content(name, media, codecs):
+                contents.append(
+                    jp.Content(name, 'initiator', 'both', [
+                        jp.Description(media, [
+                            jp.PayloadType(name, str(rate), str(id)) for
+                            (name, id, rate) in codecs ]),
+                    jp.TransportGoogleP2P() ])
+                )
+
+            for name in self.audio_names:
+                mk_content(name, 'audio', self.audio_codecs)
+
+            for name in self.video_names:
+                mk_content(name, 'video', self.video_codecs)
 
         return contents
 
     def incoming_call(self, audio=True, video=False):
         jp = self.jp
-        contents = self.generate_contents(audio, video)
+
+        self.audio_names = ['audio1'] if audio else []
+        self.video_names = ['video1'] if video else []
+
+        contents = self.generate_contents()
 
         node = jp.SetIq(self.peer, self.jid, [
             jp.Jingle(self.sid, self.peer, 'session-initiate', contents),
@@ -543,10 +546,10 @@ class JingleTest2:
         self.sid, self.audio_names, self.video_names = \
             self.jp.validate_session_initiate(query)
 
-    def accept(self, with_video=False):
+    def accept(self):
         jp = self.jp
 
-        contents = self.generate_contents(True, with_video)
+        contents = self.generate_contents()
         node = jp.SetIq(self.peer, self.jid, [
             jp.Jingle(self.sid, self.peer, 'session-accept',
                 contents) ])
diff --git a/tests/twisted/jingle/test-content-adding-removal.py b/tests/twisted/jingle/test-content-adding-removal.py
index ab95374..15251ed 100644
--- a/tests/twisted/jingle/test-content-adding-removal.py
+++ b/tests/twisted/jingle/test-content-adding-removal.py
@@ -75,7 +75,7 @@ def test(jp, q, bus, conn, stream, peer_removes_final_content):
     e2 = q.expect('stream-iq', predicate=jp.action_predicate('content-remove'))
 
     # ...but before the peer notices, they accept the call.
-    jt.accept(with_video=True)
+    jt.accept()
 
     # Only now the remote end removes the video stream; if gabble mistakenly
     # marked it as accepted on session acceptance, it'll crash right about
diff --git a/tests/twisted/jingle/test-content-complex.py b/tests/twisted/jingle/test-content-complex.py
index 6b760c3..de4462b 100644
--- a/tests/twisted/jingle/test-content-complex.py
+++ b/tests/twisted/jingle/test-content-complex.py
@@ -123,11 +123,10 @@ def worker(jp, q, bus, conn, stream):
     else:
         q.expect('stream-iq', iq_type='error')
 
-
     # 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('stream1', '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 ]),
diff --git a/tests/twisted/jingle/test-description-info.py b/tests/twisted/jingle/test-description-info.py
index ba30a68..939e71c 100644
--- a/tests/twisted/jingle/test-description-info.py
+++ b/tests/twisted/jingle/test-description-info.py
@@ -143,11 +143,15 @@ def test(q, bus, conn, stream, send_early_description_info=False):
                    ('PCMU', 0, 8000, {}) ]
     stream_handler.CodecsUpdated(jt2.dbusify_codecs_with_params(new_codecs))
 
+    audio_content = jt2.audio_names[0]
+
     e = q.expect('stream-iq', iq_type='set', predicate=lambda x:
         xpath.queryForNodes("/iq/jingle[@action='description-info']",
             x.stanza))
     payload_types = xpath.queryForNodes(
-        "/iq/jingle/content[@name='stream1']/description/payload-type", e.stanza)
+        "/iq/jingle/content[@name='%s']/description/payload-type"
+            % audio_content,
+        e.stanza)
     # Gabble SHOULD only include the changed codecs in description-info
     assert len(payload_types) == 2, payload_types
 
@@ -162,7 +166,7 @@ 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('stream1', 'initiator', 'both', [
+            jp.Content(audio_content, 'initiator', 'both', [
                 jp.Description('audio', [
                     jp.PayloadType('PCMU', '1600', '0') ]) ]) ]) ])
     stream.send(jp.xml(node))
@@ -178,7 +182,7 @@ 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('stream1', 'initiator', 'both', [
+            jp.Content(audio_content, 'initiator', 'both', [
                 jp.Description('audio', [
                     jp.PayloadType(c[0], str(c[2]), str(c[1]), c[3])
                 ]) ]) ]) ])
-- 
1.5.6.5




More information about the telepathy-commits mailing list