示例#1
0
def test_config_full(hass, mock_scanner, mock_ctrl):
    """Test the setup with full configuration."""
    config = {
        DOMAIN:
        unifi.PLATFORM_SCHEMA({
            CONF_PLATFORM: unifi.DOMAIN,
            CONF_USERNAME: '******',
            CONF_PASSWORD: '******',
            CONF_HOST: 'myhost',
            CONF_VERIFY_SSL: False,
            CONF_MONITORED_CONDITIONS: ['essid', 'signal'],
            'port': 123,
            'site_id': 'abcdef01',
            'detection_time': 300,
        })
    }
    result = unifi.get_scanner(hass, config)
    assert mock_scanner.return_value == result
    assert mock_ctrl.call_count == 1
    assert mock_ctrl.call_args == \
        mock.call('myhost', 'foo', 'password', 123,
                  version='v4', site_id='abcdef01', ssl_verify=False)

    assert mock_scanner.call_count == 1
    assert mock_scanner.call_args == mock.call(
        mock_ctrl.return_value, DEFAULT_DETECTION_TIME, None,
        config[DOMAIN][CONF_MONITORED_CONDITIONS])
示例#2
0
def test_config_valid_verify_ssl(hass, mock_scanner, mock_ctrl):
    """Test the setup with a string for ssl_verify.

    Representing the absolute path to a CA certificate bundle.
    """
    config = {
        DOMAIN:
        unifi.PLATFORM_SCHEMA({
            CONF_PLATFORM: unifi.DOMAIN,
            CONF_USERNAME: '******',
            CONF_PASSWORD: '******',
            CONF_VERIFY_SSL: "/tmp/unifi.crt"
        })
    }
    result = unifi.get_scanner(hass, config)
    assert mock_scanner.return_value == result
    assert mock_ctrl.call_count == 1
    assert mock_ctrl.mock_calls[0] == \
        mock.call('localhost', 'foo', 'password', 8443,
                  version='v4', site_id='default', ssl_verify="/tmp/unifi.crt")

    assert mock_scanner.call_count == 1
    assert mock_scanner.call_args == mock.call(mock_ctrl.return_value,
                                               DEFAULT_DETECTION_TIME, None,
                                               None)
示例#3
0
def test_config_error():
    """Test for configuration errors."""
    with pytest.raises(vol.Invalid):
        unifi.PLATFORM_SCHEMA({
            # no username
            CONF_PLATFORM: unifi.DOMAIN,
            CONF_HOST: 'myhost',
            'port': 123,
        })
    with pytest.raises(vol.Invalid):
        unifi.PLATFORM_SCHEMA({
            CONF_PLATFORM: unifi.DOMAIN,
            CONF_USERNAME: '******',
            CONF_PASSWORD: '******',
            CONF_HOST: 'myhost',
            'port': 'foo',  # bad port!
        })
    with pytest.raises(vol.Invalid):
        unifi.PLATFORM_SCHEMA({
            CONF_PLATFORM: unifi.DOMAIN,
            CONF_USERNAME: '******',
            CONF_PASSWORD: '******',
            CONF_VERIFY_SSL: "dfdsfsdfsd",  # Invalid ssl_verify (no file)
        })
async def test_config_minimal(hass, mock_scanner, mock_ctrl):
    """Test the setup with minimal configuration."""
    config = {
        DOMAIN:
        unifi.PLATFORM_SCHEMA({
            CONF_PLATFORM: unifi.DOMAIN,
            CONF_USERNAME: '******',
            CONF_PASSWORD: '******',
        })
    }

    result = await unifi.async_get_scanner(hass, config)
    assert mock_scanner.return_value == result
    assert mock_ctrl.call_count == 1

    assert mock_scanner.call_count == 1
    assert mock_scanner.call_args == mock.call(mock_ctrl.return_value,
                                               DEFAULT_DETECTION_TIME, None,
                                               None)
示例#5
0
def test_config_minimal(hass, mock_scanner, mock_ctrl):
    """Test the setup with minimal configuration."""
    config = {
        DOMAIN:
        unifi.PLATFORM_SCHEMA({
            CONF_PLATFORM: unifi.DOMAIN,
            CONF_USERNAME: '******',
            CONF_PASSWORD: '******',
        })
    }
    result = unifi.get_scanner(hass, config)
    assert mock_scanner.return_value == result
    assert mock_ctrl.call_count == 1
    assert mock_ctrl.mock_calls[0] == \
        mock.call('localhost', 'foo', 'password', 8443,
                  version='v4', site_id='default', ssl_verify=True)

    assert mock_scanner.call_count == 1
    assert mock_scanner.call_args == mock.call(mock_ctrl.return_value,
                                               DEFAULT_DETECTION_TIME, None,
                                               None)