Test photo authorization upload

This commit is contained in:
Yohann D'ANELLO 2020-09-27 17:06:05 +02:00
parent 366f0c40a0
commit 3b73edd6b0
3 changed files with 35 additions and 1 deletions

View File

@ -8,7 +8,7 @@ py38:
before_script:
- apk add --no-cache libmagic
- pip install tox --no-cache-dir
script: tox -e py38-django31
script: tox -e py38
linters:
stage: quality-assurance

View File

@ -122,10 +122,19 @@ class TestStudentParticipation(TestCase):
self.assertRedirects(response, reverse("participation:team_detail", args=(self.team.pk,)), 302, 200)
self.assertTrue(Team.objects.filter(trigram="BBB", participation__problem=3).exists())
def test_no_myparticipation_redirect_nomyparticipation(self):
response = self.client.get(reverse("participation:my_participation_detail"))
self.assertTrue(response.status_code, 200)
def test_participation_detail(self):
self.user.registration.team = self.team
self.user.registration.save()
response = self.client.get(reverse("participation:my_participation_detail"))
self.assertRedirects(response,
reverse("participation:participation_detail", args=(self.team.participation.pk,)),
302, 200)
response = self.client.get(reverse("participation:participation_detail", args=(self.team.participation.pk,)))
self.assertEqual(response.status_code, 200)

View File

@ -145,6 +145,31 @@ class TestRegistration(TestCase):
self.assertFalse(user.registration.email_confirmed)
self.assertEqual(user.first_name, "Changed")
def test_upload_photo_authorization(self):
response = self.client.get(reverse("registration:upload_user_photo_authorization",
args=(self.student.registration.pk,)))
self.assertEqual(response.status_code, 200)
# README is not a valid PDF file
response = self.client.post(reverse("registration:upload_user_photo_authorization",
args=(self.student.registration.pk,)), data=dict(
photo_authorization=open("README.md", "rb"),
))
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"),
))
self.assertRedirects(response, reverse("registration:user_detail", args=(self.student.pk,)), 302, 200)
self.student.registration.refresh_from_db()
self.assertTrue(self.student.registration.photo_authorization)
response = self.client.get(reverse("photo_authorization",
args=(self.student.registration.photo_authorization.name.split('/')[-1],)))
self.assertEqual(response.status_code, 200)
def test_string_render(self):
# TODO These string field tests will be removed when used in a template
str(self.user.registration)