예제 #1
0
    def setUp(self):
        super(AlbumMonitorControllerTest, self).setUp()
        self.album_id = IdentityService.id_album("name")
        self.data_producer.album(self.album_id, "name").video("source1").video(
            "source2"
        ).album(IdentityService.id_album("name2"), "name2").populate(self.data_facade)

        self.album_repo = self.data_facade.album_repo
        self.albums = self.album_repo.list()
예제 #2
0
 def test_construction(self):
     name = "name"
     ids = [IdentityService.random()]
     thumbnail = "thumbnail"
     id = IdentityService.id_album(name)
     album = Album(id, name, ids, thumbnail)
     self.expect_events(album, Evt.AlbumCreated)
예제 #3
0
    def _create_video(self, cmd):
        def impl(ctx, metadata):
            video = Video(cmd.model_id, cmd.source, cmd.collection_id,
                          **metadata)
            ctx.add(video)

        if Path(cmd.source).is_file():
            metadata = self._source_service.pick_file_metadata(Path(
                cmd.source))
        else:
            metadata = self._source_service.pick_stream_metadata(cmd.source)

        if metadata is None:
            self._abort_operation(cmd.id,
                                  "no media found", {"source": cmd.source},
                                  cmd=cmd)
            return

        if metadata["duration"]:
            metadata["duration"] = timedelta(seconds=metadata["duration"])
        if metadata["artist"]:
            metadata["artist_id"] = IdentityService.id_artist(
                metadata["artist"])
        if metadata["album"]:
            metadata["album_id"] = IdentityService.id_album(metadata["album"])
        del metadata["artist"]
        del metadata["album"]

        self._start_transaction(self._video_repo, cmd.id, impl, metadata)
예제 #4
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)
예제 #5
0
    def test_create_video(self):
        source = "source"
        video_id = IdentityService.id_video(source)
        collection_id = IdentityService.random()

        metadata = {
            "title": "title",
            "duration": 300,
            "source_protocol": "http",
            "artist": "artist",
            "album": "album",
            "thumbnail": "thumbnail_url",
        }
        self.downloader.download_metadata.return_value = metadata
        self.deezer.search.return_value = []

        attrs = deepcopy(metadata)
        attrs["artist_id"] = IdentityService.id_artist(attrs.pop("artist"))
        attrs["album_id"] = IdentityService.id_album(attrs.pop("album"))
        self.evt_expecter.expect(
            VideoEvt.VideoCreated,
            video_id,
            source,
            collection_id,
            **attrs,
            state=VideoState.CREATED,
        ).from_(Cmd.CreateVideo, video_id, source, collection_id)
예제 #6
0
    def test_create_album_no_deezer_data(self):
        video_id = IdentityService.id_video("source")
        album_id = IdentityService.id_album("album")
        self.data_producer.video("source",
                                 album_id=album_id).populate(self.data_facade)

        metadata = {
            "title": "title",
            "duration": 300,
            "source_protocol": "http",
            "artist": "artist",
            "album": "album",
            "thumbnail": "thumbnail_url",
        }
        self.downloader.download_metadata.return_value = metadata

        self.deezer.search.return_value = []

        self.evt_expecter.expect(Evt.AlbumCreated, album_id, "album",
                                 [video_id], "thumbnail_url").from_event(
                                     VideoEvt.VideoCreated,
                                     video_id,
                                     "source",
                                     None,
                                     None,
                                     album_id,
                                     "title",
                                     300,
                                     "http",
                                     "thumbnail_url",
                                     VideoState.CREATED,
                                 )
예제 #7
0
    def test_retrieving_to_finalizing(self):
        event = Evt.VideoCreated(
            IdentityService.random(),
            *self.video.to_tuple(),
            IdentityService.id_artist("artist"),
            IdentityService.id_album("album"),
            "title",
            300,
            "m3u8",
            "thumbnail",
            VideoState.CREATED,
        )
        self.workflow.to_RETRIEVING(event)

        cmd = self.expect_dispatch(
            Cmd.RetrieveVideo, self.video.id, settings["downloader.output_directory"]
        )

        def return_video(id):
            self.assertEqual(self.video.id, id)
            return VideoModel(self.video.id, self.video.source, source_protocol="m3u8")

        self.video_repo.get.side_effect = return_video

        self.raise_event(
            Evt.VideoRetrieved,
            cmd.id,
            self.video.id,
            "https://url.m3u8",
        )
        self.assertTrue(self.workflow.is_FINALIZING())
