From dee215261698ed0b1327f55269cc94ce257b3782 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Mon, 2 Nov 2020 16:00:08 +0100 Subject: [PATCH] Test get absolute urls --- apps/registration/tests.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/apps/registration/tests.py b/apps/registration/tests.py index dcef4a8..c25a09b 100644 --- a/apps/registration/tests.py +++ b/apps/registration/tests.py @@ -1,15 +1,17 @@ import os -from django.core.management import call_command +from django.contrib.sites.models import Site from corres2math.tokens import email_validation_token +from django.contrib.contenttypes.models import ContentType from django.contrib.auth.models import User +from django.core.management import call_command from django.test import TestCase from django.urls import reverse from django.utils.encoding import force_bytes from django.utils.http import urlsafe_base64_encode -from .models import CoachRegistration, Registration, StudentRegistration +from .models import AdminRegistration, CoachRegistration, Registration, StudentRegistration class TestIndexPage(TestCase): @@ -52,14 +54,29 @@ class TestRegistration(TestCase): response = self.client.get(reverse("admin:index") + f"registration/registration/{self.user.registration.pk}/change/") self.assertEqual(response.status_code, 200) + response = self.client.get(reverse("admin:index") + + f"r/{ContentType.objects.get_for_model(AdminRegistration).id}/" + f"{self.user.registration.pk}/") + self.assertRedirects(response, "http://" + Site.objects.get().domain + + str(self.user.registration.get_absolute_url()), 302, 200) response = self.client.get(reverse("admin:index") + f"registration/registration/{self.student.registration.pk}/change/") self.assertEqual(response.status_code, 200) + response = self.client.get(reverse("admin:index") + + f"r/{ContentType.objects.get_for_model(StudentRegistration).id}/" + f"{self.student.registration.pk}/") + self.assertRedirects(response, "http://" + Site.objects.get().domain + + str(self.student.registration.get_absolute_url()), 302, 200) response = self.client.get(reverse("admin:index") + f"registration/registration/{self.coach.registration.pk}/change/") self.assertEqual(response.status_code, 200) + response = self.client.get(reverse("admin:index") + + f"r/{ContentType.objects.get_for_model(CoachRegistration).id}/" + f"{self.coach.registration.pk}/") + self.assertRedirects(response, "http://" + Site.objects.get().domain + + str(self.coach.registration.get_absolute_url()), 302, 200) def test_registration(self): """