Esempio n. 1
0
    def status( self, medianame='name-required', status='item-required' ):
        """
        Return status of a media server
        """
        result = ClientProfiles.makeStandardResponse( cherrypy.request )

        self.__log.debug( 'MediaAccess.status %s, %s ' % (medianame, status) )
        result['stserr'] = None
        result['mediaName'] = medianame

        try :
            if ( status == 'vol' ):
                xmlStr = MediaSet.volume( self, medianame )
            elif ( status == 'playlist' ):
                 xmlStr = MediaSet.playlist( self, medianame )
            elif ( status == 'playlists' ):
                xmlStr = MediaSet.playlists( self, medianame )
            elif ( status == 'position' ):
                xmlStr = MediaSet.status( self, medianame )
            else:
                xmlStr = MediaSet.status( self, medianame )
            self.__log.debug( '%s:%s - xmlString %s' % (medianame, status, xmlStr) )
            xml = parseXmlString( xmlStr )

            if ( status == 'position' ):
                result['position'] = getNamedNodeText( xml, 'position' )
                result['duration'] = getNamedNodeText( xml, 'duration' )

            elif ( status == 'vol' ):
                result['vol'] = getNamedNodeText( xml, status )

            elif ( status == 'playlist' ):
                result['playlist'] = getElemXml( getNamedElem( xml, status ) )

            elif ( status == 'playlists' ):
                result['playlists'] = getElemXml( getNamedElem( xml, status ) )

            elif ( status == 'track' ):
                result['track'] = getNamedNodeText( xml, status )

            else:
                result[str(status)] = getNamedNodeText( xml, status )
        except Exception, ex :
            self.__log.exception( 'Error %s, %s ' % (medianame, status) )
            result['stserr'] = "unknown"
Esempio n. 2
0
class TestMediaSet(unittest.TestCase):

    def setUp(self):
        self._mediaSet = MediaSet()
        self._mediaSet.configure( parseXmlString(testConfigMediaSet) )
        return

    def tearDown(self):
        return

    def assertUnicode( self, str, match ):
        self.assertEqual( type(str), types.UnicodeType )
        self.assertEqual( type(match), types.UnicodeType )
        self.assertEqual( str, match )

    # Actual tests follow
    def testGetStatus(self):
        self.assertUnicode( self._mediaSet.status( "AccessGood" ), u'<status name="AccessGood"><state>1</state><track>Test Track</track><position>119</position><duration>500</duration></status>' )
        self.assertEqual( self._mediaSet.status( "AccessBad" ), None )
        self.assertUnicode( self._mediaSet.status( "noKnownInterface" ), u'<error>No Such Interface noKnownInterface</error>' )

        self.assertUnicode( self._mediaSet.volume( "AccessGood" ), u'<vol>40</vol>' )
        self.assertEqual( self._mediaSet.volume( "AccessBad" ), None )
        self.assertUnicode( self._mediaSet.volume( "noKnownInterface" ), u'<error>No Such Interface noKnownInterface</error>' )

    def testCommands(self):
        self.assertEqual( self._mediaSet.command("AccessGood", "stop"), None )
        self.assertUnicode( self._mediaSet.command("AccessBad", "stop"), u'<error>Error</error>' )

        self.assertEqual( self._mediaSet.command("AccessGood", "play"), None )
        self.assertUnicode( self._mediaSet.command("AccessBad", "play"), u'<error>Error</error>' )

        self.assertEqual( self._mediaSet.command("AccessGood", "pause"), None )
        self.assertUnicode( self._mediaSet.command("AccessBad", "pause"), u'<error>Error</error>' )

        self.assertEqual( self._mediaSet.command("AccessGood", "togglePause"), None )
        self.assertUnicode( self._mediaSet.command("AccessBad", "togglePause"), u'<error>Error</error>' )

        self.assertEqual( self._mediaSet.command("AccessGood", "next"), None )
        self.assertUnicode( self._mediaSet.command("AccessBad", "next"), u'<error>Error</error>' )

        self.assertEqual( self._mediaSet.command("AccessGood", "prev"), None )
        self.assertUnicode( self._mediaSet.command("AccessBad", "prev"), u'<error>Error</error>' )

        self.assertEqual( self._mediaSet.command("AccessGood", "forward"), None )
        self.assertUnicode( self._mediaSet.command("AccessBad", "forward"), u'<error>Error</error>' )

        self.assertEqual( self._mediaSet.command("AccessGood", "rewind"), None )
        self.assertUnicode( self._mediaSet.command("AccessBad", "rewind"), u'<error>Error</error>' )

        self.assertEqual( self._mediaSet.setPosition( "AccessGood", 100), None )
        self.assertUnicode( self._mediaSet.setPosition("AccessBad", 100), u'Error' )

        self.assertEqual( self._mediaSet.setVolume( "AccessGood", 100), None )
        self.assertUnicode( self._mediaSet.setVolume("AccessBad", 100), u'Error' )

        self.assertEqual( self._mediaSet.selectPlaylist("AccessGood", '1.1'), None )
        self.assertUnicode( self._mediaSet.selectPlaylist("AccessBad",'1.1'), u'Error' )

        self.assertEqual( self._mediaSet.selectTrack("AccessGood", '1.1.1'), None )
        self.assertUnicode( self._mediaSet.selectTrack("AccessBad", '1.1.1'), u'Error' )

        self.assertEqual( self._mediaSet.command("AccessGood", "toggleMute"), None )
        self.assertUnicode( self._mediaSet.command("AccessBad", "toggleMute"), u'<error>Error</error>' )

        self.assertEqual( self._mediaSet.command("AccessGood", "volup"), None )
        self.assertUnicode( self._mediaSet.command("AccessBad", "volup"), u'<error>Error</error>' )

        self.assertEqual( self._mediaSet.command("AccessGood", "voldown"), None )
        self.assertUnicode( self._mediaSet.command("AccessBad", "voldown"), u'<error>Error</error>' )

        self.assertUnicode( self._mediaSet.command("AccessGood", "xxCommand"), u"<error>No Such Command xxCommand</error>" )
        self.assertUnicode( self._mediaSet.command("AccessBad", "xxCommand"), u"<error>No Such Command xxCommand</error>" )

    def testPlaylist(self):
        # first the playlists array
        self.assertUnicode( self._mediaSet.playlists("AccessGood"), u'<playlists><playlist id="1.1" current="yes">Playlist 1</playlist><playlist id="1.2">Playlist 2</playlist></playlists>' )
        self.assertEqual( self._mediaSet.playlists("AccessBad"), None )
       
        self.assertUnicode( self._mediaSet.playlist("AccessGood"), u'<playlist><track id="1.1.1" current="yes">Track 1</track><track id="1.1.2">Track 2</track><track id="1.1.3">Track 3</track></playlist>' )
        self.assertEqual( self._mediaSet.playlist("AccessBad"), None )