• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python common.mock_registry函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: test_get_entity

async def test_get_entity(hass, client):
    """Test get entry."""
    mock_registry(hass, {
        'test_domain.name': RegistryEntry(
            entity_id='test_domain.name',
            unique_id='1234',
            platform='test_platform',
            name='Hello World'
        ),
        'test_domain.no_name': RegistryEntry(
            entity_id='test_domain.no_name',
            unique_id='6789',
            platform='test_platform',
        ),
    })

    resp = await client.get(
        '/api/config/entity_registry/test_domain.name')
    assert resp.status == 200
    data = await resp.json()
    assert data == {
        'entity_id': 'test_domain.name',
        'name': 'Hello World'
    }

    resp = await client.get(
        '/api/config/entity_registry/test_domain.no_name')
    assert resp.status == 200
    data = await resp.json()
    assert data == {
        'entity_id': 'test_domain.no_name',
        'name': None
    }
开发者ID:TheRealLink,项目名称:home-assistant,代码行数:33,代码来源:test_entity_registry.py


示例2: test_update_file_path

async def test_update_file_path(hass):
    """Test update_file_path service."""
    # Setup platform

    mock_registry(hass)

    with mock.patch('os.path.isfile', mock.Mock(return_value=True)), \
            mock.patch('os.access', mock.Mock(return_value=True)):
        await async_setup_component(hass, 'camera', {
            'camera': {
                'platform': 'local_file',
                'file_path': 'mock/path.jpg'
            }
        })

        # Fetch state and check motion detection attribute
        state = hass.states.get('camera.local_file')
        assert state.attributes.get('friendly_name') == 'Local File'
        assert state.attributes.get('file_path') == 'mock/path.jpg'

        service_data = {
            "entity_id": 'camera.local_file',
            "file_path": 'new/path.jpg'
        }

        await hass.services.async_call(DOMAIN,
                                       SERVICE_UPDATE_FILE_PATH,
                                       service_data)
        await hass.async_block_till_done()

        state = hass.states.get('camera.local_file')
        assert state.attributes.get('file_path') == 'new/path.jpg'
开发者ID:fbradyirl,项目名称:home-assistant,代码行数:32,代码来源:test_camera.py


示例3: test_loading_file

def test_loading_file(hass, test_client):
    """Test that it loads image from disk."""
    mock_registry(hass)

    with mock.patch('os.path.isfile', mock.Mock(return_value=True)), \
            mock.patch('os.access', mock.Mock(return_value=True)):
        yield from async_setup_component(hass, 'camera', {
            'camera': {
                'name': 'config_test',
                'platform': 'local_file',
                'file_path': 'mock.file',
            }})

    client = yield from test_client(hass.http.app)

    m_open = MockOpen(read_data=b'hello')
    with mock.patch(
            'homeassistant.components.camera.local_file.open',
            m_open, create=True
    ):
        resp = yield from client.get('/api/camera_proxy/camera.config_test')

    assert resp.status == 200
    body = yield from resp.text()
    assert body == 'hello'
开发者ID:BaptisteSim,项目名称:home-assistant,代码行数:25,代码来源:test_local_file.py


示例4: test_update_entity_no_changes

async def test_update_entity_no_changes(hass, client):
    """Test get entry."""
    mock_registry(hass, {
        'test_domain.world': RegistryEntry(
            entity_id='test_domain.world',
            unique_id='1234',
            # Using component.async_add_entities is equal to platform "domain"
            platform='test_platform',
            name='name of entity'
        )
    })
    platform = MockEntityPlatform(hass)
    entity = MockEntity(unique_id='1234')
    await platform.async_add_entities([entity])

    state = hass.states.get('test_domain.world')
    assert state is not None
    assert state.name == 'name of entity'

    await client.send_json({
        'id': 6,
        'type': 'config/entity_registry/update',
        'entity_id': 'test_domain.world',
        'name': 'name of entity',
    })

    msg = await client.receive_json()

    assert msg['result'] == {
        'entity_id': 'test_domain.world',
        'name': 'name of entity'
    }

    state = hass.states.get('test_domain.world')
    assert state.name == 'name of entity'
