示例#1
0
    def test_add_missing_video_to_playlist(self):
        video_repository = InMemoryVideoRepository({})
        playlist_repository = InMemoryPlaylistRepository({100: [Playlist(100, None)]})

        usecase = PlaylistsVideosUsecases(video_repository, playlist_repository, None)

        with self.assertRaises(MissingVideo):
            usecase.add(100, 50)
示例#2
0
    def test_delete_video(self):
        video_repository = InMemoryVideoRepository({
            1: Video(1, 'the title of the video', 'The url of the video'),
        })
        playlist_video_repository = InMemoryPlaylistVideoRepository({})

        VideosUsecases(video_repository, playlist_video_repository).delete(1)

        self.assertEqual({}, video_repository.storage)
示例#3
0
    def test_create_video(self):
        a_video = {
            'title': 'the title of the video',
            'thumbnail': 'The url of the video',
        }
        video_repository = InMemoryVideoRepository({})
        VideosUsecases(video_repository, None).add(a_video)

        self.assertEqual({1: Video(1, 'the title of the video', 'The url of the video')},
                         video_repository.storage)
示例#4
0
    def test_add_video_to_playlist(self):
        video_repository = InMemoryVideoRepository({50: Video(50, None, None)})
        playlist_repository = InMemoryPlaylistRepository({100: [Playlist(100, None)]})
        playlist_video_repository = InMemoryPlaylistVideoRepository({})

        usecase = PlaylistsVideosUsecases(playlist_repository, playlist_video_repository, video_repository)

        usecase.add(100, 50)

        self.assertEqual({100: [50]}, playlist_video_repository.storage)
示例#5
0
    def test_create_video(self):
        expected_result = {
            'data': [{
                'id': 1,
                'title': 'the title of the video',
                'thumbnail': 'The url of the video',
            },{
                'id': 2,
                'title': 'another title',
                'thumbnail': 'another url',
            }]
        }

        video_repository = InMemoryVideoRepository({
            1: Video(1, 'the title of the video', 'The url of the video'),
            2: Video(2, 'another title', 'another url')
        })

        self.assertEqual(expected_result, VideosUsecases(video_repository, None).get())
示例#6
0
    def test_get_playlists(self):
        expected_result = {
            'data': [{
                'id': 1,
                'title': 'the title of the video',
                'thumbnail': 'a thumbnail'
            },{
                'id': 2,
                'title': 'another title',
                'thumbnail': 'another thumbnail'
            }]
        }

        playlist_repository = InMemoryPlaylistRepository({10: Playlist(10, 'name'), 11: Playlist(11, 'name')})
        video_repository = InMemoryVideoRepository({1: Video(1, 'the title of the video', 'a thumbnail'),
                                                    2: Video(2, 'another title', 'another thumbnail')})
        playlist_video_repository = InMemoryPlaylistVideoRepository({10: [1, 2]})

        usecase = PlaylistsVideosUsecases(playlist_repository, playlist_video_repository, video_repository)

        self.assertEqual(expected_result, usecase.get_all(10))
        self.assertEqual({'data':[]}, usecase.get_all(11))
示例#7
0
from http.server import HTTPServer

from adapters.http_handler import ServerRequestHandler
from core.adapters import InMemoryPlaylistRepository, InMemoryPlaylistVideoRepository, InMemoryVideoRepository
from core.application import Application

if __name__ == '__main__':

    server = HTTPServer(('0.0.0.0', 8000), ServerRequestHandler)
    server.app = Application(InMemoryPlaylistRepository({}),
                             InMemoryPlaylistVideoRepository({}),
                             InMemoryVideoRepository({}))
    server.serve_forever()
示例#8
0
 def setUp(self):
     self.storage = {}
     self.repo = InMemoryVideoRepository(self.storage)