From 7bb8033f0c5b97ad047a33fa7c3cf94ebfd3e34a Mon Sep 17 00:00:00 2001
From: Bryan Brancotte <bryan.brancotte@pasteur.fr>
Date: Tue, 8 Apr 2025 10:10:33 +0200
Subject: [PATCH 1/3] stop as soon as error is seen

---
 src/strass/strass_app/forms.py                |  2 +
 .../strass_app/tests/test_candidate_apply.py  | 40 +++++++++++++++++++
 2 files changed, 42 insertions(+)

diff --git a/src/strass/strass_app/forms.py b/src/strass/strass_app/forms.py
index e74b9b09..5b2a9eca 100644
--- a/src/strass/strass_app/forms.py
+++ b/src/strass/strass_app/forms.py
@@ -378,6 +378,8 @@ class CandidateForm(ModelFormWithReadOnly):
 
     def clean(self):
         cleaned_data = super().clean()
+        if self.errors:
+            return cleaned_data
         if len(cleaned_data.get("profiles", [])) > live_settings.max_num_profile__int > 0:
             raise ValidationError(
                 {
diff --git a/src/strass/strass_app/tests/test_candidate_apply.py b/src/strass/strass_app/tests/test_candidate_apply.py
index f32f596e..4d2ffac4 100644
--- a/src/strass/strass_app/tests/test_candidate_apply.py
+++ b/src/strass/strass_app/tests/test_candidate_apply.py
@@ -1191,6 +1191,46 @@ class TestCandidateApply(TooledTestCase):
             "all question must have an answer, even empty",
         )
 
+    def test_apply_with_wrong_email(self):
+        live_settings.show_email_as_message = False
+        live_settings.max_num_referee = 0
+        live_settings.cv_enabled = False
+        load_demo.create_candidate_questions(load_demo.create_faker_instance(0))
+        steps = list()
+
+        #######################################################################
+        # Apply
+        #######################################################################
+        candidate_wizard = "candidate_wizard"
+        url = reverse('strass:candidate-apply')
+        # self.client.force_login(self.user)
+        response_home = self.client.get(url, follow=True)
+        target = response_home.redirect_chain[0][0]
+        step_name = target.split("/")[-2]
+        form_data = {f"{candidate_wizard}-current_step": target.split("/")[-2]}
+        response = self.client.post(target, form_data, follow=True)
+        self.assertEqual(response.status_code, 200)
+        steps.append(WizardStep(target=target, response=response, form_data=form_data, step_name=step_name))
+        del target, response, form_data, step_name
+        del response_home, url
+
+        target = steps[-1].response.redirect_chain[0][0]
+
+        step_name = target.split("/")[-2]
+        cv = open(os.path.join(self.test_data, "cv.pdf"), "rb")
+        form_data = {
+            step_name + "-first_name": "Ada",
+            step_name + "-last_name": "Lovelace",
+            step_name + "-email": "ada.lovelace@pasteurfr", # dot is missing
+            step_name + "-profiles": "2",
+            step_name + "-motivation": "Yes I am !",
+            step_name + "-cv": SimpleUploadedFile(cv.name, cv.read(), content_type="application/pdf"),
+            step_name + "-lang": "en",
+            f"{candidate_wizard}-current_step": step_name,
+        }
+        response = self.client.post(target, form_data, follow=False)
+        self.assertEqual(response.status_code, 200)
+
     def test_reviewers_notification(self):
         fake = Faker()
         fake.seed_instance(0)
-- 
GitLab


From 858c7065b355b9cca79e126f880f45d3bd522444 Mon Sep 17 00:00:00 2001
From: Bryan Brancotte <bryan.brancotte@pasteur.fr>
Date: Tue, 8 Apr 2025 10:31:23 +0200
Subject: [PATCH 2/3] testfix, create profiles

---
 src/strass/strass_app/tests/test_forms.py | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/strass/strass_app/tests/test_forms.py b/src/strass/strass_app/tests/test_forms.py
index 22a408d9..69e5ab83 100644
--- a/src/strass/strass_app/tests/test_forms.py
+++ b/src/strass/strass_app/tests/test_forms.py
@@ -21,10 +21,11 @@ import os
 import pathlib
 import random
 from tempfile import NamedTemporaryFile
-from django.core import mail
 
+import live_settings
 from crispy_forms import layout
 from django.contrib.auth.models import AnonymousUser
+from django.core import mail
 from django.core.files.uploadedfile import SimpleUploadedFile
 from django.template import Template, Context
 from django.test import RequestFactory
@@ -32,6 +33,7 @@ from freezegun import freeze_time
 
 from strass_app import forms
 from strass_app.forms import EmptyForm
+from strass_app.management.commands import load_demo
 from strass_app.tests.test_base_test_case import TooledTestCase
 
 logger = logging.getLogger(__name__)
@@ -59,6 +61,7 @@ class TestMain(TooledTestCase):
 
 class TestCandidateForm(TooledTestCase):
     def test_pdf_safe_crashes_log_collected(self):
+        load_demo.create_profiles()
         mail_count = len(mail.outbox)
         m = random.randint(1, 12)
         d = random.randint(1, 28)
@@ -72,7 +75,7 @@ class TestCandidateForm(TooledTestCase):
                     "first_name": "Ada",
                     "last_name": "Lovelace",
                     "email": "ada.lovelace@pasteur.fr",
-                    "profiles": "2",
+                    "profiles": [2],
                     "motivation": "Yes I am !",
                     "lang": "en",
                 },
-- 
GitLab


From 369648b99e037f450793ea5344a91053188ace01 Mon Sep 17 00:00:00 2001
From: Bryan Brancotte <bryan.brancotte@pasteur.fr>
Date: Tue, 8 Apr 2025 10:31:29 +0200
Subject: [PATCH 3/3] formatting

---
 src/strass/strass_app/tests/test_candidate_apply.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/strass/strass_app/tests/test_candidate_apply.py b/src/strass/strass_app/tests/test_candidate_apply.py
index 4d2ffac4..312280c5 100644
--- a/src/strass/strass_app/tests/test_candidate_apply.py
+++ b/src/strass/strass_app/tests/test_candidate_apply.py
@@ -1221,7 +1221,7 @@ class TestCandidateApply(TooledTestCase):
         form_data = {
             step_name + "-first_name": "Ada",
             step_name + "-last_name": "Lovelace",
-            step_name + "-email": "ada.lovelace@pasteurfr", # dot is missing
+            step_name + "-email": "ada.lovelace@pasteurfr",  # dot is missing
             step_name + "-profiles": "2",
             step_name + "-motivation": "Yes I am !",
             step_name + "-cv": SimpleUploadedFile(cv.name, cv.read(), content_type="application/pdf"),
-- 
GitLab