diff --git a/pod/enrichment/tests/test_views.py b/pod/enrichment/tests/test_views.py index 58ec022046..6aea208811 100644 --- a/pod/enrichment/tests/test_views.py +++ b/pod/enrichment/tests/test_views.py @@ -5,6 +5,7 @@ from django.contrib.auth import authenticate from django.contrib.auth.models import User from django.urls import reverse +from pod.playlist.models import Playlist from pod.video.models import Video, Type from ..models import Enrichment from django.contrib.sites.models import Site @@ -154,3 +155,48 @@ def test_video_enrichment_delete(self): print(" [ BEGIN ENRICHMENT VIEWS ] ") print(" ---> test_video_enrichment_delete: OK!") + + +class VideoEnrichmentViewTestCase(TestCase): + fixtures = [ + "initial_data.json", + ] + + def setUp(self): + site = Site.objects.get(id=1) + self.user = User.objects.create(username="test", password="azerty", is_staff=True) + self.student = User.objects.create(username="student", password="azerty") + self.video = Video.objects.create( + title="videotest", + owner=self.user, + video="test.mp4", + duration=20, + type=Type.objects.get(id=1), + ) + self.video.sites.add(site) + + def test_access_video_enrichment(self): + """Test the video enrichment access.""" + self.client.force_login(self.user) + url = reverse('enrichment:video_enrichment', kwargs={'slug': self.video.slug}) + response = self.client.get(url) + self.assertEqual(response.status_code, 200) + self.assertTemplateUsed(response, 'enrichment/video_enrichment.html') + + def test_invalid_video_slug(self): + """Test the view with invalid slug.""" + url = reverse('enrichment:video_enrichment', kwargs={'slug': 'invalid-slug'}) + response = self.client.get(url) + self.assertEqual(response.status_code, 400) + + def test_private_playlist_access(self): + """Test if a random user can't access to a private playlist.""" + self.client.force_login(self.student) + playlist = Playlist.objects.create( + name="Private playlist", + visibility="private", + owner=self.user, + ) + url = reverse('enrichment:video_enrichment', kwargs={'slug': self.video.slug}) + f'?playlist={playlist.slug}' + response = self.client.get(url) + self.assertEqual(response.status_code, 403)