Exemple #1
0
    def __init__(
        self,
        host_frontend,
        port_frontend,
        host_backend,
        port_backend,
        name,
        mac,
        show_artwork,
        turn_off,
        timeout,
    ):
        """Initialize the MythTV API."""

        # Save a reference to the api
        self._host_frontend = host_frontend
        self._port_frontend = port_frontend
        self._api = api.Send(self._host_frontend, self._port_frontend)
        self._host_backend = host_backend
        self._port_backend = port_backend
        self._name = name
        self._show_artwork = show_artwork
        self._frontend = {}
        self._mac = mac
        self._wol = wakeonlan
        self._volume = {"control": False, "level": 0, "muted": False}
        self._state = STATE_UNKNOWN
        self._last_playing_title = None
        self._media_image_url = None
        self._be = api.Send(host=host_backend, port=port_backend)
        self._fe = api.Send(host=host_frontend, port=port_frontend)
        self._turn_off = turn_off
        self._timeout = timeout
    def __init__(self, hass, host_frontend, port_frontend, origin, timeout):
        """Initialize the MythTV Services API."""

        # Save a reference to the api
        self._api = api
        self._host_frontend = host_frontend
        self._port_frontend = port_frontend
        self._origin = origin
        self._timeout = timeout
        self._fe = api.Send(host=host_frontend, port=port_frontend)

        _LOGGER.debug("Setup MythTV Notifications %s", self._host_frontend)
    def test_access(self):
        '''
        Do additional basic access tests that setUp() doesn't need to
        do every time it's called.
        '''

        self.assertTrue(BACKEND.server_version == TEST_SERVER_VERSION)
        self.assertIsInstance(BACKEND.get_headers(),
                              requests.structures.CaseInsensitiveDict)

        BACKEND.close_session()
        with self.assertRaisesRegex(RuntimeError, 'Missing host argument'):
            api.Send(host=None)
 def __init__(self, host_frontend, port_frontend, host_backend,
              port_backend, name, mac, show_artwork, turn_off):
     """Initialize the MythTV API."""
     from mythtv_services_api import send as api
     import wakeonlan
     # Save a reference to the api
     self._host_frontend = host_frontend
     self._port_frontend = port_frontend
     self._api = api.Send(self._host_frontend, self._port_frontend)
     self._host_backend = host_backend
     self._port_backend = port_backend
     self._name = name
     self._show_artwork = show_artwork
     self._frontend = {}
     self._mac = mac
     self._wol = wakeonlan
     self._volume = {'control': False, 'level': 0, 'muted': False}
     self._state = STATE_UNKNOWN
     self._last_playing_title = None
     self._media_image_url = None
     self._be = api.Send(host=host_backend, port=port_backend)
     self._fe = api.Send(host=host_frontend, port=port_frontend)
     self._turn_off = turn_off
    def test_default_opts(self):
        '''
        Test default option values

        All default values are False except timeout, which is 10.
        '''

        global BACKEND

        for key, value in BACKEND.get_opts.items():
            if key is 'timeout':
                self.assertEqual(value, 10)
            elif key is 'user' or key is 'pass':
                pass
            else:
                self.assertFalse(value)

        response = '{"String": "' + TEST_DVR_VERSION + '"}'
        self.assertEqual(
            BACKEND.send(endpoint=TEST_ENDPOINT, opts={'wsdl': True}),
            {'WSDL': response})

        session_options = {
            # option: expect
            'noetag': "{'String': ",
            'nogzip': "{'String': ",
            'usexml': '<?xml version="1.0" encoding="UTF-8"?><String>',
        }

        expected_headers = {
            # option: header, value (0, 1)
            'noetag': ('If-None-Match', ''),
            'nogzip': ('Accept-Encoding', ''),
            'usexml': ('Accept', ''),
        }

        for option, expect in session_options.items():
            BACKEND.close_session()
            BACKEND = api.Send(host=TEST_HOST)
            opts = {option: True, 'user': '******', 'pass': '******'}
            response = str(BACKEND.send(endpoint=TEST_ENDPOINT, opts=opts))

            self.assertIn(expect, response)

            self.assertEqual(
                BACKEND.get_headers(header=expected_headers[option][0]),
                expected_headers[option][1])
    def setUp(self):
        '''
        Called before every one of the following test_*()s. Guarantee
        that the session's options are set to their default values
        and that the UTC offset is set.
        '''

        global BACKEND

        # self.longMessage = True

        if BACKEND:
            BACKEND.close_session()

        opts = {'user': '******', 'pass': '******'}
        BACKEND = api.Send(host=TEST_HOST)
        self.assertIsInstance(BACKEND, api.Send)
        self.assertEqual(
            BACKEND.send(endpoint=TEST_ENDPOINT, opts=opts)['String'],
            TEST_DVR_VERSION)
        self.assertEqual(util.get_utc_offset(backend=BACKEND), TEST_UTC_OFFSET)
    def test_digest(self):
        '''
        Verify that bad digest user and passwords fail.
        '''

        global BACKEND

        # Save the existing protected service(s)...
        BACKEND.close_session()
        BACKEND = api.Send(host=TEST_HOST)
        kwargs = {
            'opts': {
                'user': '******',
                'pass': '******',
                'wrmi': True
            },
            'postdata': {
                'Key': 'HTTP/Protected/Urls',
                'HostName': '_GLOBAL_'
            }
        }
        value = BACKEND.send(endpoint='Myth/GetSetting', **kwargs)['String']
        self.assertIsNotNone(value)

        url_protection = 'Myth/ManageUrlProtection'

        # Turn authentication on...
        kwargs = {
            'opts': {
                'user': '******',
                'pass': '******',
                'wrmi': True
            },
            'postdata': {
                'Services': 'All',
                'AdminPassword': '******'
            }
        }
        self.assertEqual(BACKEND.send(endpoint=url_protection, **kwargs),
                         {'bool': 'true'})

        # Create a new session and try a POST with an invalid password...
        BACKEND.close_session()
        BACKEND = api.Send(host=TEST_HOST)
        kwargs = {
            'opts': {
                'user': '******',
                'pass': '******',
                'wrmi': True
            },
            'postdata': {
                'Services': 'All',
                'AdminPassword': '******'
            }
        }
        with self.assertRaisesRegex(RuntimeError,
                                    r'Unauthorized \(401\)..*password'):
            BACKEND.send(endpoint=url_protection, **kwargs)

        # Turn authentication back off...
        BACKEND.close_session()
        BACKEND = api.Send(host=TEST_HOST)
        kwargs = {
            'opts': {
                'user': '******',
                'pass': '******',
                'wrmi': True
            },
            'postdata': {
                'Services': 'None',
                'AdminPassword': '******'
            }
        }
        self.assertEqual(BACKEND.send(endpoint=url_protection, **kwargs),
                         {'bool': 'true'})