本文整理汇总了Python中tests.common.MockConfigEntry类的典型用法代码示例。如果您正苦于以下问题:Python MockConfigEntry类的具体用法?Python MockConfigEntry怎么用?Python MockConfigEntry使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MockConfigEntry类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: test_remove_entry
def test_remove_entry(hass, client):
"""Test removing an entry via the API."""
entry = MockConfigEntry(domain='demo', state=core_ce.ENTRY_STATE_LOADED)
entry.add_to_hass(hass)
resp = yield from client.delete(
'/api/config/config_entries/entry/{}'.format(entry.entry_id))
assert resp.status == 200
data = yield from resp.json()
assert data == {
'require_restart': True
}
assert len(hass.config_entries.async_entries()) == 0
开发者ID:chilicheech,项目名称:home-assistant,代码行数:12,代码来源:test_config_entries.py
示例17: test_configured_devices
async def test_configured_devices(hass):
"""Test that configured devices works as expected."""
result = config_flow.configured_devices(hass)
assert not result
entry = MockConfigEntry(domain=axis.DOMAIN,
data={axis.CONF_DEVICE: {axis.CONF_HOST: ''}})
entry.add_to_hass(hass)
result = config_flow.configured_devices(hass)
assert len(result) == 1
开发者ID:fbradyirl,项目名称:home-assistant,代码行数:13,代码来源:test_config_flow.py
示例18: test_setup_entry_successful
async def test_setup_entry_successful(hass):
"""Test setup entry is successful."""
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
assert hass.data[deconz.DOMAIN]
开发者ID:Martwall,项目名称:home-assistant,代码行数:13,代码来源:test_init.py
示例19: test_full_flow_implementation
async def test_full_flow_implementation(hass):
"""Test registering an implementation and flow works."""
flow = ps4.PlayStation4FlowHandler()
flow.hass = hass
manager = hass.config_entries
# User Step Started, results in Step Creds
with patch('pyps4_homeassistant.Helper.port_bind',
return_value=None):
result = await flow.async_step_user()
assert result['type'] == data_entry_flow.RESULT_TYPE_FORM
assert result['step_id'] == 'creds'
# Step Creds results with form in Step Mode.
with patch('pyps4_homeassistant.Helper.get_creds',
return_value=MOCK_CREDS):
result = await flow.async_step_creds({})
assert result['type'] == data_entry_flow.RESULT_TYPE_FORM
assert result['step_id'] == 'mode'
# Step Mode with User Input which is not manual, results in Step Link.
with patch('pyps4_homeassistant.Helper.has_devices',
return_value=[{'host-ip': MOCK_HOST}]):
result = await flow.async_step_mode(MOCK_AUTO)
assert result['type'] == data_entry_flow.RESULT_TYPE_FORM
assert result['step_id'] == 'link'
# User Input results in created entry.
with patch('pyps4_homeassistant.Helper.link',
return_value=(True, True)), \
patch('pyps4_homeassistant.Helper.has_devices',
return_value=[{'host-ip': MOCK_HOST}]):
result = await flow.async_step_link(MOCK_CONFIG)
assert result['type'] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert result['data'][CONF_TOKEN] == MOCK_CREDS
assert result['data']['devices'] == [MOCK_DEVICE]
assert result['title'] == MOCK_TITLE
await hass.async_block_till_done()
# Add entry using result data.
mock_data = {
CONF_TOKEN: result['data'][CONF_TOKEN],
'devices': result['data']['devices']}
entry = MockConfigEntry(domain=ps4.DOMAIN, data=mock_data)
entry.add_to_manager(manager)
# Check if entry exists.
assert len(manager.async_entries()) == 1
# Check if there is a device config in entry.
assert len(entry.data['devices']) == 1
开发者ID:fbradyirl,项目名称:home-assistant,代码行数:51,代码来源:test_config_flow.py
示例20: setup_push_receiver
async def setup_push_receiver(hass, aioclient_mock):
"""Fixture that sets up a mocked push receiver."""
push_url = 'https://mobile-push.home-assistant.dev/push'
from datetime import datetime, timedelta
now = (datetime.now() + timedelta(hours=24))
iso_time = now.strftime("%Y-%m-%dT%H:%M:%SZ")
aioclient_mock.post(push_url, json={
'rateLimits': {
'attempts': 1,
'successful': 1,
'errors': 0,
'total': 1,
'maximum': 150,
'remaining': 149,
'resetsAt': iso_time
}
})
entry = MockConfigEntry(
connection_class="cloud_push",
data={
"app_data": {
"push_token": "PUSH_TOKEN",
"push_url": push_url
},
"app_id": "io.homeassistant.mobile_app",
"app_name": "mobile_app tests",
"app_version": "1.0",
"device_id": "4d5e6f",
"device_name": "Test",
"manufacturer": "Home Assistant",
"model": "mobile_app",
"os_name": "Linux",
"os_version": "5.0.6",
"secret": "123abc",
"supports_encryption": False,
"user_id": "1a2b3c",
"webhook_id": "webhook_id"
},
domain=DOMAIN,
source="registration",
title="mobile_app test entry",
version=1
)
entry.add_to_hass(hass)
await async_setup_component(hass, DOMAIN, {DOMAIN: {}})
await hass.async_block_till_done()
开发者ID:fbradyirl,项目名称:home-assistant,代码行数:50,代码来源:test_notify.py
注:本文中的tests.common.MockConfigEntry类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论