mirror of
				https://gitlab.com/animath/si/plateforme-corres2math.git
				synced 2025-11-04 09:42:13 +01:00 
			
		
		
		
	Test video upload
This commit is contained in:
		@@ -2,7 +2,7 @@ stages:
 | 
				
			|||||||
  - test
 | 
					  - test
 | 
				
			||||||
  - quality-assurance
 | 
					  - quality-assurance
 | 
				
			||||||
 | 
					
 | 
				
			||||||
py38-django31:
 | 
					py38:
 | 
				
			||||||
  stage: test
 | 
					  stage: test
 | 
				
			||||||
  image: python:3-alpine
 | 
					  image: python:3-alpine
 | 
				
			||||||
  before_script:
 | 
					  before_script:
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -122,6 +122,32 @@ class TestStudentParticipation(TestCase):
 | 
				
			|||||||
        self.assertRedirects(response, reverse("participation:team_detail", args=(self.team.pk,)), 302, 200)
 | 
					        self.assertRedirects(response, reverse("participation:team_detail", args=(self.team.pk,)), 302, 200)
 | 
				
			||||||
        self.assertTrue(Team.objects.filter(trigram="BBB", participation__problem=3).exists())
 | 
					        self.assertTrue(Team.objects.filter(trigram="BBB", participation__problem=3).exists())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def test_participation_detail(self):
 | 
				
			||||||
 | 
					        self.user.registration.team = self.team
 | 
				
			||||||
 | 
					        self.user.registration.save()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        response = self.client.get(reverse("participation:participation_detail", args=(self.team.participation.pk,)))
 | 
				
			||||||
 | 
					        self.assertEqual(response.status_code, 200)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def test_upload_video(self):
 | 
				
			||||||
 | 
					        self.user.registration.team = self.team
 | 
				
			||||||
 | 
					        self.user.registration.save()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        response = self.client.get(reverse("participation:upload_video", args=(self.team.participation.solution.pk,)))
 | 
				
			||||||
 | 
					        self.assertEqual(response.status_code, 200)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        response = self.client.post(reverse("participation:upload_video", args=(self.team.participation.solution.pk,)),
 | 
				
			||||||
 | 
					                                    data=dict(link="https://youtube.com/watch?v=73nsrixx7eI"))
 | 
				
			||||||
 | 
					        self.assertRedirects(response,
 | 
				
			||||||
 | 
					                             reverse("participation:participation_detail", args=(self.team.participation.id,)),
 | 
				
			||||||
 | 
					                             302, 200)
 | 
				
			||||||
 | 
					        self.team.participation.refresh_from_db()
 | 
				
			||||||
 | 
					        self.assertEqual(self.team.participation.solution.platform, "youtube")
 | 
				
			||||||
 | 
					        self.assertEqual(self.team.participation.solution.youtube_code, "73nsrixx7eI")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        response = self.client.get(reverse("participation:participation_detail", args=(self.team.participation.pk,)))
 | 
				
			||||||
 | 
					        self.assertEqual(response.status_code, 200)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class TestAdminForbidden(TestCase):
 | 
					class TestAdminForbidden(TestCase):
 | 
				
			||||||
    def setUp(self) -> None:
 | 
					    def setUp(self) -> None:
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -147,7 +147,7 @@ class UploadVideoView(LoginRequiredMixin, UpdateView):
 | 
				
			|||||||
    def dispatch(self, request, *args, **kwargs):
 | 
					    def dispatch(self, request, *args, **kwargs):
 | 
				
			||||||
        user = request.user
 | 
					        user = request.user
 | 
				
			||||||
        if user.registration.is_admin or user.registration.participates\
 | 
					        if user.registration.is_admin or user.registration.participates\
 | 
				
			||||||
                and user.registration.team.participation.pk == self.object.participation.pk:
 | 
					                and user.registration.team.participation.pk == self.get_object().participation.pk:
 | 
				
			||||||
            return super().dispatch(request, *args, **kwargs)
 | 
					            return super().dispatch(request, *args, **kwargs)
 | 
				
			||||||
        raise PermissionDenied
 | 
					        raise PermissionDenied
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -4,7 +4,7 @@ from corres2math.tokens import email_validation_token
 | 
				
			|||||||
from django.conf import settings
 | 
					from django.conf import settings
 | 
				
			||||||
from django.contrib.auth.mixins import LoginRequiredMixin
 | 
					from django.contrib.auth.mixins import LoginRequiredMixin
 | 
				
			||||||
from django.contrib.auth.models import User
 | 
					from django.contrib.auth.models import User
 | 
				
			||||||
from django.core.exceptions import ValidationError, PermissionDenied
 | 
					from django.core.exceptions import PermissionDenied, ValidationError
 | 
				
			||||||
from django.db import transaction
 | 
					from django.db import transaction
 | 
				
			||||||
from django.http import FileResponse, Http404
 | 
					from django.http import FileResponse, Http404
 | 
				
			||||||
from django.shortcuts import redirect, resolve_url
 | 
					from django.shortcuts import redirect, resolve_url
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user