Esempio n. 1
0
    def test_add_cannot_find_piece_in_sc(self, mock_add_movie,
                                         mock_find_product, *mocks):
        user = User(email="*****@*****.**", password="******", username="******")
        mock_find_product.return_value = []

        remote = RemoteCollectionStore(user=user)
        piece = FixtureList.piece_list[0]

        # WHEN
        result = remote.add(piece)

        # THEN
        self.assertFalse(result)
        self.assertFalse(mock_add_movie.called)
    def test_add_cannot_find_piece_in_sc(self, mock_add_movie, mock_find_product, *mocks):
        user = User(email="*****@*****.**", password="******", username="******")
        mock_find_product.return_value = [
        ]

        remote = RemoteCollectionStore(user=user)
        piece = FixtureList.piece_list[0]

        # WHEN
        result = remote.add(piece)

        # THEN
        self.assertFalse(result)
        self.assertFalse(mock_add_movie.called)
    def test_add_takes_first_matching_sc_product(self, mock_add_movie, mock_find_product, *mocks):
        user = User(email="*****@*****.**", password="******", username="******")
        mock_find_product.return_value = [
            Product(title="SomeTitle", id="12345", type=ProductType.MOVIE),
            Product(title="SomeTitle2", id="67890", type=ProductType.MOVIE),
        ]

        remote = RemoteCollectionStore(user=user)

        piece = FixtureList.piece_list[0]

        # WHEN
        remote.add(piece)

        # THEN
        mock_add_movie.assert_called_once_with(list_id=mock.ANY, product_id="12345")
    def test_remote_collection_creates_list_if_not_present(self, mock_add_movie, mock_find_product, mock_create_list, *mocks):
        user = User(email="*****@*****.**", password="******", username="******")
        mock_find_product.return_value = [
            Product(title="SomeTitle", id="12345", type=ProductType.MOVIE),
        ]
        mock_create_list.return_value = ScList(name="a List", path="/liste/aList/123ListId", type=ListType.MOVIE)

        piece = FixtureList.piece_list[0]

        # WHEN
        remote = RemoteCollectionStore(user=user, movie_collection_title="A movie List")
        result = remote.add(piece)

        # THEN
        self.assertTrue(result)
        mock_create_list.assert_called_once_with(name="A movie List", list_type=ListType.MOVIE)
        mock_add_movie.assert_called_once_with(list_id="123ListId", product_id="12345")
    def test_add_fail_to_add_piece_to_sc(self, mock_add_movie, mock_find_product, *mocks):
        user = User(email="*****@*****.**", password="******", username="******")
        mock_find_product.return_value = [
            Product(title="SomeTitle", id="12345", type=ProductType.MOVIE),
        ]

        mock_add_movie.return_value = None

        remote = RemoteCollectionStore(user=user)
        piece = FixtureList.piece_list[0]

        # WHEN
        result = remote.add(piece)

        # THEN
        self.assertFalse(result)
        self.assertTrue(mock_add_movie.called)
Esempio n. 6
0
    def test_should_not_allow_unauthentified_user_at_creation(
            self, mock_is_authentified):
        user = User(email="*****@*****.**", password="", username="******")

        with self.assertRaises(NotAuthenticatedError):
            RemoteCollectionStore(user=user)

        self.assertTrue(mock_is_authentified.called)
    def test_should_add_piece_to_sc_list(self, mock_add_movie, mock_find_product, *mocks):
        # GIVEN
        user = User(email="*****@*****.**", password="******", username="******")
        mock_find_product.return_value = [
            Product(title="SomeTitle", id="12345", type=ProductType.MOVIE),
        ]

        remote = RemoteCollectionStore(user=user)

        piece_1 = FixtureList.piece_list[0]
        piece_2 = FixtureList.piece_list[1]

        # WHEN
        self.assertTrue(remote.add(piece_1))
        self.assertTrue(remote.add(piece_2))

        # THEN
        self.assertEqual(2, mock_add_movie.call_count)
Esempio n. 8
0
    def test_add_takes_first_matching_sc_product(self, mock_add_movie,
                                                 mock_find_product, *mocks):
        user = User(email="*****@*****.**", password="******", username="******")
        mock_find_product.return_value = [
            Product(title="SomeTitle", id="12345", type=ProductType.MOVIE),
            Product(title="SomeTitle2", id="67890", type=ProductType.MOVIE),
        ]

        remote = RemoteCollectionStore(user=user)

        piece = FixtureList.piece_list[0]

        # WHEN
        remote.add(piece)

        # THEN
        mock_add_movie.assert_called_once_with(list_id=mock.ANY,
                                               product_id="12345")