开发者ID:DavidMStraub,项目名称:home-assistant,代码行数:35,代码来源:test_entity_registry.py


示例5: test_registry_respect_entity_namespace

def test_registry_respect_entity_namespace(hass):
    """Test that the registry respects entity namespace."""
    mock_registry(hass)
    platform = MockEntityPlatform(hass, entity_namespace='ns')
    entity = MockEntity(unique_id='1234', name='Device Name')
    yield from platform.async_add_entities([entity])
    assert entity.entity_id == 'test_domain.ns_device_name'
开发者ID:BaptisteSim,项目名称:home-assistant,代码行数:7,代码来源:test_entity_platform.py


示例6: test_update_entity_no_changes

async def test_update_entity_no_changes(hass, client):
    """Test get entry."""
    mock_registry(hass, {
        'test_domain.world': RegistryEntry(
            entity_id='test_domain.world',
            unique_id='1234',
            # Using component.async_add_entities is equal to platform "domain"
            platform='test_platform',
            name='name of entity'
        )
    })
    platform = MockEntityPlatform(hass)
    entity = MockEntity(unique_id='1234')
    await platform.async_add_entities([entity])

    state = hass.states.get('test_domain.world')
    assert state is not None
    assert state.name == 'name of entity'

    resp = await client.post(
        '/api/config/entity_registry/test_domain.world', json={
            'name': 'name of entity'
        })
    assert resp.status == 200
    data = await resp.json()
    assert data == {
        'entity_id': 'test_domain.world',
        'name': 'name of entity'
    }

    state = hass.states.get('test_domain.world')
    assert state.name == 'name of entity'
开发者ID:TheRealLink,项目名称:home-assistant,代码行数:32,代码来源:test_entity_registry.py


示例7: test_update_entity_id

async def test_update_entity_id(hass, client):
    """Test update entity id."""
    mock_registry(hass, {
        'test_domain.world': RegistryEntry(
            entity_id='test_domain.world',
            unique_id='1234',
            # Using component.async_add_entities is equal to platform "domain"
            platform='test_platform',
        )
    })
    platform = MockEntityPlatform(hass)
    entity = MockEntity(unique_id='1234')
    await platform.async_add_entities([entity])

    assert hass.states.get('test_domain.world') is not None

    await client.send_json({
        'id': 6,
        'type': 'config/entity_registry/update',
        'entity_id': 'test_domain.world',
        'new_entity_id': 'test_domain.planet',
    })

    msg = await client.receive_json()

    assert msg['result'] == {
        'entity_id': 'test_domain.planet',
        'name': None
    }

    assert hass.states.get('test_domain.world') is None
    assert hass.states.get('test_domain.planet') is not None
开发者ID:EarthlingRich,项目名称:home-assistant,代码行数:32,代码来源:test_entity_registry.py


示例8: test_extract_entity_ids_from_area

async def test_extract_entity_ids_from_area(hass):
    """Test extract_entity_ids method with areas."""
    hass.states.async_set('light.Bowl', STATE_ON)
    hass.states.async_set('light.Ceiling', STATE_OFF)
    hass.states.async_set('light.Kitchen', STATE_OFF)

    device_in_area = dev_reg.DeviceEntry(area_id='test-area')
    device_no_area = dev_reg.DeviceEntry()
    device_diff_area = dev_reg.DeviceEntry(area_id='diff-area')

    mock_device_registry(hass, {
        device_in_area.id: device_in_area,
        device_no_area.id: device_no_area,
        device_diff_area.id: device_diff_area,
    })

    entity_in_area = ent_reg.RegistryEntry(
        entity_id='light.in_area',
        unique_id='in-area-id',
        platform='test',
        device_id=device_in_area.id,
    )
    entity_no_area = ent_reg.RegistryEntry(
        entity_id='light.no_area',
        unique_id='no-area-id',
        platform='test',
        device_id=device_no_area.id,
    )
    entity_diff_area = ent_reg.RegistryEntry(
        entity_id='light.diff_area',
        unique_id='diff-area-id',
        platform='test',
        device_id=device_diff_area.id,
    )
    mock_registry(hass, {
        entity_in_area.entity_id: entity_in_area,
        entity_no_area.entity_id: entity_no_area,
        entity_diff_area.entity_id: entity_diff_area,
    })

    call = ha.ServiceCall('light', 'turn_on',
                          {'area_id': 'test-area'})

    assert {'light.in_area'} == \
        await service.async_extract_entity_ids(hass, call)

    call = ha.ServiceCall('light', 'turn_on',
                          {'area_id': ['test-area', 'diff-area']})

    assert {'light.in_area', 'light.diff_area'} == \
        await service.async_extract_entity_ids(hass, call)
