Esempio n. 1
0
async def test_create_duplicate_user_id(hass, hass_admin_user):
    """Test we do not allow duplicate user ID during creation."""
    manager = PersonManager(hass, Mock(async_add_entities=mock_coro_func()), [])
    await manager.async_initialize()
    await manager.async_create_person(name="Hello", user_id=hass_admin_user.id)

    with pytest.raises(ValueError):
        await manager.async_create_person(name="Hello", user_id=hass_admin_user.id)
Esempio n. 2
0
async def test_create_invalid_user_id(hass):
    """Test we do not allow invalid user ID during creation."""
    manager = PersonManager(hass, Mock(), [])
    await manager.async_initialize()
    with pytest.raises(ValueError):
        await manager.async_create_person(
            name='Hello',
            user_id='non-existing'
        )
Esempio n. 3
0
async def test_update_invalid_user_id(hass):
    """Test updating to invalid user ID."""
    manager = PersonManager(hass, Mock(async_add_entities=mock_coro_func()),
                            [])
    await manager.async_initialize()
    person = await manager.async_create_person(name='Hello', )

    with pytest.raises(ValueError):
        await manager.async_update_person(person_id=person['id'],
                                          user_id='non-existing')
Esempio n. 4
0
async def test_update_person_when_user_removed(hass, hass_read_only_user):
    """Update person when user is removed."""
    manager = PersonManager(hass, Mock(async_add_entities=mock_coro_func()),
                            [])
    await manager.async_initialize()
    person = await manager.async_create_person(name='Hello',
                                               user_id=hass_read_only_user.id)

    await hass.auth.async_remove_user(hass_read_only_user)
    await hass.async_block_till_done()
    assert person['user_id'] is None
Esempio n. 5
0
async def test_update_double_user_id(hass, hass_admin_user):
    """Test we do not allow double user ID during update."""
    manager = PersonManager(hass, Mock(async_add_entities=mock_coro_func()),
                            [])
    await manager.async_initialize()
    await manager.async_create_person(name='Hello', user_id=hass_admin_user.id)
    person = await manager.async_create_person(name='Hello', )

    with pytest.raises(ValueError):
        await manager.async_update_person(person_id=person['id'],
                                          user_id=hass_admin_user.id)