Exemplo n.º 1
0
def test_default_policy_allow_all():
    """Test that the default policy is to allow all entity actions."""
    perm = permissions.PolicyPermissions(permissions.DEFAULT_POLICY)
    assert perm.check_entity('light.kitchen')
    states = [
        State('light.kitchen', 'on'),
        State('light.living_room', 'off'),
        State('light.balcony', 'on'),
    ]
    assert perm.filter_states(states) == states
Exemplo n.º 2
0
def test_policy_perm_filter_states():
    """Test filtering entitites."""
    states = [
        State('light.kitchen', 'on'),
        State('light.living_room', 'off'),
        State('light.balcony', 'on'),
    ]
    perm = permissions.PolicyPermissions({
        'entities': {
            'entity_ids': {
                'light.kitchen': True,
                'light.balcony': True,
            }
        }
    })
    filtered = perm.filter_states(states)
    assert len(filtered) == 2
    assert filtered == [states[0], states[2]]
Exemplo n.º 3
0
 def mock_policy(self, policy):
     """Mock a policy for a user."""
     self._permissions = auth_permissions.PolicyPermissions(
         policy, self.perm_lookup)