开发者ID:boced66,项目名称:home-assistant,代码行数:51,代码来源:test_service.py


示例9: test_setup_entry

async def test_setup_entry(hass):
    """Test we can setup an entry."""
    registry = mock_registry(hass)

    async def async_setup_entry(hass, config_entry, async_add_devices):
        """Mock setup entry method."""
        async_add_devices([
            MockEntity(name='test1', unique_id='unique')
        ])
        return True

    platform = MockPlatform(
        async_setup_entry=async_setup_entry
    )
    config_entry = MockConfigEntry(entry_id='super-mock-id')
    entity_platform = MockEntityPlatform(
        hass,
        platform_name=config_entry.domain,
        platform=platform
    )

    assert await entity_platform.async_setup_entry(config_entry)
    await hass.async_block_till_done()
    full_name = '{}.{}'.format(entity_platform.domain, config_entry.domain)
    assert full_name in hass.config.components
    assert len(hass.states.async_entity_ids()) == 1
    assert len(registry.entities) == 1
    assert registry.entities['test_domain.test1'].config_entry_id == \
        'super-mock-id'
开发者ID:keatontaylor,项目名称:home-assistant,代码行数:29,代码来源:test_entity_platform.py


示例10: test_registry_respect_entity_disabled

def test_registry_respect_entity_disabled(hass):
    """Test that the registry respects entity disabled."""
    mock_registry(hass, {
        'test_domain.world': entity_registry.RegistryEntry(
            entity_id='test_domain.world',
            unique_id='1234',
            # Using component.async_add_entities is equal to platform "domain"
            platform='test_platform',
            disabled_by=entity_registry.DISABLED_USER
        )
    })
    platform = MockEntityPlatform(hass)
    entity = MockEntity(unique_id='1234')
    yield from platform.async_add_entities([entity])
    assert entity.entity_id is None
    assert hass.states.async_entity_ids() == []
开发者ID:BaptisteSim,项目名称:home-assistant,代码行数:16,代码来源:test_entity_platform.py


示例11: test_entities_device_id_boolean

def test_entities_device_id_boolean(hass):
    """Test entity ID policy applying control on device id."""
    entity_registry = mock_registry(hass, {
        'test_domain.allowed': RegistryEntry(
            entity_id='test_domain.allowed',
            unique_id='1234',
            platform='test_platform',
            device_id='mock-allowed-dev-id'
        ),
        'test_domain.not_allowed': RegistryEntry(
            entity_id='test_domain.not_allowed',
            unique_id='5678',
            platform='test_platform',
            device_id='mock-not-allowed-dev-id'
        ),
    })
    device_registry = mock_device_registry(hass)

    policy = {
        'device_ids': {
            'mock-allowed-dev-id': {
                'read': True,
            }
        }
    }
    ENTITY_POLICY_SCHEMA(policy)
    compiled = compile_entities(policy, PermissionLookup(
        entity_registry, device_registry
    ))
    assert compiled('test_domain.allowed', 'read') is True
    assert compiled('test_domain.allowed', 'control') is False
    assert compiled('test_domain.not_allowed', 'read') is False
    assert compiled('test_domain.not_allowed', 'control') is False
开发者ID:boced66,项目名称:home-assistant,代码行数:33,代码来源:test_entities.py


示例12: test_entities_areas_area_true

