From e1453627263b53f60cd2ffd662b6c6dcb96dbc13 Mon Sep 17 00:00:00 2001 From: onyx-and-iris <75868496+onyx-and-iris@users.noreply.github.com> Date: Fri, 29 Jul 2022 02:42:44 +0100 Subject: [PATCH] added test_attrs added tests to test_request keys in attrs() list now snake cased --- obsstudio_sdk/baseclient.py | 2 +- obsstudio_sdk/events.py | 2 +- obsstudio_sdk/reqs.py | 2 +- obsstudio_sdk/util.py | 2 +- tests/test_attrs.py | 27 +++++++++++++++ tests/test_request.py | 69 +++++++++++++++++++++++++++++++++++++ 6 files changed, 100 insertions(+), 4 deletions(-) create mode 100644 tests/test_attrs.py diff --git a/obsstudio_sdk/baseclient.py b/obsstudio_sdk/baseclient.py index 27a0c71..0779a69 100644 --- a/obsstudio_sdk/baseclient.py +++ b/obsstudio_sdk/baseclient.py @@ -8,7 +8,7 @@ import tomllib import websocket -class ObsClient(object): +class ObsClient: DELAY = 0.001 def __init__(self, **kwargs): diff --git a/obsstudio_sdk/events.py b/obsstudio_sdk/events.py index 6abc89d..92f455b 100644 --- a/obsstudio_sdk/events.py +++ b/obsstudio_sdk/events.py @@ -19,7 +19,7 @@ Subs = IntEnum( ) -class EventClient(object): +class EventClient: DELAY = 0.001 def __init__(self, **kwargs): diff --git a/obsstudio_sdk/reqs.py b/obsstudio_sdk/reqs.py index 2bf39f1..46679f1 100644 --- a/obsstudio_sdk/reqs.py +++ b/obsstudio_sdk/reqs.py @@ -9,7 +9,7 @@ https://github.com/obsproject/obs-websocket/blob/master/docs/generated/protocol. """ -class ReqClient(object): +class ReqClient: def __init__(self, **kwargs): self.base_client = ObsClient(**kwargs) self.base_client.authenticate() diff --git a/obsstudio_sdk/util.py b/obsstudio_sdk/util.py index 7f1ec48..26d3197 100644 --- a/obsstudio_sdk/util.py +++ b/obsstudio_sdk/util.py @@ -12,7 +12,7 @@ def to_snake_case(s): def as_dataclass(identifier, data): def attrs(): - return list(data.keys()) + return list(to_snake_case(k) for k in data.keys()) return dataclass( type( diff --git a/tests/test_attrs.py b/tests/test_attrs.py new file mode 100644 index 0000000..689ae8a --- /dev/null +++ b/tests/test_attrs.py @@ -0,0 +1,27 @@ +import pytest + +from tests import req_cl + + +class TestAttrs: + __test__ = True + + def test_get_version_attrs(self): + resp = req_cl.get_version() + assert resp.attrs() == [ + "available_requests", + "obs_version", + "obs_web_socket_version", + "platform", + "platform_description", + "rpc_version", + "supported_image_formats", + ] + + def test_get_current_program_scene_attrs(self): + resp = req_cl.get_current_program_scene() + assert resp.attrs() == ["current_program_scene_name"] + + def test_get_transition_kind_list_attrs(self): + resp = req_cl.get_transition_kind_list() + assert resp.attrs() == ["transition_kinds"] diff --git a/tests/test_request.py b/tests/test_request.py index bbea0f4..b7cc14a 100644 --- a/tests/test_request.py +++ b/tests/test_request.py @@ -36,6 +36,53 @@ class TestRequests: resp = req_cl.get_studio_mode_enabled() assert resp.studio_mode_enabled == state + def test_get_hot_key_list(self): + resp = req_cl.get_hot_key_list() + hotkey_list = [ + "OBSBasic.StartStreaming", + "OBSBasic.StopStreaming", + "OBSBasic.ForceStopStreaming", + "OBSBasic.StartRecording", + "OBSBasic.StopRecording", + "OBSBasic.PauseRecording", + "OBSBasic.UnpauseRecording", + "OBSBasic.StartReplayBuffer", + "OBSBasic.StopReplayBuffer", + "OBSBasic.StartVirtualCam", + "OBSBasic.StopVirtualCam", + "OBSBasic.EnablePreview", + "OBSBasic.DisablePreview", + "OBSBasic.ShowContextBar", + "OBSBasic.HideContextBar", + "OBSBasic.TogglePreviewProgram", + "OBSBasic.Transition", + "OBSBasic.ResetStats", + "OBSBasic.Screenshot", + "OBSBasic.SelectedSourceScreenshot", + "libobs.mute", + "libobs.unmute", + "libobs.push-to-mute", + "libobs.push-to-talk", + "libobs.mute", + "libobs.unmute", + "libobs.push-to-mute", + "libobs.push-to-talk", + "OBSBasic.SelectScene", + "OBSBasic.SelectScene", + "OBSBasic.SelectScene", + "OBSBasic.SelectScene", + "libobs.show_scene_item.Colour Source 2", + "libobs.hide_scene_item.Colour Source 2", + "libobs.show_scene_item.Colour Source 3", + "libobs.hide_scene_item.Colour Source 3", + "libobs.show_scene_item.Colour Source", + "libobs.hide_scene_item.Colour Source", + "OBSBasic.QuickTransition.1", + "OBSBasic.QuickTransition.2", + "OBSBasic.QuickTransition.3", + ] + assert all(x in resp.hotkeys for x in hotkey_list) + @pytest.mark.parametrize( "name,data", [ @@ -47,3 +94,25 @@ class TestRequests: req_cl.set_persistent_data("OBS_WEBSOCKET_DATA_REALM_PROFILE", name, data) resp = req_cl.get_persistent_data("OBS_WEBSOCKET_DATA_REALM_PROFILE", name) assert resp.slot_value == data + + def test_profile_list(self): + req_cl.create_profile("test") + resp = req_cl.get_profile_list() + assert "test" in resp.profiles + req_cl.remove_profile("test") + resp = req_cl.get_profile_list() + assert "test" not in resp.profiles + + def test_source_filter(self): + req_cl.create_source_filter("START", "test", "color_key_filter_v2") + resp = req_cl.get_source_filter_list("START") + assert resp.filters == [ + { + "filterEnabled": True, + "filterIndex": 0, + "filterKind": "color_key_filter_v2", + "filterName": "test", + "filterSettings": {}, + } + ] + req_cl.remove_source_filter("START", "test")