def test_Browse(self):
        """ tries to find the activated FSStore backend
            and browses its root.
        """
        d = Deferred()

        @wrapped(d)
        def the_result(mediaserver):
            cdc = mediaserver.client.content_directory
            self.assertEqual(self.uuid, mediaserver.udn)
            call = cdc.browse(process_result=False)
            call.addCallback(got_first_answer, cdc)

        @wrapped(d)
        def got_first_answer(r, cdc):
            self.assertEqual(int(r['TotalMatches']), 1)
            didl = DIDLLite.DIDLElement.fromString(r['Result'])
            item = didl.getItems()[0]
            self.assertEqual(item.childCount, 3)
            call = cdc.browse(object_id=item.id, process_result=False)
            call.addCallback(got_second_answer, item.childCount)

        @wrapped(d)
        def got_second_answer(r, childcount):
            self.assertEqual(int(r['TotalMatches']), childcount)
            d.callback(None)

        self.coherence.ctrl.add_query(
            DeviceQuery('uuid',
                        self.uuid,
                        the_result,
                        timeout=10,
                        oneshot=True))
        return d
    def test_XBOX_Browse_Metadata(self):
        """ tries to find the activated FSStore backend
            and requests metadata for ObjectID 0.
        """
        d = Deferred()

        @wrapped(d)
        def the_result(mediaserver):
            mediaserver.client.overlay_headers = {
                'user-agent': 'Xbox/Coherence emulation'
            }
            cdc = mediaserver.client.content_directory
            self.assertEqual(self.uuid, mediaserver.udn)
            call = cdc.browse(object_id='0',
                              browse_flag='BrowseMetadata',
                              process_result=False)
            call.addCallback(got_first_answer)

        @wrapped(d)
        def got_first_answer(r):
            """ we expect one item here """
            self.assertEqual(int(r['TotalMatches']), 1)
            didl = DIDLLite.DIDLElement.fromString(r['Result'])
            item = didl.getItems()[0]
            self.assertEqual(item.title, 'root')
            d.callback(None)

        self.coherence.ctrl.add_query(
            DeviceQuery('uuid',
                        self.uuid,
                        the_result,
                        timeout=10,
                        oneshot=True))
        return d
    def test_XBOX_Search(self):
        """ tries to find the activated FSStore backend
            and searches for all its audio files.
        """

        d = Deferred()

        @wrapped(d)
        def the_result(mediaserver):
            mediaserver.client.overlay_headers = {
                'user-agent': 'Xbox/Coherence emulation'
            }
            cdc = mediaserver.client.content_directory
            self.assertEqual(self.uuid, mediaserver.udn)
            call = cdc.search(container_id='4', criteria='')
            call.addCallback(got_first_answer)

        @wrapped(d)
        def got_first_answer(r):
            """ we expect four audio files here """
            self.assertEqual(len(r), 4)
            d.callback(None)

        self.coherence.ctrl.add_query(
            DeviceQuery('uuid',
                        self.uuid,
                        the_result,
                        timeout=10,
                        oneshot=True))
        return d
    def test_XBOX_Browse(self):
        """ tries to find the activated FSStore backend
            and browses all audio files.
        """
        d = Deferred()

        @wrapped(d)
        def the_result(mediaserver):
            mediaserver.client.overlay_headers = {
                'user-agent': 'Xbox/Coherence emulation'
            }
            cdc = mediaserver.client.content_directory
            self.assertEqual(self.uuid, mediaserver.udn)
            call = cdc.browse(object_id='4', process_result=False)
            call.addCallback(got_first_answer)

        @wrapped(d)
        def got_first_answer(r):
            """ we expect four audio files here """
            self.assertEqual(int(r['TotalMatches']), 4)
            d.callback(None)

        d = Deferred()
        self.coherence.ctrl.add_query(
            DeviceQuery('uuid',
                        self.uuid,
                        the_result,
                        timeout=10,
                        oneshot=True))
        return d
    def test_XBOX_Browse(self):
        """ tries to find the activated FSStore backend
            and browses all audio files.
        """
        d = Deferred()

        def the_result(mediaserver):
            try:
                self.assertEqual(str(self.uuid), mediaserver.udn)
            except:
                d.errback()

            def got_first_answer(r):
                """ we expect four audio files here """
                try:
                    self.assertEqual(int(r['TotalMatches']), 4)
                except:
                    d.errback()
                    return
                d.callback(None)

            def my_browse(*args, **kwargs):
                kwargs['ContainerID'] = kwargs['ObjectID']
                del kwargs['ObjectID']
                del kwargs['BrowseFlag']
                kwargs['SearchCriteria'] = ''
                return 'Search', kwargs

            #mediaserver.client.overlay_actions = {'Browse':my_browse}
            mediaserver.client.overlay_headers = {
                'user-agent': 'Xbox/Coherence emulation'
            }

            call = mediaserver.client.content_directory.browse(
                object_id='4', process_result=False)
            call.addCallback(got_first_answer)
            call.addErrback(lambda x: d.errback(None))

        self.coherence.ctrl.add_query(
            DeviceQuery('uuid',
                        str(self.uuid),
                        the_result,
                        timeout=10,
                        oneshot=True))
        return d
Esempio n. 6
0
    def test_Browse_Non_Existing_Object(self):

        d = Deferred()

        @wrapped(d)
        def the_result(mediaserver):
            cdc = mediaserver.client.content_directory
            self.assertEqual(self.uuid, mediaserver.udn)
            call = cdc.browse(object_id='9999.nothing', process_result=False)
            call.addCallback(got_first_answer)

        @wrapped(d)
        def got_first_answer(r):
            self.assertIs(r, None)
            d.callback(None)

        self.coherence.ctrl.add_query(
            DeviceQuery('uuid', self.uuid, the_result,
                        timeout=10, oneshot=True))
        return d
    def test_get_state(self):
        """ tries to find the activated SimpleLight backend
            and queries its state.
            The state is expected to be "off"
        """
        d = Deferred()

        def the_result(r):
            #print "the_result", r
            self.assertEqual(str(self.uuid), r.udn)

            call = r.client.switch_power.get_status()
            def got_answer(r):
                self.assertEqual(int(r['ResultStatus']), 0)
                d.callback(None)

            call.addCallback(got_answer)

        self.coherence.ctrl.add_query(DeviceQuery('uuid', str(self.uuid), the_result, timeout=10, oneshot=True))
        return d
    def test_Browse_Metadata(self):
        """ tries to find the activated FSStore backend
            and requests metadata for ObjectID 0.
        """
        d = Deferred()

        def the_result(mediaserver):
            try:
                self.assertEqual(str(self.uuid), mediaserver.udn)
            except:
                d.errback()

            def got_first_answer(r):
                try:
                    self.assertEqual(int(r['TotalMatches']), 1)
                except:
                    d.errback()
                    return
                didl = DIDLLite.DIDLElement.fromString(r['Result'])
                item = didl.getItems()[0]
                try:
                    self.assertEqual(item.title, 'root')
                except:
                    d.errback()
                    return
                d.callback(None)

            call = mediaserver.client.content_directory.browse(
                object_id='0',
                browse_flag='BrowseMetadata',
                process_result=False)
            call.addCallback(got_first_answer)
            call.addErrback(lambda x: d.errback(None))

        self.coherence.ctrl.add_query(
            DeviceQuery('uuid',
                        str(self.uuid),
                        the_result,
                        timeout=10,
                        oneshot=True))
        return d