Beispiel #1
0
 def test_construction(self):
     collection_id = IdentityService.random()
     artist_id = (IdentityService.id_artist("artist"), )
     album_id = (IdentityService.id_album("album_name"), )
     video = Video(
         IdentityService.random(),
         "source",
         collection_id,
         artist_id,
         album_id,
         "title",
         timedelta(seconds=300),
         timedelta(),
         None,
         "protocol",
         "thumbnail_url",
         "/tmp/file",
         [],
         "subtitle",
     )
     self.assertEqual("source", video.source)
     self.assertEqual(collection_id, video.collection_id)
     self.assertEqual(artist_id, video.artist_id)
     self.assertEqual(album_id, video.album_id)
     self.assertEqual("title", video.title)
     self.assertEqual(300, video.duration)
     self.assertEqual("/tmp/file", video.location)
     self.assertEqual([], video.streams)
     self.assertEqual("subtitle", video.subtitle)
     self.expect_events(video, Evt.VideoCreated)
Beispiel #2
0
    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())
Beispiel #3
0
    def test_init_to_purging_videos(self):
        self.player_repo.exists.return_value = True

        video = Video(IdentityService.id_video("source"),
                      "source",
                      location="unknown")
        self.video_repo.list.return_value = [video]

        self.workflow.start()
        self.assertTrue(self.workflow.is_PURGING_VIDEOS())
Beispiel #4
0
 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)
Beispiel #5
0
 def impl(ctx, metadata):
     video = Video(cmd.model_id, cmd.source, cmd.collection_id,
                   **metadata)
     ctx.add(video)
Beispiel #6
0
 def test_streamable(self):
     self.assertFalse(self.video.streamable())
     video = Video(IdentityService.random(),
                   "source",
                   source_protocol="m3u8")
     self.assertTrue(video.streamable())
Beispiel #7
0
 def setUp(self):
     self.video = Video(IdentityService.random(), "source")
     self.video.release_events()
Beispiel #8
0
class VideoTest(ModelTestCase):
    def setUp(self):
        self.video = Video(IdentityService.random(), "source")
        self.video.release_events()

    def test_construction(self):
        collection_id = IdentityService.random()
        artist_id = (IdentityService.id_artist("artist"), )
        album_id = (IdentityService.id_album("album_name"), )
        video = Video(
            IdentityService.random(),
            "source",
            collection_id,
            artist_id,
            album_id,
            "title",
            timedelta(seconds=300),
            timedelta(),
            None,
            "protocol",
            "thumbnail_url",
            "/tmp/file",
            [],
            "subtitle",
        )
        self.assertEqual("source", video.source)
        self.assertEqual(collection_id, video.collection_id)
        self.assertEqual(artist_id, video.artist_id)
        self.assertEqual(album_id, video.album_id)
        self.assertEqual("title", video.title)
        self.assertEqual(300, video.duration)
        self.assertEqual("/tmp/file", video.location)
        self.assertEqual([], video.streams)
        self.assertEqual("subtitle", video.subtitle)
        self.expect_events(video, Evt.VideoCreated)

    def test_retrieve(self):
        self.video.location = "/tmp"
        self.expect_events(self.video, Evt.VideoRetrieved)

    def test_parse(self):
        self.video.streams = {}
        self.expect_events(self.video, Evt.VideoParsed)

    def test_set_subtitles(self):
        self.video.subtitle = "/tmp/toto.srt"
        self.expect_events(self.video, Evt.VideoSubtitleFetched)

    def test_streamable(self):
        self.assertFalse(self.video.streamable())
        video = Video(IdentityService.random(),
                      "source",
                      source_protocol="m3u8")
        self.assertTrue(video.streamable())

    def test_start(self):
        self.video.state = VideoState.READY
        self.video.release_events()

        self.video.start()
        self.expect_events(self.video, Evt.VideoStateUpdated)

    def test_start_already_started(self):
        self.video.state = VideoState.PLAYING
        with self.assertRaises(DomainError) as ctx:
            self.video.start()
        self.assertEqual("the video is already started", str(ctx.exception))

    def test_start_not_ready(self):
        with self.assertRaises(DomainError) as ctx:
            self.video.start()
        self.assertEqual("the video is not ready", str(ctx.exception))

    def test_start_stop(self):
        self.video.state = VideoState.READY
        self.video.release_events()

        self.video.start()
        self.video.stop()
        self.expect_events(self.video, Evt.VideoStateUpdated,
                           Evt.VideoStateUpdated)

    def test_pause(self):
        self.video.state = VideoState.READY
        self.video.start()
        self.video.release_events()

        self.video.pause()
        self.expect_events(self.video, Evt.VideoStateUpdated)

    def test_unpause(self):
        self.video.state = VideoState.PAUSED
        self.video.release_events()

        self.video.pause()
        self.expect_events(self.video, Evt.VideoStateUpdated)

    def test_pause_stopped(self):
        self.video.state = VideoState.READY
        self.video.release_events()

        with self.assertRaises(DomainError) as ctx:
            self.video.pause()
        self.assertEqual("the video is not started", str(ctx.exception))

    def test_stop_not_started(self):
        with self.assertRaises(DomainError) as ctx:
            self.video.stop()
        self.assertEqual("the video is not started", str(ctx.exception))

    def test_delete(self):
        self.video.delete()
        self.expect_events(self.video, Evt.VideoDeleted)