diff --git a/backend/videoflix/content/signals.py b/backend/videoflix/content/signals.py index b4a77a0..a8f44d8 100644 --- a/backend/videoflix/content/signals.py +++ b/backend/videoflix/content/signals.py @@ -18,7 +18,7 @@ def video_post_save(sender, instance, created, **kwargs): create_thumbnails(instance, instance.id) #Convert video - for resolution in ["480", "720", "1080"]: + for resolution in ["720", "480", "1080"]: queue.enqueue(convert_video_to_hls, instance.video_file.path, resolution, instance.id) #Delete the original video file diff --git a/backend/videoflix/content/tasks.py b/backend/videoflix/content/tasks.py index d686d99..c1f6037 100644 --- a/backend/videoflix/content/tasks.py +++ b/backend/videoflix/content/tasks.py @@ -62,4 +62,5 @@ def create_thumbnails(instance, model_id): ffmpeg.input(video_file_path, ss=1).output(thumbnail_480_path, vf='scale=720:-1', vframes=1).run(overwrite_output=True) except ffmpeg._run.Error as e: - print(f"Ein Fehler ist aufgetreten: {e.stderr.decode()}") \ No newline at end of file + error_message = e.stderr.decode() if e.stderr else "Unknown ffmpeg error" + print(f"Ein Fehler ist aufgetreten: {error_message}") \ No newline at end of file diff --git a/backend/videoflix/content/tests.py b/backend/videoflix/content/tests.py index 7ce503c..bcaa433 100644 --- a/backend/videoflix/content/tests.py +++ b/backend/videoflix/content/tests.py @@ -1,3 +1,21 @@ from django.test import TestCase +from unittest.mock import patch, MagicMock +from .tasks import convert_video_to_hls, delete_original_video, create_thumbnails +from .signals import auto_delete_file_on_delete +from .models import Video +from django.core.files.uploadedfile import SimpleUploadedFile -# Create your tests here. + +class VideoTasksTest(TestCase): + @patch('subprocess.run') + def test_convert_video_to_hls(self, mock_subprocess_run): + mock_subprocess_run.return_value = MagicMock() + convert_video_to_hls('test/source.mp4', '1080', 1) + mock_subprocess_run.assert_called_once() + self.assertIn('-i', mock_subprocess_run.call_args[0][0]) + self.assertIn('hd1080', mock_subprocess_run.call_args[0][0]) + + @patch('os.remove') + def test_delete_original_video(self, mock_os_remove): + delete_original_video('test/source.mp4') + mock_os_remove.assert_called_once_with('test/source.mp4') \ No newline at end of file diff --git a/backend/videoflix/videoflix/urls.py b/backend/videoflix/videoflix/urls.py index 22a4e80..9f42377 100644 --- a/backend/videoflix/videoflix/urls.py +++ b/backend/videoflix/videoflix/urls.py @@ -36,9 +36,9 @@ urlpatterns = [ path('django-rq/', include('django_rq.urls')), # Content URLs - path('content/', content_views.video_list), - path('content/upload/', content_views.video_upload), - path('content/movie//', content_views.check_video), + path('content/', content_views.video_list, name='video_list'), + path('content/upload/', content_views.video_upload, name='video_upload'), + path('content/movie//', content_views.check_video, name='check_video'), # Users URLs path('users/', user_views.user_list, name='user_list'), diff --git a/frontend/src/app/services/auth.service.ts b/frontend/src/app/services/auth.service.ts index 7cc5222..726bf31 100644 --- a/frontend/src/app/services/auth.service.ts +++ b/frontend/src/app/services/auth.service.ts @@ -33,10 +33,10 @@ export class AuthService { } async login(body: any, storage: boolean) { - const data = await lastValueFrom( + const data = (await lastValueFrom( this.http.post(`${environment.baseUrl}/auth/login/`, body) - ); - this.storeAuthToken(data, storage); + )) as { token: string }; + this.storeAuthToken(data.token, storage); } async verifyEmail(body: any) {