Skip to content

Commit

Permalink
✅ Add unit tests for the video_enrichment view
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastienCozeDev committed Nov 9, 2023
1 parent 7afe706 commit f69446e
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions pod/enrichment/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

0 comments on commit f69446e

Please sign in to comment.