Esempio n. 9
0
    def test_add_fail_to_add_piece_to_sc(self, mock_add_movie,
                                         mock_find_product, *mocks):
        user = User(email="*****@*****.**", password="******", username="******")
        mock_find_product.return_value = [
            Product(title="SomeTitle", id="12345", type=ProductType.MOVIE),
        ]

        mock_add_movie.return_value = None

        remote = RemoteCollectionStore(user=user)
        piece = FixtureList.piece_list[0]

        # WHEN
        result = remote.add(piece)

        # THEN
        self.assertFalse(result)
        self.assertTrue(mock_add_movie.called)
    def test_remote_collection_adds_to_specified_list(self, mock_add_movie, mock_find_product, mock_find_list, *mocks):
        user = User(email="*****@*****.**", password="******", username="******")
        mock_find_product.return_value = [
            Product(title="SomeTitle", id="12345", type=ProductType.MOVIE),
        ]
        mock_find_list.return_value = iter([
            ScList(name="a List", path="/liste/aList/aListId", type=ListType.MOVIE)
        ])

        piece = FixtureList.piece_list[0]

        # WHEN
        remote = RemoteCollectionStore(user=user)
        result = remote.add(piece)

        # THEN
        self.assertTrue(result)
        self.assertTrue(mock_find_list.called)
        mock_add_movie.assert_called_once_with(list_id="aListId", product_id="12345")
Esempio n. 11
0
    def test_should_add_piece_to_sc_list(self, mock_add_movie,
                                         mock_find_product, *mocks):
        # GIVEN
        user = User(email="*****@*****.**", password="******", username="******")
        mock_find_product.return_value = [
            Product(title="SomeTitle", id="12345", type=ProductType.MOVIE),
        ]

        remote = RemoteCollectionStore(user=user)

        piece_1 = FixtureList.piece_list[0]
        piece_2 = FixtureList.piece_list[1]

        # WHEN
        self.assertTrue(remote.add(piece_1))
        self.assertTrue(remote.add(piece_2))

        # THEN
        self.assertEqual(2, mock_add_movie.call_count)
    def test_should_add_movies_to_sc_list(self):
        # GIVEN
        random_list_title = uuid.uuid4()

        user = AuthService().do_login(email="*****@*****.**",
                                      password="******")
        collection = RemoteCollectionStore(
            user=user, movie_collection_title=random_list_title.hex)

        path_1 = "/home/remi/Downloads/The Life Aquatic with Steve Zissou (2004) [1080p]/The.Life.Aquatic.with.Steve.Zissou.2004.1080p.BluRay.x264.YIFY.mp4"
        path_2 = "/home/remi/Downloads/files_to_scan/The Big Lebowski.mkv"

        # WHEN
        collection.add(piece=Piece(path=path_1, guess=guessit(path_1)))
        collection.add(piece=Piece(path=path_2, guess=guessit(path_2)))

        # THEN
        piece_list = list(collection.piece_list())
        self.assertEqual(2, len(piece_list))
Esempio n. 13
0
    def test_remote_collection_creates_list_if_not_present(
            self, mock_add_movie, mock_find_product, mock_create_list, *mocks):
        user = User(email="*****@*****.**", password="******", username="******")
        mock_find_product.return_value = [
            Product(title="SomeTitle", id="12345", type=ProductType.MOVIE),
        ]
        mock_create_list.return_value = ScList(name="a List",
                                               path="/liste/aList/123ListId",
                                               type=ListType.MOVIE)

        piece = FixtureList.piece_list[0]

        # WHEN
        remote = RemoteCollectionStore(user=user,
                                       movie_collection_title="A movie List")
        result = remote.add(piece)

        # THEN
        self.assertTrue(result)
        mock_create_list.assert_called_once_with(name="A movie List",
                                                 list_type=ListType.MOVIE)
        mock_add_movie.assert_called_once_with(list_id="123ListId",
                                               product_id="12345")
Esempio n. 14
0
    def test_remote_collection_adds_to_specified_list(self, mock_add_movie,
                                                      mock_find_product,
                                                      mock_find_list, *mocks):
        user = User(email="*****@*****.**", password="******", username="******")
        mock_find_product.return_value = [
            Product(title="SomeTitle", id="12345", type=ProductType.MOVIE),
        ]
        mock_find_list.return_value = iter([
            ScList(name="a List",
                   path="/liste/aList/aListId",
                   type=ListType.MOVIE)
        ])

        piece = FixtureList.piece_list[0]

        # WHEN
        remote = RemoteCollectionStore(user=user)
        result = remote.add(piece)

        # THEN
        self.assertTrue(result)
        self.assertTrue(mock_find_list.called)
        mock_add_movie.assert_called_once_with(list_id="aListId",
                                               product_id="12345")
Esempio n. 15
0
    def __init__(self):
        self._local_collection = LocalCollectionStore(
            path=self.local_collection_path)

        # Get previous watch state from local collection
        state_by_path = self._state_by_path()
        initial_state = state_by_path.get(
            self.path) or EmptyDirectorySnapshot(path=self.path)

        self._observer = PollingObserverWithState(
            timeout=self.DEFAULT_CRAWL_TIMEOUT)
        self._observer.schedule(event_handler=self,
                                path=self.path,
                                recursive=True,
                                initial_state=initial_state)

        self._remote_collection = None
        if self.user is not None:
            try:
                self._remote_collection = RemoteCollectionStore(
                    user=self.user,
                    movie_collection_title=self.remote_collection_title)
            except NotAuthenticatedError:
                pass