def test_setup_incomplete_config(self):
     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))
Exemple #2
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))
Exemple #3
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'),
     ])
Exemple #4
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'),
        ])
    def test_setup_full_config(self, mock_uvc, mock_remote):
        config = {
            'nvr': 'foo',
            'port': 123,
            'key': 'secret',
        }
        fake_cameras = [
            {'uuid': 'one', 'name': 'Front'},
            {'uuid': 'two', 'name': 'Back'},
            {'uuid': 'three', 'name': 'Old AirCam'},
        ]

        def fake_get_camera(uuid):
            if uuid == 'three':
                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
        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, 'one', 'Front'),
            mock.call(mock_remote.return_value, 'two', 'Back'),
        ])
 def test_setup_nvr_errors(self, mock_remote):
     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))
Exemple #7
0
 def test_setup_nvr_errors(self, mock_remote):
     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))
Exemple #8
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'),
        ])
 def test_setup_partial_config(self, mock_uvc, mock_remote):
     config = {
         'nvr': 'foo',
         'key': 'secret',
     }
     fake_cameras = [
         {'uuid': 'one', 'name': 'Front'},
         {'uuid': 'two', 'name': 'Back'},
     ]
     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'}
     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'),
     ])
Exemple #10
0
    def test_setup_full_config(self, mock_uvc, mock_remote):
        config = {
            'nvr': 'foo',
            'port': 123,
            'key': 'secret',
        }
        fake_cameras = [
            {
                'uuid': 'one',
                'name': 'Front'
            },
            {
                'uuid': 'two',
                'name': 'Back'
            },
            {
                'uuid': 'three',
                'name': 'Old AirCam'
            },
        ]

        def fake_get_camera(uuid):
            if uuid == 'three':
                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
        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, 'one', 'Front'),
            mock.call(mock_remote.return_value, 'two', 'Back'),
        ])
Exemple #11
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))
Exemple #12
0
 def test_setup_incomplete_config(self):
     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))