当前位置: 首页>>代码示例>>Python>>正文


Python common.MockConfigEntry类代码示例

本文整理汇总了Python中tests.common.MockConfigEntry的典型用法代码示例。如果您正苦于以下问题:Python MockConfigEntry类的具体用法?Python MockConfigEntry怎么用?Python MockConfigEntry使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了MockConfigEntry类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_config_passed_to_config_entry

async def test_config_passed_to_config_entry(hass):
    """Test that configured options for a host are loaded via config entry."""
    entry = MockConfigEntry(domain=hue.DOMAIN, data={
        'host': '0.0.0.0',
    })
    entry.add_to_hass(hass)

    with patch.object(hue, 'HueBridge') as mock_bridge:
        mock_bridge.return_value.async_setup.return_value = mock_coro(True)
        assert await async_setup_component(hass, hue.DOMAIN, {
            hue.DOMAIN: {
                hue.CONF_BRIDGES: {
                    hue.CONF_HOST: '0.0.0.0',
                    hue.CONF_FILENAME: 'bla.conf',
                    hue.CONF_ALLOW_HUE_GROUPS: False,
                    hue.CONF_ALLOW_UNREACHABLE: True
                }
            }
        }) is True

    assert len(mock_bridge.mock_calls) == 2
    p_hass, p_entry, p_allow_unreachable, p_allow_groups = \
        mock_bridge.mock_calls[0][1]

    assert p_hass is hass
    assert p_entry is entry
    assert p_allow_unreachable is True
    assert p_allow_groups is False
开发者ID:sander76,项目名称:home-assistant,代码行数:28,代码来源:test_init.py

示例2: test_service_refresh_devices

async def test_service_refresh_devices(hass):
    """Test that service can refresh devices."""
    entry = MockConfigEntry(domain=deconz.DOMAIN, data={
        'host': '1.2.3.4', 'port': 80, 'api_key': '1234567890ABCDEF'
    })
    entry.add_to_hass(hass)
    mock_registry = Mock()

    with patch.object(deconz, 'DeconzGateway') as mock_gateway, \
        patch('homeassistant.helpers.device_registry.async_get_registry',
              return_value=mock_coro(mock_registry)):
        mock_gateway.return_value.async_setup.return_value = mock_coro(True)
        assert await deconz.async_setup_entry(hass, entry) is True

    with patch.object(hass.data[deconz.DOMAIN].api, 'async_load_parameters',
                      return_value=mock_coro(True)):
        await hass.services.async_call(
            'deconz', 'device_refresh', service_data={})
        await hass.async_block_till_done()

    with patch.object(hass.data[deconz.DOMAIN].api, 'async_load_parameters',
                      return_value=mock_coro(False)):
        await hass.services.async_call(
            'deconz', 'device_refresh', service_data={})
        await hass.async_block_till_done()
开发者ID:fbradyirl,项目名称:home-assistant,代码行数:25,代码来源:test_init.py

示例3: test_import_already_configured

async def test_import_already_configured(hass):
    """Test importing a device from .homekit that is already a ConfigEntry."""
    discovery_info = {
        'host': '127.0.0.1',
        'port': 8080,
        'properties': {
            'md': 'TestDevice',
            'id': '00:00:00:00:00:00',
            'c#': 1,
            'sf': 1,
        }
    }

    import_info = {
        'AccessoryPairingID': '00:00:00:00:00:00',
    }

    config_entry = MockConfigEntry(
        domain='homekit_controller',
        data=import_info
    )
    config_entry.add_to_hass(hass)

    flow = config_flow.HomekitControllerFlowHandler()
    flow.hass = hass

    result = await flow.async_import_legacy_pairing(
        discovery_info['properties'], import_info)
    assert result['type'] == 'abort'
    assert result['reason'] == 'already_configured'
开发者ID:boced66,项目名称:home-assistant,代码行数:30,代码来源:test_config_flow.py

示例4: test_controller_no_mac

async def test_controller_no_mac(hass):
    """Test that configured options for a host are loaded via config entry."""
    entry = MockConfigEntry(domain=unifi.DOMAIN, data={
        'controller': {
            'host': '0.0.0.0',
            'username': 'user',
            'password': 'pass',
            'port': 80,
            'site': 'default',
            'verify_ssl': True
        },
        'poe_control': True
    })
    entry.add_to_hass(hass)
    mock_registry = Mock()
    with patch.object(unifi, 'UniFiController') as mock_controller, \
        patch('homeassistant.helpers.device_registry.async_get_registry',
              return_value=mock_coro(mock_registry)):
        mock_controller.return_value.async_setup.return_value = mock_coro(True)
        mock_controller.return_value.mac = None
        assert await unifi.async_setup_entry(hass, entry) is True

    assert len(mock_controller.mock_calls) == 2

    assert len(mock_registry.mock_calls) == 0
