def setUp(self): super(PlaylistMonitorControllerTest, self).setUp() self.playlist_id = IdentityService.id_playlist() self.data_producer.playlist( self.playlist_id, "playlist1").video("source1").video("source2").playlist( IdentityService.id_playlist(), "playlist2").populate(self.data_facade) self.playlist_repo = self.data_facade.playlist_repo self.video_repo = self.data_facade.video_repo self.playlists = self.playlist_repo.list()
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, )
async def test_update_not_found(self): playlist_id = IdentityService.id_playlist() req_body = { "name": "test_playlist", "ids": [str(IdentityService.random())] } resp = await self.client.patch(f"/api/playlists/{playlist_id}", json=req_body) self.assertEqual(404, resp.status)
def test_update_playlist_content(self): playlist_id = IdentityService.id_playlist() self.data_producer.playlist(playlist_id, "name", []).populate(self.data_facade) playlist = self.playlist_repo.get(playlist_id) new_content = [IdentityService.id_video("source")] self.evt_expecter.expect(Evt.PlaylistContentUpdated, playlist.id, new_content).from_(Cmd.UpdatePlaylistContent, playlist.id, new_content)
def test_delete_playlist(self): playlist_id = IdentityService.id_playlist() self.data_producer.select( Playlist, HOME_PLAYLIST.id).video("source").playlist( playlist_id, "name").video("source").video("other").playlist( IdentityService.id_playlist(), "other").populate(self.data_facade) playlist = self.playlist_repo.get(playlist_id) home_playlist = self.playlist_repo.get(HOME_PLAYLIST.id) self.evt_expecter.expect(Evt.PlaylistDeleted, playlist.id, playlist.name, playlist.ids).expect( Evt.PlaylistContentUpdated, home_playlist.id, home_playlist.ids + [IdentityService.id_video("other")], ).from_(Cmd.DeletePlaylist, playlist.id) self.assertFalse(playlist in self.playlist_repo.list())
def test_rename_playlist(self): playlist_id = IdentityService.id_playlist() self.data_producer.playlist(playlist_id, "name", []).populate(self.data_facade) playlist = self.playlist_repo.get(playlist_id) new_name = "renamed" self.evt_expecter.expect(Evt.PlaylistRenamed, playlist.id, new_name).from_(Cmd.RenamePlaylist, playlist.id, new_name)
def test_create_playlist(self): name = "name" content = [IdentityService.id_video("source")] playlist_id = IdentityService.id_playlist() generated = True self.evt_expecter.expect(Evt.PlaylistCreated, playlist_id, name, content, generated).from_(Cmd.CreatePlaylist, playlist_id, name, content, generated)
def test_list_containing(self): playlists = [ Playlist( IdentityService.id_playlist(), "playlist_1", [ IdentityService.id_video("source1"), IdentityService.id_video("source2"), ], ), Playlist( IdentityService.id_playlist(), "playlist_2", [ IdentityService.id_video("source3"), IdentityService.id_video("source4"), ], ), Playlist( IdentityService.id_playlist(), "playlist_3", [ IdentityService.id_video("source1"), IdentityService.id_video("source3"), ], ), ] for playlist in playlists: self.repo.create(playlist) result = self.repo.list_containing(IdentityService.id_video("source1")) self.assertEqual([playlists[0], playlists[2]], result) result = self.repo.list_containing(IdentityService.id_video("source4")) self.assertEqual([playlists[1]], result) result = self.repo.list_containing(IdentityService.id_video("source5")) self.assertEqual([], result)
def test_queue_video(self): playlist_id = IdentityService.id_playlist() self.data_producer.video("source").playlist( playlist_id, "name", []).populate(self.data_facade) video_id = IdentityService.id_video("source") playlist = self.playlist_repo.get(playlist_id) self.evt_expecter.expect(Evt.PlaylistContentUpdated, playlist.id, [video_id]).from_( Cmd.QueueVideo, playlist.id, video_id, queue_front=False, )
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_encode_video(self): video_id = IdentityService.id_video("source") playlist_id = IdentityService.id_playlist() video = Video( video_id, "source", playlist_id, "artist", "album", "title", timedelta(seconds=300), timedelta(minutes=10), datetime(2020, 10, 5), "protocol", "thumbnail", ) video.location = "/tmp/video.mp4" video.streams = [Stream(0, "audio", "en")] video.subtitle = Path("/tmp/video.srt") json.dumps(video, cls=ModelEncoder)
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])
async def create(self, req): data = await req.json() channel = self._io_factory.make_janus_channel() def on_success(evt): playlist = self._playlist_repo.get(evt.model_id) channel.send(self._ok(playlist)) def on_error(evt): channel.send(self._internal_error(evt.error, evt.details)) self._observe_dispatch( { PlaylistEvt.PlaylistCreated: on_success, OperationError: on_error }, Cmd.CreatePlaylist, IdentityService.id_playlist(), **data, ) return await channel.receive()
async def test_get_not_found(self): playlist_id = IdentityService.id_playlist() resp = await self.client.get(f"/api/playlists/{playlist_id}") self.assertEqual(404, resp.status)
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)
def test_encode_playlist(self): playlist_id = IdentityService.id_playlist() playlist = Playlist(playlist_id, "title", [IdentityService.random()], generated=True) json.dumps(playlist, cls=ModelEncoder)
def setUp(self): super(StreamPlaylistWorkflowTest, self).setUp() self.video_repo = self.data_facade.video_repo self.video_repo.exists.return_value = True self.player_playlist_id = IdentityService.id_playlist()
def setUp(self): database = TinyDB(storage=MemoryStorage) self.repo = PlaylistRepo(database, RLock()) self.playlist_id = IdentityService.id_playlist() self.playlist = Playlist(self.playlist_id, "name")
def setUp(self): self.queue_id = IdentityService.id_playlist() self.player = Player(IdentityService.id_player(), self.queue_id) self.player.release_events()
def setUp(self): self.playlist = Playlist(IdentityService.id_playlist(), "name", []) self.playlist.release_events()
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)