2018-10-29 10:28:04 +00:00
|
|
|
"""Tests for permissions merging."""
|
|
|
|
from homeassistant.auth.permissions.merge import merge_policies
|
|
|
|
|
|
|
|
|
|
|
|
def test_merging_permissions_true_rules_dict():
|
|
|
|
"""Test merging policy with two entities."""
|
|
|
|
policy1 = {
|
2019-07-31 19:25:30 +00:00
|
|
|
"something_else": True,
|
|
|
|
"entities": {"entity_ids": {"light.kitchen": True}},
|
2018-10-29 10:28:04 +00:00
|
|
|
}
|
2019-07-31 19:25:30 +00:00
|
|
|
policy2 = {"entities": {"entity_ids": True}}
|
2018-10-29 10:28:04 +00:00
|
|
|
assert merge_policies([policy1, policy2]) == {
|
2019-07-31 19:25:30 +00:00
|
|
|
"something_else": True,
|
|
|
|
"entities": {"entity_ids": True},
|
2018-10-29 10:28:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
def test_merging_permissions_multiple_subcategories():
|
|
|
|
"""Test merging policy with two entities."""
|
2019-07-31 19:25:30 +00:00
|
|
|
policy1 = {"entities": None}
|
|
|
|
policy2 = {"entities": {"entity_ids": True}}
|
|
|
|
policy3 = {"entities": True}
|
2018-10-29 10:28:04 +00:00
|
|
|
assert merge_policies([policy1, policy2]) == policy2
|
|
|
|
assert merge_policies([policy1, policy3]) == policy3
|
|
|
|
|
|
|
|
assert merge_policies([policy2, policy3]) == policy3
|