cdffd680be5e — Oben Sonne 10 years ago
server: more bong session tests
2 files changed, 60 insertions(+), 4 deletions(-)

M server/src/tests/bong.py
M server/src/tests/test_bongsession.py
M server/src/tests/bong.py +8 -4
@@ 49,7 49,7 @@ class Bong(dbus.service.Object):
         for k, v in x.items():
             if k.startswith("info_"):
                 continue
-            if self.x.get(k, None) != v:  # FIXME: fails on playlist changes
+            if self.x.get(k, None) != v:
                 log("%s changed: %s" % (k, v))
                 self.x[k] = v
                 if k == "library":

          
@@ 185,7 185,8 @@ class Bong(dbus.service.Object):
             return # TODO: how to pass errors to server? DBusException?
         position = self.x.get('position', 0)
         playlist = self.x['playlist']
-        if self.x.get('repeat', self.features.get('repeatmodes', ['disabled'])[0]) != 'disabled':
+        repeatmodes = self.x.get('info_repeatmodes', ['off'])
+        if self.x.get('repeat', repeatmodes[0]) == 'list':
             newpos = (position + n) % len(playlist)
         else:
             newpos = max(0, min(len(playlist) - 1, position + n))

          
@@ 215,11 216,14 @@ class Bong(dbus.service.Object):
 
     @dbus.service.method(IFACE, 'u', '')
     def SetRating(self, value):
-        playlist = self.x.get('playlist', [])
+        playlist = self.x.get('playlist', [])[:]
         if not playlist:
             return
         position = self.x.get('position', 0)
-        playlist[position]['rating'] = value
+        tid, title, meta = playlist[position]
+        rmax = meta.get('rating', [0,0])[1]
+        meta['rating'] = [value, rmax]
+        playlist[position] = [tid, title, meta]
         self.changestate('playlist', playlist)
 
     # -------------------------------------------------------------------------

          
M server/src/tests/test_bongsession.py +52 -0
@@ 437,6 437,58 @@ def test_playercontrol():
         - mode: track
     """) # shuffle did not change -> no update
 
+    p.update("""
+        playlist:
+          - - UID1
+            - TITLE1
+            - artist: ARTIST1
+              album: ALBUM1
+              rating: [4, 5]
+          - - UID2
+            - TITLE2
+            - artist: ARTIST2
+              album: ALBUM2
+          - - UID3
+            - TITLE3
+            - duration: 20
+    """)
+    c.exp("""
+        - updatetrack
+        - title: TITLE1
+          artist: ARTIST1
+          album: ALBUM1
+          uid: UID1
+          rating: [4, 5]
+    """)
+
+    # change rating, skip to next and then to previous, check changed rating
+    c.snd("""
+        - setrating
+        - value: 0
+
+        - playnext
+        - {}
+    """)
+    c.exp("""
+        - updatetrack
+        - title: TITLE2
+          artist: ARTIST2
+          album: ALBUM2
+          uid: UID2
+    """)
+    c.snd("""
+        - playprevious
+        - {}
+    """)
+    c.exp("""
+        - updatetrack
+        - title: TITLE1
+          artist: ARTIST1
+          album: ALBUM1
+          uid: UID1
+          rating: [0, 5]
+    """)
+
     c.disconnect()
     p.stop()
     s.stop()