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)
def setUp(self): super(VideoServiceTest, self).setUp() self.data_producer.player().populate(self.data_facade) self.video_repo = self.data_facade.video_repo self.player_repo = self.data_facade.player_repo self.player_id = IdentityService.id_player()
def on_enter_STARTING(self, _): self._observe_dispatch( PlayerEvt.PlayerStateUpdated, PlayerCmd.PlayVideo, IdentityService.id_player(), self.video.id, )
def setUp(self): super(QueueVideoWorkflowTest, self).setUp() self.video_repo = self.data_facade.video_repo self.playlist_repo = self.data_facade.playlist_repo self.video_repo.exists.return_value = True self.player_playlist = Mock() self.player_playlist.ids = [] self.playlist_repo.get.return_value = self.player_playlist self.player_id = IdentityService.id_player() self.player_playlist_id = IdentityService.id_playlist() player = Mock() player.queue = self.player_playlist_id self.data_facade.player_repo.get_player.return_value = player self.video = Video( IdentityService.id_video("source"), "source", collection_id=None, ) self.workflow = self.make_workflow( QueueVideoWorkflow, self.video, self.player_playlist_id, queue_front=False, )
def setUp(self): super(PlayerServiceTest, self).setUp() self.video_repo = self.data_facade.video_repo self.player_id = IdentityService.id_player() self.player_playlist_id = HOME_PLAYLIST.id
def player(self, *args, **attrs): if self._population.find(Playlist, HOME_PLAYLIST.id) is None: PlaylistProducer(self._population).playlist(HOME_PLAYLIST.id, HOME_PLAYLIST.name, [], generated=True) player_id = IdentityService.id_player() self._population.add(Player, player_id, HOME_PLAYLIST.id, *args, **attrs) return self
def test_construction(self): player = Player(IdentityService.id_player(), self.queue_id) self.assertEqual(self.queue_id, player.queue) self.assertEqual(None, player.video_id) self.assertEqual(PlayerState.STOPPED, player.state) self.assertEqual(70, player.volume) self.assertTrue(player.subtitle_state) self.assertEqual(0, player.subtitle_delay) self.expect_events(player, Evt.PlayerCreated)
def on_enter_CREATING_PLAYER(self): cmd = make_cmd( PlaylistCmd.CreatePlaylist, HOME_PLAYLIST.id, HOME_PLAYLIST.name, generated=True, ) self._cmd_dispatcher.dispatch(cmd) self._observe_dispatch( PlayerEvt.PlayerCreated, PlayerCmd.CreatePlayer, IdentityService.id_player(), HOME_PLAYLIST.id, )
def setUp(self): super(StreamVideoWorkflowTest, self).setUp() self.video_repo = self.data_facade.video_repo self.video_repo.exists.return_value = True self.player_playlist_id = IdentityService.id_playlist() self.player_id = IdentityService.id_player() self.video = Video( IdentityService.id_video("source"), "source", collection_id=None, ) self.workflow = self.make_workflow( StreamVideoWorkflow, self.video, self.player_playlist_id, )
def test_media_end_reached_with_videos(self): next_video_id = IdentityService.id_video("source") self.queueing_service.next_video.return_value = next_video_id self.raise_event(self.controller, Evt.MediaEndReached, None) self.expect_dispatch_l([ { "type": Cmd.StopPlayer, "args": { "model_id": IdentityService.id_player() }, }, { "type": Cmd.PlayVideo, "args": { "model_id": self.player.id, "video_id": next_video_id, }, }, ]),
async def test_play(self): video_id = IdentityService.id_video("source") self.data_producer.select(Player, IdentityService.id_player()).video( "source", state=VideoState.READY).populate(self.data_facade) self.expect_and_raise( make_cmd(PlayerCmd.PlayVideo, self.player_id, video_id), [ { "type": PlayerEvt.PlayerStateUpdated, "args": { "old_state": PlayerState.STOPPED, "new_state": PlayerState.PLAYING, }, }, { "type": PlayerEvt.PlayerVideoUpdated, "args": { "old_video_id": None, "new_video_id": video_id, }, }, { "type": VideoEvt.VideoStateUpdated, "args": { "old_state": VideoState.READY, "new_state": VideoState.PLAYING, "total_playing_duration": timedelta(), "last_play": datetime.now(), }, }, ], ) resp = await self.client.post( "/api/player/play", params={"id": str(video_id)}, ) body = await resp.json() player = self.data_facade.player_repo.get_player() self.assertEqual(200, resp.status) self.assertEqual(player.to_dict(), body)
async def test_play_error(self): self.data_producer.select( Player, IdentityService.id_player()).video("source").populate( self.data_facade) video_id = IdentityService.id_video("source") self.expect_and_error( make_cmd(PlayerCmd.PlayVideo, self.player_id, video_id), error="Error message", ) resp = await self.client.post( "/api/player/play", params={"id": str(video_id)}, ) body = await resp.json() self.assertEqual(500, resp.status) self.assertEqual( { "message": "Error message", "details": {}, }, body, )
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 _dispatch(self, cmd_cls, *args, **kwargs): player_id = IdentityService.id_player() return super()._dispatch(cmd_cls, player_id, *args, **kwargs)
def player_exists(self): return self._player_repo.exists(IdentityService.id_player())
def setUp(self): self.queue_id = IdentityService.id_playlist() self.player = Player(IdentityService.id_player(), self.queue_id) self.player.release_events()
def test_media_end_reached_without_video(self): self.queueing_service.next_video.return_value = None self.raise_event(self.controller, Evt.MediaEndReached, None) self.expect_dispatch(Cmd.StopPlayer, IdentityService.id_player())
def _observe_dispatch(self, evtcls_handler, cmd_cls, *args, **kwargs): player_id = IdentityService.id_player() super()._observe_dispatch(evtcls_handler, cmd_cls, player_id, *args, **kwargs)
def setUp(self): super(VideoMonitorControllerTest, self).setUp() self.data_producer.video("source").video("source2").populate( self.data_facade) self.player_id = IdentityService.id_player() self.video_id = IdentityService.id_video("source")
def setUp(self): database = TinyDB(storage=MemoryStorage) self.repo = PlayerRepo(database, RLock()) self.player_id = IdentityService.id_player() self.queue_id = IdentityService.id_playlist() self.player = Player(self.player_id, self.queue_id)
def test_encode_player(self): player_id = IdentityService.id_player() queue_id = IdentityService.id_playlist() player = Player(player_id, queue_id) json.dumps(player, cls=ModelEncoder)