def test_creating_player_to_purging_videos(self, identityMock): player_id = IdentityService.id_player() identityMock.id_player.return_value = player_id video = Video(IdentityService.id_video("source"), "source", location="unknown") self.video_repo.list.return_value = [video] self.workflow.to_CREATING_PLAYER() createPlaylistId = IdentityService.id_command( PlaylistCmd.CreatePlaylist, HOME_PLAYLIST.id) createPlayerId = IdentityService.id_command(PlayerCmd.CreatePlayer, player_id) expected_cmds = [ PlaylistCmd.CreatePlaylist(createPlaylistId, HOME_PLAYLIST.id, HOME_PLAYLIST.name, [], True), PlayerCmd.CreatePlayer(createPlayerId, player_id, HOME_PLAYLIST.id), ] self.expect_dispatch_l(expected_cmds) self.raise_event( PlayerEvt.PlayerCreated, createPlayerId, player_id, HOME_PLAYLIST.id, PlayerState.STOPPED, True, 0, 70, ) self.assertTrue(self.workflow.is_PURGING_VIDEOS())
def setUp(self): super(PlayerMonitorControllerTest, self).setUp() self.data_producer.player().populate(self.data_facade) self.player_id = IdentityService.id_player() self.cmd_id = IdentityService.id_command(PlayerCmd.PlayVideo, self.player_id)
async def test_event_listening(self): async with self.client.ws_connect("/api/events") as ws: playlist_id = IdentityService.id_playlist() cmd_id = IdentityService.id_command(PlaylistCmd.CreatePlaylist, playlist_id) created_evt = PlaylistEvt.PlaylistCreated( cmd_id, playlist_id, "name", [], False, ) self.evt_dispatcher.dispatch(created_evt) await self.expect_ws_events(ws, [created_evt]) update_cmd_id = IdentityService.id_command( PlaylistCmd.UpdatePlaylistContent, playlist_id) updated_evt = PlaylistEvt.PlaylistContentUpdated( update_cmd_id, playlist_id, []) self.evt_dispatcher.dispatch(created_evt) self.evt_dispatcher.dispatch(updated_evt) await self.expect_ws_events(ws, [created_evt, updated_evt])
def from_(self, cmd_cls, model_id, *args, **kwargs): cmd_id = IdentityService.id_command(cmd_cls, model_id) for evt_cls, handler_data in self.evt_to_handler.items(): self.evt_dispatcher.observe_result(cmd_id, {evt_cls: handler_data.functor}) cmd = cmd_cls(cmd_id, model_id, *args, **kwargs) self.cmd_dispatcher.dispatch(cmd) for evt_cls, handler_data in self.evt_to_handler.items(): handler_data.functor.assert_called_once_with( evt_cls(cmd_id, *handler_data.attrs, **handler_data.dict_attrs))
def on_enter_COLLECTING(self): workflow_id = IdentityService.id_workflow(VideoWorkflow, self.video.id) workflow = self._factory.make_video_workflow( workflow_id, self._app_facade, self._data_facade, self.video ) create_cmd_id = IdentityService.id_command(VideoCmd.CreateVideo, self.video.id) self._observe_group( { workflow_id: [workflow.Completed, workflow.Aborted], create_cmd_id: [VideoEvt.VideoCreated], }, ) self._start_workflow(workflow)
def test_creating_player_to_aborted(self, identityMock): player_id = IdentityService.id_player() identityMock.id_player.return_value = player_id self.workflow.to_CREATING_PLAYER() createPlaylistId = IdentityService.id_command( PlaylistCmd.CreatePlaylist, HOME_PLAYLIST.id) createPlayerId = IdentityService.id_command(PlayerCmd.CreatePlayer, player_id) expected_cmds = [ PlaylistCmd.CreatePlaylist( createPlaylistId, HOME_PLAYLIST.id, HOME_PLAYLIST.name, [], True, ), PlayerCmd.CreatePlayer(createPlayerId, player_id, HOME_PLAYLIST.id), ] self.expect_dispatch_l(expected_cmds) self.raise_error(expected_cmds[-1]) self.assertTrue(self.workflow.is_ABORTED())
def make_cmd(cmd_cls, model_id, *args, **kwargs): """Command factory method. Args: cmd_cls: The class of the command. model_id: The ID of the related model. *args: Variable length argument list, forwarded to the command's constructor **kwargs: Arbitrary keyword arguments, forwarded to the command's constructor Returns: Command: The created command. """ cmd_id = IdentityService.id_command(cmd_cls, model_id) return cmd_cls(cmd_id, model_id, *args, **kwargs)
def test_encode_domain_event(self): video_id = IdentityService.id_video("source") collection_id = None cmd_id = IdentityService.id_command(CreateVideo, video_id) event = VideoCreated( cmd_id, video_id, "source", collection_id, IdentityService.id_artist("artist"), IdentityService.id_album("album"), "title", 300, "protocol", "thumbnail", VideoState.CREATED, ) json.dumps(event, cls=EventEncoder)
def test_collecting_to_queueing_with_video_created(self): (video_workflow, ) = self.expect_workflow_creation(VideoWorkflow) self.workflow.to_COLLECTING() video_workflow.start.assert_called_once() cmd_id = IdentityService.id_command(VideoCmd.CreateVideo, self.video.id) self.raise_event( VideoEvt.VideoCreated, cmd_id, self.video.id, self.video.source, self.video.collection_id, IdentityService.id_artist("artist"), IdentityService.id_album("album"), "title", 300, "m3u8", "thumbnail", VideoState.CREATED, ) self.assertTrue(self.workflow.is_QUEUEING())
def expect_dispatch(self, cmd_cls, model_id, *args, **kwargs): cmd_id = IdentityService.id_command(cmd_cls, model_id) cmd = cmd_cls(cmd_id, model_id, *args, **kwargs) self.app_facade.cmd_dispatcher.dispatch.assert_called_once_with(cmd) self.app_facade.cmd_dispatcher.dispatch.reset_mock() return cmd