def test_entities_areas_area_true(hass):
    """Test entity ID policy for areas with specific area."""
    entity_registry = mock_registry(hass, {
        'light.kitchen': RegistryEntry(
            entity_id='light.kitchen',
            unique_id='1234',
            platform='test_platform',
            device_id='mock-dev-id'
        ),
    })
    device_registry = mock_device_registry(hass, {
        'mock-dev-id': DeviceEntry(
            id='mock-dev-id',
            area_id='mock-area-id'
        )
    })

    policy = {
        'area_ids': {
            'mock-area-id': {
                'read': True,
                'control': True,
            }
        }
    }
    ENTITY_POLICY_SCHEMA(policy)
    compiled = compile_entities(policy, PermissionLookup(
        entity_registry, device_registry
    ))
    assert compiled('light.kitchen', 'read') is True
    assert compiled('light.kitchen', 'control') is True
    assert compiled('light.kitchen', 'edit') is False
    assert compiled('switch.kitchen', 'read') is False
开发者ID:boced66,项目名称:home-assistant,代码行数:33,代码来源:test_entities.py


示例13: test_entity_id_update

async def test_entity_id_update(hass, mqtt_mock):
    """Test MQTT subscriptions are managed when entity_id is updated."""
    registry = mock_registry(hass, {})
    mock_mqtt = await async_mock_mqtt_component(hass)
    assert await async_setup_component(hass, lock.DOMAIN, {
        lock.DOMAIN: [{
            'platform': 'mqtt',
            'name': 'beer',
            'state_topic': 'test-topic',
            'command_topic': 'test-topic',
            'availability_topic': 'avty-topic',
            'unique_id': 'TOTALLY_UNIQUE'
        }]
    })

    state = hass.states.get('lock.beer')
    assert state is not None
    assert mock_mqtt.async_subscribe.call_count == 2
    mock_mqtt.async_subscribe.assert_any_call('test-topic', ANY, 0, 'utf-8')
    mock_mqtt.async_subscribe.assert_any_call('avty-topic', ANY, 0, 'utf-8')
    mock_mqtt.async_subscribe.reset_mock()

    registry.async_update_entity('lock.beer', new_entity_id='lock.milk')
    await hass.async_block_till_done()
    await hass.async_block_till_done()

    state = hass.states.get('lock.beer')
    assert state is None

    state = hass.states.get('lock.milk')
    assert state is not None
    assert mock_mqtt.async_subscribe.call_count == 2
    mock_mqtt.async_subscribe.assert_any_call('test-topic', ANY, 0, 'utf-8')
    mock_mqtt.async_subscribe.assert_any_call('avty-topic', ANY, 0, 'utf-8')
开发者ID:Martwall,项目名称:home-assistant,代码行数:34,代码来源:test_lock.py


示例14: test_entity_registry_updates_entity_id

async def test_entity_registry_updates_entity_id(hass):
    """Test that updates on the entity registry update platform entities."""
    registry = mock_registry(hass, {
        'test_domain.world': entity_registry.RegistryEntry(
            entity_id='test_domain.world',
            unique_id='1234',
            # Using component.async_add_entities is equal to platform "domain"
            platform='test_platform',
            name='Some name'
        )
    })
    platform = MockEntityPlatform(hass)
    entity = MockEntity(unique_id='1234')
    await platform.async_add_entities([entity])

    state = hass.states.get('test_domain.world')
    assert state is not None
    assert state.name == 'Some name'

    registry.async_update_entity('test_domain.world',
                                 new_entity_id='test_domain.planet')
    await hass.async_block_till_done()
    await hass.async_block_till_done()

    assert hass.states.get('test_domain.world') is None
    assert hass.states.get('test_domain.planet') is not None
开发者ID:keatontaylor,项目名称:home-assistant,代码行数:26,代码来源:test_entity_platform.py


示例15: registries

def registries(hass):
    """Registry mock setup."""
    from types import SimpleNamespace
    ret = SimpleNamespace()
    ret.entity = mock_registry(hass)
    ret.device = mock_device_registry(hass)
    ret.area = mock_area_registry(hass)
    return ret
开发者ID:boced66,项目名称:home-assistant,代码行数:8,代码来源:test_smart_home.py


示例16: test_overriding_name_from_registry

def test_overriding_name_from_registry(hass):
    """Test that we can override a name via the Entity Registry."""
    component = EntityComponent(_LOGGER, DOMAIN, hass)
    mock_registry(hass, {
        'test_domain.world': entity_registry.RegistryEntry(
            entity_id='test_domain.world',
            unique_id='1234',
            # Using component.async_add_entities is equal to platform "domain"
            platform='test_domain',
            name='Overridden'
        )
    })
    yield from component.async_add_entities([
        MockEntity(unique_id='1234', name='Device Name')])

    state = hass.states.get('test_domain.world')
    assert state is not None
    assert state.name == 'Overridden'