开发者ID:ManHammer,项目名称:home-assistant,代码行数:25,代码来源:test_init.py

示例5: test_remove_entry_handles_callback_error

async def test_remove_entry_handles_callback_error(hass, manager):
    """Test that exceptions in the remove callback are handled."""
    mock_setup_entry = MagicMock(return_value=mock_coro(True))
    mock_unload_entry = MagicMock(return_value=mock_coro(True))
    mock_remove_entry = MagicMock(
        side_effect=lambda *args, **kwargs: mock_coro())
    loader.set_component(hass, 'test', MockModule(
        'test',
        async_setup_entry=mock_setup_entry,
        async_unload_entry=mock_unload_entry,
        async_remove_entry=mock_remove_entry
    ))
    entry = MockConfigEntry(
        domain='test',
        entry_id='test1',
    )
    entry.add_to_manager(manager)
    # Check all config entries exist
    assert [item.entry_id for item in manager.async_entries()] == \
        ['test1']
    # Setup entry
    await entry.async_setup(hass)
    await hass.async_block_till_done()

    # Remove entry
    result = await manager.async_remove('test1')
    await hass.async_block_till_done()
    # Check that unload went well and so no need to restart
    assert result == {
        'require_restart': False
    }
    # Check the remove callback was invoked.
    assert mock_remove_entry.call_count == 1
    # Check that config entry was removed.
    assert [item.entry_id for item in manager.async_entries()] == []
开发者ID:boced66,项目名称:home-assistant,代码行数:35,代码来源:test_config_entries.py

示例6: test_unload_entry

async def test_unload_entry(hass):
    """Test being able to unload an entry."""
    entry = MockConfigEntry(domain=unifi.DOMAIN, data={
        'controller': {
            'host': '0.0.0.0',
            'username': 'user',
            'password': 'pass',
            'port': 80,
            'site': 'default',
            'verify_ssl': True
        },
        'poe_control': True
    })
    entry.add_to_hass(hass)

    with patch.object(unifi, 'UniFiController') as mock_controller, \
        patch('homeassistant.helpers.device_registry.async_get_registry',
              return_value=mock_coro(Mock())):
        mock_controller.return_value.async_setup.return_value = mock_coro(True)
        mock_controller.return_value.mac = '00:11:22:33:44:55'
        assert await unifi.async_setup_entry(hass, entry) is True

    assert len(mock_controller.return_value.mock_calls) == 1

    mock_controller.return_value.async_reset.return_value = mock_coro(True)
    assert await unifi.async_unload_entry(hass, entry)
    assert len(mock_controller.return_value.async_reset.mock_calls) == 1
    assert hass.data[unifi.DOMAIN] == {}
开发者ID:ManHammer,项目名称:home-assistant,代码行数:28,代码来源:test_init.py

示例7: test_controller_site_already_configured

async def test_controller_site_already_configured(hass):
    """Test config flow."""
    flow = unifi.UnifiFlowHandler()
    flow.hass = hass

    entry = MockConfigEntry(domain=unifi.DOMAIN, data={
        'controller': {
            'host': '1.2.3.4',
            'site': 'default',
        }
    })
    entry.add_to_hass(hass)

    flow.config = {
        unifi.CONF_HOST: '1.2.3.4',
        unifi.CONF_USERNAME: 'username',
        unifi.CONF_PASSWORD: 'password',
    }
    flow.desc = 'site name'
    flow.sites = {
        'site1': {
            'name': 'default', 'role': 'admin', 'desc': 'site name'
        }
    }

    result = await flow.async_step_site()

    assert result['type'] == 'abort'
开发者ID:ManHammer,项目名称:home-assistant,代码行数:28,代码来源:test_init.py

示例8: test_entry_options

async def test_entry_options(hass, manager):
    """Test that we can set options on an entry."""
    entry = MockConfigEntry(
        domain='test',
        data={'first': True},
        options=None
    )
    entry.add_to_manager(manager)

    class TestFlow:
        @staticmethod
        @callback
        def async_get_options_flow(config, options):
            class OptionsFlowHandler(data_entry_flow.FlowHandler):
                def __init__(self, config, options):
                    pass
            return OptionsFlowHandler(config, options)

    config_entries.HANDLERS['test'] = TestFlow()
    flow = await manager.options._async_create_flow(
        entry.entry_id, context={'source': 'test'}, data=None)

    flow.handler = entry.entry_id  # Used to keep reference to config entry

    await manager.options._async_finish_flow(
        flow, {'data': {'second': True}})

    assert entry.data == {
        'first': True
    }

    assert entry.options == {
        'second': True
    }
开发者ID:boced66,项目名称:home-assistant,代码行数:34,代码来源:test_config_entries.py

示例9: test_entry_reload_error

async def test_entry_reload_error(hass, manager, state):
    """Test that we can reload an entry."""
    entry = MockConfigEntry(
        domain='comp',
        state=state
    )
    entry.add_to_hass(hass)

    async_setup = MagicMock(return_value=mock_coro(True))
    async_setup_entry = MagicMock(return_value=mock_coro(True))
    async_unload_entry = MagicMock(return_value=mock_coro(True))

    loader.set_component(hass, 'comp', MockModule(
        'comp',
        async_setup=async_setup,
        async_setup_entry=async_setup_entry,
        async_unload_entry=async_unload_entry
    ))

    with pytest.raises(config_entries.OperationNotAllowed):
        assert await manager.async_reload(entry.entry_id)

    assert len(async_unload_entry.mock_calls) == 0
    assert len(async_setup.mock_calls) == 0
    assert len(async_setup_entry.mock_calls) == 0

    assert entry.state == state
开发者ID:boced66,项目名称:home-assistant,代码行数:27,代码来源:test_config_entries.py

示例10: test_entity_device_info_with_identifier

async def test_entity_device_info_with_identifier(hass, mqtt_mock):
    """Test MQTT climate device registry integration."""
    entry = MockConfigEntry(domain=mqtt.DOMAIN)
    entry.add_to_hass(hass)
    await async_start(hass, 'homeassistant', {}, entry)
    registry = await hass.helpers.device_registry.async_get_registry()

    data = json.dumps({
        'platform': 'mqtt',
        'name': 'Test 1',
        'device': {
            'identifiers': ['helloworld'],
            'connections': [
                ["mac", "02:5b:26:a8:dc:12"],
            ],
            'manufacturer': 'Whatever',
            'name': 'Beer',
            'model': 'Glass',
            'sw_version': '0.1-beta',
        },
        'unique_id': 'veryunique'
    })
    async_fire_mqtt_message(hass, 'homeassistant/climate/bla/config',
                            data)
    await hass.async_block_till_done()
    await hass.async_block_till_done()

    device = registry.async_get_device({('mqtt', 'helloworld')}, set())
    assert device is not None
    assert device.identifiers == {('mqtt', 'helloworld')}
    assert device.connections == {('mac', "02:5b:26:a8:dc:12")}
    assert device.manufacturer == 'Whatever'
    assert device.name == 'Beer'
    assert device.model == 'Glass'
    assert device.sw_version == '0.1-beta'
开发者ID:boced66,项目名称:home-assistant,代码行数:35,代码来源:test_climate.py

示例11: test_entity_device_info_with_hub

async def test_entity_device_info_with_hub(hass, mqtt_mock):
    """Test MQTT sensor device registry integration."""
    entry = MockConfigEntry(domain=mqtt.DOMAIN)
    entry.add_to_hass(hass)
    await async_start(hass, 'homeassistant', {}, entry)

    registry = await hass.helpers.device_registry.async_get_registry()
    hub = registry.async_get_or_create(
        config_entry_id='123',
        connections=set(),
        identifiers={('mqtt', 'hub-id')},
        manufacturer='manufacturer', model='hub'
    )

    data = json.dumps({
        'platform': 'mqtt',
        'name': 'Test 1',
        'state_topic': 'test-topic',
        'device': {
            'identifiers': ['helloworld'],
            'via_hub': 'hub-id',
        },
        'unique_id': 'veryunique'
    })
    async_fire_mqtt_message(hass, 'homeassistant/sensor/bla/config', data)
    await hass.async_block_till_done()
    await hass.async_block_till_done()

    device = registry.async_get_device({('mqtt', 'helloworld')}, set())
    assert device is not None
    assert device.hub_device_id == hub.id
开发者ID:Martwall,项目名称:home-assistant,代码行数:31,代码来源:test_sensor.py

示例12: test_setup_registered_zone_skips_home_zone

 def test_setup_registered_zone_skips_home_zone(self):
     """Test that config entry named home should override hass home zone."""
     entry = MockConfigEntry(domain=zone.DOMAIN, data={
         zone.CONF_NAME: 'home'
     })
     entry.add_to_hass(self.hass)
     assert setup.setup_component(self.hass, zone.DOMAIN, {'zone': None})
     assert len(self.hass.states.entity_ids('zone')) == 0
开发者ID:EarthlingRich,项目名称:home-assistant,代码行数:8,代码来源:test_init.py

示例13: test_remove_entry_unauth

async def test_remove_entry_unauth(hass, client, hass_admin_user):
    """Test removing an entry via the API."""
    hass_admin_user.groups = []
    entry = MockConfigEntry(domain='demo', state=core_ce.ENTRY_STATE_LOADED)
    entry.add_to_hass(hass)
    resp = await client.delete(
        '/api/config/config_entries/entry/{}'.format(entry.entry_id))
    assert resp.status == 401
    assert len(hass.config_entries.async_entries()) == 1
