Ejemplo n.º 1
0
    def setUp(self):
        super(ArtistMonitorControllerTest, self).setUp()
        self.artist_id = IdentityService.id_artist("name")
        self.data_producer.artist(
            self.artist_id, "name").video("source1").video("source2").artist(
                IdentityService.id_artist("name2"),
                "name2").populate(self.data_facade)

        self.artist_repo = self.data_facade.artist_repo
        self.artists = self.artist_repo.list()
Ejemplo n.º 2
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())
Ejemplo n.º 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)
Ejemplo n.º 4
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)
Ejemplo n.º 5
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)
Ejemplo n.º 6
0
    def test_create_artist_no_deezer_data(self):
        video_id = IdentityService.id_video("source")
        artist_id = IdentityService.id_artist("artist")
        self.data_producer.video("source", artist_id=artist_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.ArtistCreated, artist_id, "artist",
                                 [video_id], None).from_event(
                                     VideoEvt.VideoCreated,
                                     video_id,
                                     "source",
                                     None,
                                     artist_id,
                                     None,
                                     "title",
                                     300,
                                     "http",
                                     "thumbnail_url",
                                     VideoState.CREATED,
                                 )
Ejemplo n.º 7
0
 def test_construction(self):
     name = "name"
     ids = [IdentityService.random()]
     thumbnail = "thumbnail"
     id = IdentityService.id_artist(name)
     artist = Artist(id, name, ids, thumbnail)
     self.expect_events(artist, Evt.ArtistCreated)
Ejemplo n.º 8
0
 def test_empty(self):
     self.assertTrue(self.artist.empty())
     self.artist = Artist(
         IdentityService.id_artist("name"),
         "name",
         [IdentityService.random()],
         "thumbnail",
     )
     self.assertFalse(self.artist.empty())
Ejemplo n.º 9
0
    def test_delete_video_deletes_artist(self):
        artist_id = IdentityService.id_artist("artist")
        video_id = IdentityService.id_video("source")
        self.data_producer.artist(artist_id, "artist").video(
            "source", artist_id=artist_id).populate(self.data_facade)

        self.evt_expecter.expect(Evt.ArtistDeleted, artist_id, []).from_event(
            VideoEvt.VideoDeleted,
            video_id,
        )
Ejemplo n.º 10
0
    def test_delete_artist(self):
        name = "name"
        artist_id = IdentityService.id_artist(name)
        self.data_producer.artist(artist_id, name).video("source").populate(
            self.data_facade)

        artist = self.artist_repo.get(artist_id)
        self.evt_expecter.expect(Evt.ArtistDeleted, artist.id,
                                 artist.ids).from_(Cmd.DeleteArtist, artist.id)

        self.assertIsNone(self.artist_repo.get(artist_id))
Ejemplo n.º 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())
Ejemplo n.º 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)
Ejemplo n.º 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())
Ejemplo n.º 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())
Ejemplo n.º 15
0
    def test_add_video_updates_artist_thumbnail(self):
        video_id_1 = IdentityService.id_video("source")
        video_id_2 = IdentityService.id_video("source2")
        artist_id = IdentityService.id_artist("artist")
        self.data_producer.video("source2", artist_id=artist_id).populate(
            self.data_facade)
        self.data_producer.artist(artist_id, "artist", thumbnail=None).video(
            "source", artist_id=artist_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

        deezer_data = [{"artist": {"picture_medium": "picture"}}]
        self.deezer.search.return_value = deezer_data

        self.evt_expecter.expect(Evt.ArtistVideosUpdated, artist_id,
                                 [video_id_1, video_id_2]).expect(
                                     Evt.ArtistThumbnailUpdated, artist_id,
                                     "picture").from_event(
                                         VideoEvt.VideoCreated,
                                         video_id_2,
                                         "source2",
                                         None,
                                         artist_id,
                                         None,
                                         "title",
                                         300,
                                         "http",
                                         "thumbnail",
                                         VideoState.CREATED,
                                     )
Ejemplo n.º 16
0
    def test_add_video_updates_artist(self):
        video_id_1 = IdentityService.id_video("source")
        video_id_2 = IdentityService.id_video("source2")
        artist_id = IdentityService.id_artist("artist")
        self.data_producer.video("source2", artist_id=artist_id).populate(
            self.data_facade)
        self.data_producer.artist(
            artist_id, "artist", thumbnail="thumbnail").video(
                "source", artist_id=artist_id).populate(self.data_facade)

        self.evt_expecter.expect(Evt.ArtistVideosUpdated, artist_id,
                                 [video_id_1, video_id_2]).from_event(
                                     VideoEvt.VideoCreated,
                                     video_id_2,
                                     "source2",
                                     None,
                                     artist_id,
                                     None,
                                     "title",
                                     300,
                                     "http",
                                     "thumbnail",
                                     VideoState.CREATED,
                                 )
Ejemplo n.º 17
0
 def setUp(self):
     name = "name"
     self.artist = Artist(IdentityService.id_artist(name), name, [],
                          "thumbnail")
     self.artist.release_events()