예제 #8
0
 def test_empty(self):
     self.assertTrue(self.album.empty())
     self.album = Album(
         IdentityService.id_album("name"),
         "name",
         [IdentityService.random()],
         "thumbnail",
     )
     self.assertFalse(self.album.empty())
예제 #9
0
    def test_delete_video_deletes_album(self):
        album_id = IdentityService.id_album("album")
        video_id = IdentityService.id_video("source")
        self.data_producer.album(album_id, "album").video(
            "source", album_id=album_id).populate(self.data_facade)

        self.evt_expecter.expect(Evt.AlbumDeleted, album_id, []).from_event(
            VideoEvt.VideoDeleted,
            video_id,
        )
예제 #10
0
    def test_delete_album(self):
        name = "name"
        album_id = IdentityService.id_album(name)
        self.data_producer.album(album_id, name).video("source").populate(
            self.data_facade)

        album = self.album_repo.get(album_id)
        self.evt_expecter.expect(Evt.AlbumDeleted, album.id,
                                 album.ids).from_(Cmd.DeleteAlbum, album.id)

        self.assertIsNone(self.album_repo.get(album_id))
예제 #11
0
 def test_creating_to_retrieving(self):
     self.workflow.to_CREATING()
     cmd = self.expect_dispatch(Cmd.CreateVideo, *self.video.to_tuple())
     self.raise_event(
         Evt.VideoCreated,
         cmd.id,
         *self.video.to_tuple(),
         IdentityService.id_artist("artist"),
         IdentityService.id_album("album"),
         "title",
         300,
         "http",
         "thumbnail",
         VideoState.CREATED,
     )
     self.assertTrue(self.workflow.is_RETRIEVING())
예제 #12
0
 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)
예제 #13
0
 def test_retrieving_to_deleting(self):
     event = Evt.VideoCreated(
         IdentityService.random(),
         *self.video.to_tuple(),
         IdentityService.id_artist("artist"),
         IdentityService.id_album("album"),
         "title",
         300,
         "http",
         "thumbnail",
         VideoState.CREATED,
     )
     self.workflow.to_RETRIEVING(event)
     cmd = self.expect_dispatch(
         Cmd.RetrieveVideo, self.video.id, settings["downloader.output_directory"]
     )
     self.raise_error(cmd)
     self.assertTrue(self.workflow.is_DELETING())
예제 #14
0
    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())
예제 #15
0
    def test_add_video_updates_album(self):
        video_id_1 = IdentityService.id_video("source")
        video_id_2 = IdentityService.id_video("source2")
        album_id = IdentityService.id_album("album")
        self.data_producer.video("source2",
                                 album_id=album_id).populate(self.data_facade)
        self.data_producer.album(album_id, "album").video(
            "source", album_id=album_id).populate(self.data_facade)

        self.evt_expecter.expect(Evt.AlbumVideosUpdated, album_id,
                                 [video_id_1, video_id_2]).from_event(
                                     VideoEvt.VideoCreated,
                                     video_id_2,
                                     "source2",
                                     None,
                                     None,
                                     album_id,
                                     "title",
                                     300,
                                     "http",
                                     "thumbnail",
                                     VideoState.CREATED,
                                 )
예제 #16
0
 def setUp(self):
     name = "name"
     self.album = Album(IdentityService.id_album(name), name, [],
                        "thumbnail")
     self.album.release_events()
예제 #17
0
 def test_encode_album(self):
     name = "name"
     album_id = IdentityService.id_album(name)
     album = Album(album_id, name, [IdentityService.random()], "thumbnail")
     json.dumps(album, cls=ModelEncoder)