开发者ID:chilicheech,项目名称:home-assistant,代码行数:9,代码来源:test_config_entries.py

示例14: test_service_configure

async def test_service_configure(hass):
    """Test that service invokes pydeconz with the correct path and data."""
    entry = MockConfigEntry(domain=deconz.DOMAIN, data={
        'host': '1.2.3.4', 'port': 80, 'api_key': '1234567890ABCDEF'
    })
    entry.add_to_hass(hass)
    mock_registry = Mock()
    with patch.object(deconz, 'DeconzGateway') as mock_gateway, \
        patch('homeassistant.helpers.device_registry.async_get_registry',
              return_value=mock_coro(mock_registry)):
        mock_gateway.return_value.async_setup.return_value = mock_coro(True)
        assert await deconz.async_setup_entry(hass, entry) is True

    hass.data[deconz.DOMAIN].deconz_ids = {
        'light.test': '/light/1'
    }
    data = {'on': True, 'attr1': 10, 'attr2': 20}

    # only field
    with patch('pydeconz.DeconzSession.async_put_state',
               return_value=mock_coro(True)):
        await hass.services.async_call('deconz', 'configure', service_data={
            'field': '/light/42', 'data': data
        })
        await hass.async_block_till_done()

    # only entity
    with patch('pydeconz.DeconzSession.async_put_state',
               return_value=mock_coro(True)):
        await hass.services.async_call('deconz', 'configure', service_data={
            'entity': 'light.test', 'data': data
        })
        await hass.async_block_till_done()

    # entity + field
    with patch('pydeconz.DeconzSession.async_put_state',
               return_value=mock_coro(True)):
        await hass.services.async_call('deconz', 'configure', service_data={
            'entity': 'light.test', 'field': '/state', 'data': data})
        await hass.async_block_till_done()

    # non-existing entity (or not from deCONZ)
    with patch('pydeconz.DeconzSession.async_put_state',
               return_value=mock_coro(True)):
        await hass.services.async_call('deconz', 'configure', service_data={
            'entity': 'light.nonexisting', 'field': '/state', 'data': data})
        await hass.async_block_till_done()

    # field does not start with /
    with pytest.raises(vol.Invalid):
        with patch('pydeconz.DeconzSession.async_put_state',
                   return_value=mock_coro(True)):
            await hass.services.async_call(
                'deconz', 'configure', service_data={
                    'entity': 'light.test', 'field': 'state', 'data': data})
            await hass.async_block_till_done()
开发者ID:Martwall,项目名称:home-assistant,代码行数:56,代码来源:test_init.py

示例15: test_config_passed_to_config_entry

async def test_config_passed_to_config_entry(hass):
    """Test that configured options for a host are loaded via config entry."""
    entry = MockConfigEntry(domain=hue.DOMAIN, data={
        'host': '0.0.0.0',
    })
    entry.add_to_hass(hass)
    mock_registry = Mock()
    with patch.object(hue, 'HueBridge') as mock_bridge, \
        patch('homeassistant.helpers.device_registry.async_get_registry',
              return_value=mock_coro(mock_registry)):
        mock_bridge.return_value.async_setup.return_value = mock_coro(True)
        mock_bridge.return_value.api.config = Mock(
            mac='mock-mac',
            bridgeid='mock-bridgeid',
            raw={
                'modelid': 'mock-modelid',
                'swversion': 'mock-swversion',
            }
        )
        # Can't set name via kwargs
        mock_bridge.return_value.api.config.name = 'mock-name'
        assert await async_setup_component(hass, hue.DOMAIN, {
            hue.DOMAIN: {
                hue.CONF_BRIDGES: {
                    hue.CONF_HOST: '0.0.0.0',
                    hue.CONF_FILENAME: 'bla.conf',
                    hue.CONF_ALLOW_HUE_GROUPS: False,
                    hue.CONF_ALLOW_UNREACHABLE: True
                }
            }
        }) is True

    assert len(mock_bridge.mock_calls) == 2
    p_hass, p_entry, p_allow_unreachable, p_allow_groups = \
        mock_bridge.mock_calls[0][1]

    assert p_hass is hass
    assert p_entry is entry
    assert p_allow_unreachable is True
    assert p_allow_groups is False

    assert len(mock_registry.mock_calls) == 1
    assert mock_registry.mock_calls[0][2] == {
        'config_entry_id': entry.entry_id,
        'connections': {
            ('mac', 'mock-mac')
        },
        'identifiers': {
            ('hue', 'mock-bridgeid')
        },
        'manufacturer': 'Signify',
        'name': 'mock-name',
        'model': 'mock-modelid',
        'sw_version': 'mock-swversion',
    }
开发者ID:ManHammer,项目名称:home-assistant,代码行数:55,代码来源:test_init.py


注:本文中的tests.common.MockConfigEntry类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。