From 1f9f60d880df78efef58d33b4de4a835bb054d71 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Tue, 22 Dec 2020 20:57:03 +0100 Subject: [PATCH] Unit test for large files uploading --- apps/registration/tests.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/apps/registration/tests.py b/apps/registration/tests.py index ad1ddc2..1ce4bea 100644 --- a/apps/registration/tests.py +++ b/apps/registration/tests.py @@ -1,6 +1,8 @@ from datetime import timedelta import os +from django.core.files.uploadedfile import SimpleUploadedFile + from corres2math.tokens import email_validation_token from django.contrib.auth.models import User from django.contrib.contenttypes.models import ContentType @@ -286,6 +288,14 @@ class TestRegistration(TestCase): )) self.assertEqual(response.status_code, 200) + # Don't send too large files + response = self.client.post(reverse("registration:upload_user_photo_authorization", + args=(self.student.registration.pk,)), data=dict( + photo_authorization=SimpleUploadedFile("file.pdf",content=int(0).to_bytes(2000001, "big"), + content_type="application/pdf"), + )) + self.assertEqual(response.status_code, 200) + response = self.client.post(reverse("registration:upload_user_photo_authorization", args=(self.student.registration.pk,)), data=dict( photo_authorization=open("corres2math/static/Autorisation de droit à l'image - majeur.pdf", "rb"),