开发者ID:BaptisteSim,项目名称:home-assistant,代码行数:18,代码来源:test_entity_platform.py


示例17: test_list_entities

async def test_list_entities(hass, client):
    """Test list entries."""
    entities = OrderedDict()
    entities['test_domain.name'] = RegistryEntry(
        entity_id='test_domain.name',
        unique_id='1234',
        platform='test_platform',
        name='Hello World'
    )
    entities['test_domain.no_name'] = RegistryEntry(
        entity_id='test_domain.no_name',
        unique_id='6789',
        platform='test_platform',
    )

    mock_registry(hass, entities)

    await client.send_json({
        'id': 5,
        'type': 'config/entity_registry/list',
    })
    msg = await client.receive_json()

    assert msg['result'] == [
        {
            'config_entry_id': None,
            'device_id': None,
            'disabled_by': None,
            'entity_id': 'test_domain.name',
            'name': 'Hello World',
            'platform': 'test_platform',
        },
        {
            'config_entry_id': None,
            'device_id': None,
            'disabled_by': None,
            'entity_id': 'test_domain.no_name',
            'name': None,
            'platform': 'test_platform',
        }
    ]
开发者ID:EarthlingRich,项目名称:home-assistant,代码行数:41,代码来源:test_entity_registry.py


示例18: test_get_entity

async def test_get_entity(hass, client):
    """Test get entry."""
    mock_registry(hass, {
        'test_domain.name': RegistryEntry(
            entity_id='test_domain.name',
            unique_id='1234',
            platform='test_platform',
            name='Hello World'
        ),
        'test_domain.no_name': RegistryEntry(
            entity_id='test_domain.no_name',
            unique_id='6789',
            platform='test_platform',
        ),
    })

    await client.send_json({
        'id': 5,
        'type': 'config/entity_registry/get',
        'entity_id': 'test_domain.name',
    })
    msg = await client.receive_json()

    assert msg['result'] == {
        'entity_id': 'test_domain.name',
        'name': 'Hello World'
    }

    await client.send_json({
        'id': 6,
        'type': 'config/entity_registry/get',
        'entity_id': 'test_domain.no_name',
    })
    msg = await client.receive_json()

    assert msg['result'] == {
        'entity_id': 'test_domain.no_name',
        'name': None
    }
开发者ID:DavidMStraub,项目名称:home-assistant,代码行数:39,代码来源:test_entity_registry.py


示例19: test_using_prescribed_entity_id_which_is_registered

def test_using_prescribed_entity_id_which_is_registered(hass):
    """Test not allowing predefined entity ID that already registered."""
    component = EntityComponent(_LOGGER, DOMAIN, hass)
    registry = mock_registry(hass)
    # Register test_domain.world
    registry.async_get_or_create(
        DOMAIN, 'test', '1234', suggested_object_id='world')

    # This entity_id will be rewritten
    yield from component.async_add_entities([
        MockEntity(entity_id='test_domain.world')])

    assert 'test_domain.world_2' in hass.states.async_entity_ids()
开发者ID:BaptisteSim,项目名称:home-assistant,代码行数:13,代码来源:test_entity_platform.py


示例20: test_name_which_conflict_with_registered

def test_name_which_conflict_with_registered(hass):
    """Test not generating conflicting entity ID based on name."""
    component = EntityComponent(_LOGGER, DOMAIN, hass)
    registry = mock_registry(hass)

    # Register test_domain.world
    registry.async_get_or_create(
        DOMAIN, 'test', '1234', suggested_object_id='world')

    yield from component.async_add_entities([
        MockEntity(name='world')])

    assert 'test_domain.world_2' in hass.states.async_entity_ids()
开发者ID:BaptisteSim,项目名称:home-assistant,代码行数:13,代码来源:test_entity_platform.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python common.mock_restore_cache函数代码示例发布时间:2022-05-27
下一篇:
Python common.mock_mqtt_component函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap