def test_apply_slomo_effect(self): video_file = File(file(movie_path('testdata'))) json_data = file(json_data_path).read() video = Video.objects.create(title="Test", user=self.user1, video=video_file, data=json_data) video.apply_slomo_effect() # test that timestamps got stretched too video = Video.objects.get(pk=video.pk) data = json.loads(video.data) timestamps = [round(f['time'], 1) for f in data['frames']][38:54] expected_timestamps = [5.9, 6.7, 7.1, 7.5, 7.9, 8.3, 8.7, 9.5, 10.3, 11.1, 11.1, 11.9, 12.3, 12.7, 13.1, 13.4] self.failUnlessEqual(expected_timestamps, timestamps)
def test_upload_user_invalid(self): c = Client() response = c.post('/api/v1/upload_video', {"username": "******", "password": "******", "title": "Dummy", "video": file(movie_path('testdata'), 'rb'), "data": file(json_data_path)}) assert response.status_code == 403 # Unauthorized
def test_email_on_notify(self): # request is implictly used by the notification method request = http.MockHttpRequest() request # get PEP8 to ignore the unused variable video_file = File(file(movie_path('testdata'))) json_data = file(json_data_path).read() assert self.user1.email video = Video.objects.create(title="Test", user=self.user1, video=video_file, data=json_data) video.notify_processing() self.failUnlessEqual(len(mail.outbox), 1)
def test_split_video(self): """ Test that a video file can be split and that length of the split file is correct. """ new_filename = effects.split_video( movie_path('testdata'), "00:00:04", "00:00:04") self.failUnless( effects.video_length(new_filename).startswith("00:00:04")) return new_filename
def test_upload_success(self): assert len(Video.objects.filter(user=self.user1)) == 0 c = Client() response = c.post('/api/v1/upload_video', {"username": "******", "password": "******", "title": "Dummy", "video": file(movie_path('testdata'), 'rb'), "data": file(json_data_path)}) assert response.status_code == 200 # Success assert len(Video.objects.filter(user=self.user1)) == 1
def test_small_videos(self): """ Test that small videos (4 seconds and less) are processed properly """ # create 4 second video new_filename = split_video(movie_path('testdata'), "00:00:04", "00:00:03.5") json_data = '{}' try: video = Video.objects.create( title="test", user=self.user1, video=File(file(new_filename)), data=json_data) video.save() video.post_process() finally: os.remove(new_filename)
def test_delete_video_file(self): """ Test that the underlying video file is removed with the models """ video_file = File(file(movie_path('testdata'))) json_data = file(json_data_path).read() video = Video.objects.create(title="Test", user=self.user1, video=video_file, data=json_data) video.generate_thumbnail() video_path = video.video.path thumbnail_path = video.thumbnail.path assert os.path.exists(video_path) assert os.path.exists(thumbnail_path) video.delete() assert not os.path.exists(video_path) assert not os.path.exists(thumbnail_path)
def test_thumbnail_scanner(self): # add a video with no thumbnail video_file = File(file(movie_path('testdata'))) json_data = file(json_data_path).read() video = Video.objects.create( title="Test", user=self.user1, video=video_file, data=json_data) video.save() # run scanner from nsextreme import thumbnail_scanner thumbnail_scanner() # check to see if thumbnail was generated video = Video.objects.get(pk=video.pk) assert video.thumbnail # check qtfaststart was applied with self.assertRaises(FastStartException): qtfaststart.processor.process(video.video.path, '/dev/null')
def test_thumbnail_generate(self): # create a video object manually video_file = File(file(movie_path('testdata'))) json_data = file(json_data_path).read() video = Video.objects.create(title="Test", user=self.user1, video=video_file, data=json_data) video.save() assert not video.thumbnail # trigger thumbnail generation video.generate_thumbnail() # check the resulting thumbnail assert video.thumbnail image = Image.open(video.thumbnail) self.failUnlessEqual(image.size, (192, 108,))
def test_get_rotation(self): filename = movie_path('flipped') self.failUnlessEqual(effects.get_rotation(filename), '180')
def test_video_length(self): self.failUnlessEqual(effects.video_length(movie_path('testdata')), "00:00:14.78")
def test_flip_180(self): filename = movie_path('flipped') new_filename = effects.flip_180(filename) # after being flipped the rotation data should be reset! self.failIfEqual(effects.get_rotation(new_filename), '180') return new_filename
def test_apply_slomo_effect(self): new_filename = effects.apply_effect( effects.flip_180(movie_path('flipped')), "00:00:05", "00:00:04", effect=effects.slow_motion) return new_filename
def test_slow_motion(self): new_filename = effects.slow_motion(movie_path('testdata')) return new_filename
def test_apply_effect(self): # basically a NOP, slight timing change due to ffmpeg new_filename = effects.apply_effect( movie_path('testdata'), "00:00:00", "00:00:05") return new_filename
def test_split_video_no_duration(self): new_filename = effects.split_video( movie_path('testdata'), "00:00:04") self.failUnlessEqual(effects.video_length(new_filename), "00:00:11.14") return new_filename