Ejemplo n.º 1
0
    def coro():
        h = GNTPHandler(loop=loop)

        logging.debug('GNTP: unregister')
        response = yield from h.unregister(notifier, local_target)
        assert response['status'] == 'ERROR'
        assert response['reason'] == 'Unsupported'
Ejemplo n.º 2
0
    def coro():
        h = GNTPHandler(loop=loop)

        notifier.add_target(local_target)

        logging.debug('GNTP: register')
        response = yield from h.register(notifier, local_target)
        assert response['status'] == 'OK'
Ejemplo n.º 3
0
    def coro():
        h = GNTPHandler(loop=loop)
        notifier.icon = icon

        logging.debug('GNTP: register with icon')
        response = yield from h.register(notifier, local_target)
        assert response['status'] == 'OK'
        assert response['status_code'] == 0
Ejemplo n.º 4
0
    def coro():
        h = GNTPHandler(loop=loop)

        notification = notifier.create_notification(
            name='Old', title="With a string call back", text="Press me")
        notification.add_callback('callback_test')
        logging.debug('GNTP: notify with string callback')
        response = yield from h.notify(notification, local_target)
        assert response['status'] == 'OK'
Ejemplo n.º 5
0
    def coro():
        h = GNTPHandler(loop=loop)

        notification = notifier.create_notification(name='New',
                                                    title="With a call back",
                                                    text="Press me")
        notification.add_callback('http://news.bbc.co.uk')
        logging.debug('GNTP: notify with url callback')
        response = yield from h.notify(notification, local_target)
        assert response['status'] == 'OK'
Ejemplo n.º 6
0
    def coro():
        h = GNTPHandler(loop=loop)

        notification = notifier.create_notification(
            name='New',
            title="A brave new world",
            text=("This notification should "
                  "have an icon"),
            icon=icon_inverted)
        response = yield from h.notify(notification, local_target)
        assert response['status'] == 'OK'
Ejemplo n.º 7
0
    def coro():
        h = GNTPHandler(loop=loop)

        notification = notifier.create_notification(name='New',
                                                    title="A brave new world",
                                                    text="Say hello to Prism")
        logging.debug('GNTP: notify')
        response = yield from h.register(notifier, local_target)
        print(response)
        response = yield from h.notify(notification, local_target)
        print(response)
        assert response['status'] == 'OK'
        assert response['status_code'] == 0
Ejemplo n.º 8
0
    def add_target(self, targets):
        """Add a single target or list of targets to the known targets
        and connects to them

        :param targets: The Target or list of Targets to add.
        :type targets:  :class:`~hiss.target.Target`
        :returns:       Result dict or list of dict if more than one target added.
        """
        if isinstance(targets, Target):
            targets = [targets]

        if self.asynchronous:
            wait_for = []
            for target in targets:
                if target.scheme in self._handlers:
                    handler = self._handlers[target.scheme]
                elif target.scheme == 'snp':
                    handler = SNPHandler(self.loop)
                    self._handlers[target.scheme] = handler
                elif target.scheme == 'gntp':
                    handler = GNTPHandler(self.loop)
                    self._handlers[target.scheme] = handler
                elif target.scheme == 'xbmc':
                    handler = XBMCHandler()
                    self._handlers[target.scheme] = handler

                wait_for.append(handler.connect(target))

            done, _pending = yield from asyncio.wait(wait_for)

            results = []
            for task in done:
                tr = task.result()

                result = {}
                result['target'] = tr.target
                if result is None:
                    result['status'] = 'ERROR'
                    result['reason'] = 'Unable to connect to target'
                else:
                    result['status'] = 'OK'
                    self.targets.append(tr.target)

                results.append(result)
        else:
            self.targets.append(target)
            results = [dict(target=target,
                            status='OK')]

        if len(results) == 1:
            return results[0]
        else:
            return results
Ejemplo n.º 9
0
    def coro():
        h = GNTPHandler(loop=loop)

        n1 = notifier.create_notification(name='New',
                                          title="A brave new world",
                                          text="Say hello to Prism")
        n1.add_callback('callback_test')

        n2 = notifier.create_notification(name='Old',
                                          title="A second Coming",
                                          text="Say hello to the Time Lords")

        logging.debug('GNTP: multiply notify')
        done, pending = yield from asyncio.wait(
            [h.notify(n1, local_target),
             h.notify(n2, local_target)])

        for task in done:
            response = task.result()
            assert response['status'] == 'OK'
            assert response['status_code'] == 0
Ejemplo n.º 10
0
 def coro():
     h = GNTPHandler(loop=loop)
     logging.debug('GNTP: connect')
     yield from h.connect(local_target)
     assert local_target.handler == h
Ejemplo n.º 11
0
    def coro():
        h = GNTPHandler(loop=loop)
        t = Target('gntp://%s' % INVALID_HOST)

        with pytest.raises((ConnectionError, TimeoutError)):
            _protocol = yield from h.connect(t)