|
12 | 12 | from pyoverkiz.converter import converter |
13 | 13 | from pyoverkiz.enums import DataType, EventName, ExecutionState, FailureType, Protocol |
14 | 14 | from pyoverkiz.models import ( |
| 15 | + Action, |
| 16 | + ActionGroup, |
| 17 | + Command, |
15 | 18 | CommandDefinitions, |
16 | 19 | Definition, |
17 | 20 | Device, |
18 | 21 | Event, |
19 | 22 | EventState, |
| 23 | + PersistedActionGroup, |
20 | 24 | Setup, |
21 | 25 | State, |
22 | 26 | StateDefinition, |
@@ -919,3 +923,61 @@ def test_event_fixture_structures_all_events(self): |
919 | 923 | for e in state_changed: |
920 | 924 | assert isinstance(e.old_state, ExecutionState) |
921 | 925 | assert isinstance(e.new_state, ExecutionState) |
| 926 | + |
| 927 | + |
| 928 | +class TestActionGroup: |
| 929 | + """Tests for ActionGroup and PersistedActionGroup model split.""" |
| 930 | + |
| 931 | + def test_action_group_minimal_construction(self): |
| 932 | + """ActionGroup can be constructed with just actions.""" |
| 933 | + action = Action( |
| 934 | + device_url="io://1234-5678-9012/12345678", |
| 935 | + commands=[Command(name="open")], |
| 936 | + ) |
| 937 | + group = ActionGroup(actions=[action]) |
| 938 | + assert len(group.actions) == 1 |
| 939 | + assert group.label is None |
| 940 | + assert not hasattr(group, "oid") |
| 941 | + |
| 942 | + def test_action_group_with_label(self): |
| 943 | + """ActionGroup accepts an optional label.""" |
| 944 | + group = ActionGroup(actions=[], label="my scene") |
| 945 | + assert group.label == "my scene" |
| 946 | + |
| 947 | + def test_action_group_no_oid_attribute(self): |
| 948 | + """ActionGroup does not have an oid attribute.""" |
| 949 | + group = ActionGroup(actions=[]) |
| 950 | + assert not hasattr(group, "oid") |
| 951 | + assert not hasattr(group, "creation_time") |
| 952 | + assert not hasattr(group, "last_update_time") |
| 953 | + |
| 954 | + def test_persisted_action_group_inherits_action_group(self): |
| 955 | + """PersistedActionGroup is a subclass of ActionGroup.""" |
| 956 | + assert issubclass(PersistedActionGroup, ActionGroup) |
| 957 | + |
| 958 | + def test_persisted_action_group_construction(self): |
| 959 | + """PersistedActionGroup requires oid and has timestamp defaults.""" |
| 960 | + group = PersistedActionGroup( |
| 961 | + oid="abc-123", |
| 962 | + actions=[], |
| 963 | + label="my scene", |
| 964 | + ) |
| 965 | + assert group.oid == "abc-123" |
| 966 | + assert group.id == "abc-123" |
| 967 | + assert group.label == "my scene" |
| 968 | + assert group.creation_time == 0 |
| 969 | + assert group.last_update_time == 0 |
| 970 | + assert isinstance(group, ActionGroup) |
| 971 | + |
| 972 | + def test_persisted_action_group_isinstance_action_group(self): |
| 973 | + """PersistedActionGroup instances pass isinstance check for ActionGroup.""" |
| 974 | + group = PersistedActionGroup(oid="abc-123", actions=[]) |
| 975 | + assert isinstance(group, ActionGroup) |
| 976 | + assert isinstance(group, PersistedActionGroup) |
| 977 | + |
| 978 | + def test_persisted_action_group_id_property_returns_str(self): |
| 979 | + """The id property returns a str, not str | None.""" |
| 980 | + group = PersistedActionGroup(oid="abc-123", actions=[]) |
| 981 | + result = group.id |
| 982 | + assert isinstance(result, str) |
| 983 | + assert result == "abc-123" |
0 commit comments