def test_scene_basic_rpcs(start_processes: None, ars: ARServer) -> None: test = "Test" # initial event show_main_screen_event = event(ars, events.c.ShowMainScreen) assert show_main_screen_event.data assert show_main_screen_event.data.what == events.c.ShowMainScreen.Data.WhatEnum.ScenesList # first, there are no scenes scenes = ars.call_rpc(rpc.s.ListScenes.Request(get_id()), rpc.s.ListScenes.Response) assert scenes.result assert not scenes.data assert ars.call_rpc( rpc.s.NewScene.Request(get_id(), rpc.s.NewScene.Request.Args(test, test)), rpc.s.NewScene.Response).result open_scene_event = event(ars, events.s.OpenScene) assert open_scene_event.parent_id is None assert open_scene_event.change_type is None assert open_scene_event.data assert open_scene_event.data.scene.id scene_id = open_scene_event.data.scene.id assert open_scene_event.data.scene.name == test assert open_scene_event.data.scene.description == test assert not open_scene_event.data.scene.objects event(ars, events.s.SceneState) # attempt to create a new scene while scene is open should fail assert not ars.call_rpc( rpc.s.NewScene.Request(get_id(), rpc.s.NewScene.Request.Args( test, test)), rpc.s.NewScene.Response).result assert ars.call_rpc(rpc.s.SaveScene.Request(get_id()), rpc.s.SaveScene.Response).result event(ars, events.s.SceneSaved) assert ars.call_rpc(rpc.s.CloseScene.Request(get_id()), rpc.s.CloseScene.Response).result event(ars, events.s.SceneClosed) show_main_screen_event_2 = event(ars, events.c.ShowMainScreen) assert show_main_screen_event_2.data assert show_main_screen_event_2.data.what == events.c.ShowMainScreen.Data.WhatEnum.ScenesList assert show_main_screen_event_2.data.highlight == scene_id # attempt to open non-existent scene assert not ars.call_rpc( rpc.s.OpenScene.Request(get_id(), IdArgs("some-random-nonsense")), rpc.s.OpenScene.Response).result list_of_scenes = ars.call_rpc(rpc.s.ListScenes.Request(get_id()), rpc.s.ListScenes.Response) assert list_of_scenes.result assert list_of_scenes.data assert len(list_of_scenes.data) == 1 assert list_of_scenes.data[0].id == scene_id # open previously saved scene assert ars.call_rpc(rpc.s.OpenScene.Request(get_id(), IdArgs(scene_id)), rpc.s.OpenScene.Response).result open_scene_event_2 = event(ars, events.s.OpenScene) assert open_scene_event_2.data assert open_scene_event_2.data.scene.id == scene_id event(ars, events.s.SceneState) assert ars.call_rpc(rpc.s.CloseScene.Request(get_id()), rpc.s.CloseScene.Response).result event(ars, events.s.SceneClosed) show_main_screen_event_3 = event(ars, events.c.ShowMainScreen) assert show_main_screen_event_3.data assert show_main_screen_event_3.data.what == events.c.ShowMainScreen.Data.WhatEnum.ScenesList assert show_main_screen_event_3.data.highlight == scene_id with ARServer(ars_connection_str(), timeout=10, event_mapping=event_mapping) as ars_2: smse = event(ars_2, events.c.ShowMainScreen) assert smse.data assert smse.data.what == events.c.ShowMainScreen.Data.WhatEnum.ScenesList assert smse.data.highlight is None assert ars.call_rpc(rpc.s.DeleteScene.Request(get_id(), IdArgs(scene_id)), rpc.s.DeleteScene.Response).result scene_changed_evt = event(ars, events.s.SceneChanged) assert scene_changed_evt.data assert scene_changed_evt.data.id == scene_id assert scene_changed_evt.change_type == Event.Type.REMOVE list_of_scenes_2 = ars.call_rpc(rpc.s.ListScenes.Request(get_id()), rpc.s.ListScenes.Response) assert list_of_scenes_2.result assert not list_of_scenes_2.data
def test_object_parameters(start_processes: None, ars: ARServer, scene: Scene) -> None: assert ars.call_rpc(rpc.s.OpenScene.Request(get_id(), IdArgs(scene.id)), rpc.s.OpenScene.Response).result event(ars, events.s.OpenScene) event(ars, events.s.SceneState) req_params = [ # TODO create settings_to_params and use it Parameter("str_param", "string", json.dumps("str_param")), Parameter("float_param", "double", json.dumps(1.0)), Parameter("int_param", "integer", json.dumps(1)), Parameter("bool_param", "boolean", json.dumps(True)), ] assert ars.call_rpc( rpc.s.AddObjectToScene.Request( get_id(), rpc.s.AddObjectToScene.Request.Args("ows", ObjectWithSettings.__name__, parameters=req_params)), rpc.s.AddObjectToScene.Response, ).result soc = event(ars, events.s.SceneObjectChanged) assert soc.change_type assert soc.change_type == soc.change_type.ADD assert soc.data.type == ObjectWithSettings.__name__ assert soc.data.parameters == req_params obj_id = soc.data.id req_params2 = [ # TODO create settings_to_params and use it Parameter("str_param", "string", json.dumps("str_param2")), Parameter("float_param", "double", json.dumps(2.0)), Parameter("int_param", "integer", json.dumps(2)), Parameter("bool_param", "boolean", json.dumps(True)), ] lock_object(ars, soc.data.id) assert ars.call_rpc( rpc.s.UpdateObjectParameters.Request( get_id(), rpc.s.UpdateObjectParameters.Request.Args(soc.data.id, parameters=req_params2)), rpc.s.AddObjectToScene.Response, ).result soc2 = event(ars, events.s.SceneObjectChanged) assert soc2.change_type == soc.change_type.UPDATE assert soc2.data.type == ObjectWithSettings.__name__ assert soc2.data.parameters == req_params2 unlock_object(ars, soc.data.id) # let's continue with testing overrides assert ars.call_rpc( rpc.p.NewProject.Request( get_id(), rpc.p.NewProject.Request.Args(scene.id, "Project name")), rpc.p.NewProject.Response, ).result event(ars, events.s.SceneSaved) event(ars, events.p.OpenProject) event(ars, events.s.SceneState) assert not ars.call_rpc( rpc.o.DeleteOverride.Request( get_id(), rpc.o.DeleteOverride.Request.Args( obj_id, Parameter("bool_param", "boolean", json.dumps(True)))), rpc.o.DeleteOverride.Response, ).result assert not ars.call_rpc( rpc.o.UpdateOverride.Request( get_id(), rpc.o.UpdateOverride.Request.Args( obj_id, Parameter("bool_param", "boolean", json.dumps(True)))), rpc.o.UpdateOverride.Response, ).result # int_param has to be set to special value, so without override, StartScene should fail now assert ars.call_rpc( rpc.s.StartScene.Request(get_id()), rpc.s.StartScene.Response, ).result assert event(ars, events.s.SceneState ).data.state == events.s.SceneState.Data.StateEnum.Starting assert event(ars, events.s.SceneState ).data.state == events.s.SceneState.Data.StateEnum.Stopping assert event(ars, events.s.SceneState ).data.state == events.s.SceneState.Data.StateEnum.Stopped lock_object(ars, obj_id) override = Parameter( "int_param", "integer", json.dumps(ObjectWithSettings.INT_PARAM_SPECIAL_VALUE)) assert ars.call_rpc( rpc.o.AddOverride.Request( get_id(), rpc.o.AddOverride.Request.Args(obj_id, override)), rpc.o.AddOverride.Response, ).result override_evt = event(ars, events.o.OverrideUpdated) assert override_evt.data == override assert override_evt.change_type assert override_evt.change_type == override_evt.change_type.ADD assert override_evt.parent_id == obj_id override2 = Parameter("str_param", "string", json.dumps("test")) assert ars.call_rpc( rpc.o.AddOverride.Request( get_id(), rpc.o.AddOverride.Request.Args(obj_id, override2)), rpc.o.AddOverride.Response, ).result event(ars, events.o.OverrideUpdated) unlock_object(ars, obj_id) save_project(ars) # now it should be possible to start the scene assert ars.call_rpc( rpc.s.StartScene.Request(get_id()), rpc.s.StartScene.Response, ).result assert event(ars, events.s.SceneState ).data.state == events.s.SceneState.Data.StateEnum.Starting assert event(ars, events.s.SceneState ).data.state == events.s.SceneState.Data.StateEnum.Started
def test_project_basic_rpcs(start_processes: None, ars: ARServer, scene: common.Scene) -> None: # first, there are no projects projects = ars.call_rpc(rpc.p.ListProjects.Request(uid()), rpc.p.ListProjects.Response) assert projects.result assert not projects.data project_name = "Test project" # attempt to use non-existent scene_id assert not ars.call_rpc( rpc.p.NewProject.Request( uid(), rpc.p.NewProject.Request.Args("some non-sense string", project_name)), rpc.p.NewProject.Response, ).result # attempt to open non-existent project assert not ars.call_rpc( rpc.p.OpenProject.Request(uid(), IdArgs("some-random-nonsense")), rpc.p.OpenProject.Response).result # correct scene_id assert ars.call_rpc( rpc.p.NewProject.Request( uid(), rpc.p.NewProject.Request.Args(scene.id, project_name)), rpc.p.NewProject.Response, ).result open_project_evt = event(ars, events.p.OpenProject) event(ars, events.s.SceneState) assert open_project_evt.data assert open_project_evt.change_type is None assert open_project_evt.parent_id is None assert open_project_evt.data.scene.id == scene.id project_id = open_project_evt.data.project.id assert open_project_evt.data.project.name == project_name assert not open_project_evt.data.project.action_points assert not open_project_evt.data.project.parameters assert not open_project_evt.data.project.functions assert not open_project_evt.data.project.logic # attempt to create project while another project is opened assert not ars.call_rpc( rpc.p.NewProject.Request( uid(), rpc.p.NewProject.Request.Args("some non-sense string", "blah")), rpc.p.NewProject.Response, ).result save_project(ars) close_project(ars) show_main_screen_event = event(ars, events.c.ShowMainScreen) assert show_main_screen_event.data assert show_main_screen_event.data.what == events.c.ShowMainScreen.Data.WhatEnum.ProjectsList assert show_main_screen_event.data.highlight == project_id list_of_projects = ars.call_rpc(rpc.p.ListProjects.Request(uid()), rpc.p.ListProjects.Response) assert list_of_projects.result assert list_of_projects.data assert len(list_of_projects.data) == 1 assert list_of_projects.data[0].id == project_id """ TODO: fix this with ARServer(WS_CONNECTION_STR, timeout=10, event_mapping=event_mapping) as ars_2: smse = event(ars_2, events.c.ShowMainScreen) assert smse.data assert smse.data.what == events.c.ShowMainScreen.Data.WhatEnum.ProjectsList assert smse.data.highlight is None """ # it should not be possible to delete scene used by a project assert not ars.call_rpc(rpc.s.DeleteScene.Request(uid(), IdArgs(scene.id)), rpc.s.DeleteScene.Response).result assert ars.call_rpc(rpc.p.DeleteProject.Request(uid(), IdArgs(project_id)), rpc.p.DeleteProject.Response).result project_changed_evt = event(ars, events.p.ProjectChanged) assert project_changed_evt.data assert project_changed_evt.data.id == project_id assert project_changed_evt.change_type == Event.Type.REMOVE assert ars.call_rpc(rpc.s.DeleteScene.Request(uid(), IdArgs(scene.id)), rpc.s.DeleteScene.Response).result scene_changed_evt = event(ars, events.s.SceneChanged) assert scene_changed_evt.data assert scene_changed_evt.data.id == scene.id assert scene_changed_evt.change_type == Event.Type.REMOVE list_of_projects_2 = ars.call_rpc(rpc.p.ListProjects.Request(uid()), rpc.p.ListProjects.Response) assert list_of_projects_2.result assert not list_of_projects_2.data
def test_object_parameters(start_processes: None, ars: ARServer, scene: Scene) -> None: assert ars.call_rpc(rpc.s.OpenScene.Request(uid(), IdArgs(scene.id)), rpc.s.OpenScene.Response).result event(ars, events.s.OpenScene) assert ars.call_rpc( rpc.s.AddObjectToScene.Request( uid(), rpc.s.AddObjectToScene.Request.Args("ows", ObjectWithActions.__name__)), rpc.s.AddObjectToScene.Response, ).result obj = event(ars, events.s.SceneObjectChanged).data assert obj is not None assert ars.call_rpc( rpc.p.NewProject.Request( uid(), rpc.p.NewProject.Request.Args(scene.id, "Project name")), rpc.p.NewProject.Response, ).result event(ars, events.p.OpenProject) assert ars.call_rpc( rpc.p.AddActionPoint.Request( uid(), rpc.p.AddActionPoint.Request.Args("ap", Position())), rpc.p.AddActionPoint.Response, ).result ap = event(ars, events.p.ActionPointChanged).data assert ap is not None assert ars.call_rpc( rpc.p.AddAction.Request( uid(), rpc.p.AddAction.Request.Args( ap.id, "a1", f"{obj.id}/{ObjectWithActions.bool_action.__name__}", [], [Flow(outputs=["bool_result"])], ), ), rpc.p.AddAction.Response, ).result a1 = event(ars, events.p.ActionChanged).data assert a1 is not None assert ars.call_rpc( rpc.p.AddAction.Request( uid(), rpc.p.AddAction.Request.Args( ap.id, "a2", f"{obj.id}/{ObjectWithActions.str_action.__name__}", [], [Flow()], ), ), rpc.p.AddAction.Response, ).result a2 = event(ars, events.p.ActionChanged).data assert a2 is not None add_logic_item(ars, LogicItem.START, a1.id) add_logic_item( ars, a1.id, a2.id, ProjectLogicIf(f"{a1.id}/{FlowTypes.DEFAULT}/{0}", json.dumps(True))) add_logic_item(ars, a2.id, LogicItem.END) add_logic_item( ars, a1.id, LogicItem.END, ProjectLogicIf(f"{a1.id}/{FlowTypes.DEFAULT}/{0}", json.dumps(False))) # TODO try to add some invalid connections here? save_project(ars)
def test_lock_events(start_processes: None, ars: ARServer, scene: cmn.Scene, project: cmn.Project) -> None: assert ars.call_rpc(rpc.p.OpenProject.Request(uid(), IdArgs(project.id)), rpc.p.OpenProject.Response).result prj_evt = event(ars, events.p.OpenProject) event(ars, events.s.SceneState) prj = prj_evt.data.project # get default project objects ap = next(ap for ap in prj.action_points if ap.name == "ap") ap_ap = next(ap for ap in prj.action_points if ap.name == "ap_ap") ap_ap_ap = next(ap for ap in prj.action_points if ap.name == "ap_ap_ap") ori = ap_ap_ap.orientations[0] lock_object(ars, ap.id, True) # lock object and expect event about it on newly logged UI ars2 = ARServer(ars_connection_str(), timeout=30, event_mapping=event_mapping) event(ars2, events.p.OpenProject) event(ars2, events.s.SceneState) second_ui = "ars2" assert ars2.call_rpc( rpc.u.RegisterUser.Request(uid(), rpc.u.RegisterUser.Request.Args(second_ui)), rpc.u.RegisterUser.Response, ).result locked_evt = event(ars2, events.lk.ObjectsLocked) assert locked_evt.data.owner == "testUser" for obj_id in (ap.id, ap_ap.id, ap_ap_ap.id, ori.id): assert obj_id in locked_evt.data.object_ids # attempt to lock/unlock objects locked by someone else for obj_id in (ap.id, ap_ap.id, ap_ap_ap.id, ori.id): # lock assert not ars2.call_rpc( rpc.lock.WriteLock.Request( uid(), rpc.lock.WriteLock.Request.Args(obj_id)), rpc.lock.WriteLock.Response).result # lock tree assert not ars2.call_rpc( rpc.lock.WriteLock.Request( uid(), rpc.lock.WriteLock.Request.Args(obj_id, True)), rpc.lock.WriteLock.Response, ).result # unlock assert not ars2.call_rpc( rpc.lock.WriteUnlock.Request( uid(), rpc.lock.WriteUnlock.Request.Args(obj_id)), rpc.lock.WriteUnlock.Response, ).result unlock_object(ars, ap.id) event(ars2, events.lk.ObjectsUnlocked) # test lock will stay locked after logout for a while lock_object(ars2, ori.id) event(ars, events.lk.ObjectsLocked) ars2.close() # wait for some time sleep(2) # TODO fill this sleep with another actions # register again and check if objects still locked ars2 = ARServer(ars_connection_str(), timeout=30, event_mapping=event_mapping) event(ars2, events.p.OpenProject) event(ars2, events.s.SceneState) assert ars2.call_rpc( rpc.u.RegisterUser.Request(uid(), rpc.u.RegisterUser.Request.Args("ars2")), rpc.u.RegisterUser.Response, ).result locked_evt = event(ars2, events.lk.ObjectsLocked) assert locked_evt.data.owner == second_ui assert len(locked_evt.data.object_ids) == 1 assert ori.id in locked_evt.data.object_ids ars2.close()