Ejemplo n.º 1
0
def test_video_ordering():
    """
    Tests that videos are sorted by reverse creation date or forward custom order
    """
    collection = CollectionFactory.create()
    VideoFactory.create_batch(10, collection=collection)
    # Should be sorted by reverse creation date
    videos = collection.videos.all()
    for (idx, video) in enumerate(videos):
        if idx > len(videos) - 1:
            assert video.created_at >= videos[idx + 1].created_at
        videos[idx].custom_order = len(videos) - idx - 1
        videos[idx].save()
    # Should be sorted by custom_order
    resorted_videos = Collection.objects.get(id=collection.id).videos.all()
    for (idx, video) in enumerate(resorted_videos):
        assert video.custom_order == idx
Ejemplo n.º 2
0
def test_schedule_retranscodes(mocker, mock_transcode,
                               mock_successful_encode_job, mocked_celery):
    """
    Test that schedule_retranscodes triggers retranscode_video tasks for each scheduled video
    """
    retranscode_video_mock = mocker.patch("cloudsync.tasks.retranscode_video",
                                          autospec=True)
    collection = CollectionFactory.create(schedule_retranscode=True)
    scheduled_videos = VideoFactory.create_batch(5, schedule_retranscode=True)
    VideoFactory.create_batch(3, schedule_retranscode=False)
    with pytest.raises(mocked_celery.replace_exception_class):
        schedule_retranscodes.delay()
    assert mocked_celery.group.call_count == 1
    assert retranscode_video_mock.si.call_count == len(scheduled_videos)
    for video in scheduled_videos:
        retranscode_video_mock.si.assert_any_call(video.id)
    assert Collection.objects.get(
        id=collection.id).schedule_retranscode is False