Ejemplo n.º 1
0
 def test_setup_incomplete_config(self):
     """"Test the setup with incomplete configuration."""
     self.assertFalse(uvc.setup_platform(
         None, {'nvr': 'foo'}, None))
     self.assertFalse(uvc.setup_platform(
         None, {'key': 'secret'}, None))
     self.assertFalse(uvc.setup_platform(
         None, {'port': 'invalid'}, None))
Ejemplo n.º 2
0
    def test_setup_full_config(self, mock_uvc, mock_remote):
        """"Test the setup with full configuration."""
        config = {
            'nvr': 'foo',
            'port': 123,
            'key': 'secret',
        }
        fake_cameras = [
            {'uuid': 'one', 'name': 'Front', 'id': 'id1'},
            {'uuid': 'two', 'name': 'Back', 'id': 'id2'},
            {'uuid': 'three', 'name': 'Old AirCam', 'id': 'id3'},
        ]

        def fake_get_camera(uuid):
            """"Create a fake camera."""
            if uuid == 'id3':
                return {'model': 'airCam'}
            else:
                return {'model': 'UVC'}

        hass = mock.MagicMock()
        add_devices = mock.MagicMock()
        mock_remote.return_value.index.return_value = fake_cameras
        mock_remote.return_value.get_camera.side_effect = fake_get_camera
        mock_remote.return_value.server_version = (3, 2, 0)
        self.assertTrue(uvc.setup_platform(hass, config, add_devices))
        mock_remote.assert_called_once_with('foo', 123, 'secret')
        add_devices.assert_called_once_with([
            mock_uvc.return_value, mock_uvc.return_value])
        mock_uvc.assert_has_calls([
            mock.call(mock_remote.return_value, 'id1', 'Front'),
            mock.call(mock_remote.return_value, 'id2', 'Back'),
        ])
Ejemplo n.º 3
0
 def test_setup_nvr_errors(self, mock_remote):
     """"Test for NVR errors."""
     errors = [nvr.NotAuthorized, nvr.NvrError,
               requests.exceptions.ConnectionError]
     config = {
         'nvr': 'foo',
         'key': 'secret',
     }
     for error in errors:
         mock_remote.return_value.index.side_effect = error
         self.assertFalse(uvc.setup_platform(None, config, None))
Ejemplo n.º 4
0
 def test_setup_partial_config_v31x(self, mock_uvc, mock_remote):
     """Test the setup with a v3.1.x server."""
     config = {
         'nvr': 'foo',
         'key': 'secret',
     }
     fake_cameras = [
         {'uuid': 'one', 'name': 'Front', 'id': 'id1'},
         {'uuid': 'two', 'name': 'Back', 'id': 'id2'},
     ]
     hass = mock.MagicMock()
     add_devices = mock.MagicMock()
     mock_remote.return_value.index.return_value = fake_cameras
     mock_remote.return_value.get_camera.return_value = {'model': 'UVC'}
     mock_remote.return_value.server_version = (3, 1, 3)
     self.assertTrue(uvc.setup_platform(hass, config, add_devices))
     mock_remote.assert_called_once_with('foo', 7080, 'secret')
     add_devices.assert_called_once_with([
         mock_uvc.return_value, mock_uvc.return_value])
     mock_uvc.assert_has_calls([
         mock.call(mock_remote.return_value, 'one', 'Front'),
         mock.call(mock_remote.return_value, 'two', 'Back'),
     ])