From 9d25df1e4e0c7a64898ad5014969807ec0e2fffc Mon Sep 17 00:00:00 2001 From: hfroot <9282816+hfroot@users.noreply.github.com> Date: Wed, 11 Dec 2024 17:51:46 +0100 Subject: [PATCH] =?UTF-8?q?fix(Import=20cantines):=20reparer=20le=20cas=20?= =?UTF-8?q?o=C3=B9=20on=20veut=20ajouter=20des=20gestionnaires=20mais=20on?= =?UTF-8?q?=20n'a=20pas=20des=20colonnes=20vides=20en=20plus=20(#4754)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/tests/files/canteen_manager_import.csv | 1 + api/tests/test_import_diagnostics.py | 16 ++++++++++++++++ api/views/diagnosticimport.py | 2 +- 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 api/tests/files/canteen_manager_import.csv diff --git a/api/tests/files/canteen_manager_import.csv b/api/tests/files/canteen_manager_import.csv new file mode 100644 index 0000000000..7b7b01a796 --- /dev/null +++ b/api/tests/files/canteen_manager_import.csv @@ -0,0 +1 @@ +21340172201787,A canteen,,54460,,700,14000,,site,conceded,,manager@example.com diff --git a/api/tests/test_import_diagnostics.py b/api/tests/test_import_diagnostics.py index 07568ec6bf..3ae9fbe941 100644 --- a/api/tests/test_import_diagnostics.py +++ b/api/tests/test_import_diagnostics.py @@ -285,6 +285,22 @@ def test_import_only_canteens(self, _): self.assertEqual(Canteen.objects.count(), 1) self.assertEqual(Canteen.objects.first().economic_model, None) + @authenticate + def test_import_canteens_with_managers(self, _): + """ + Should be able to import canteens from a file that doesn't contain any diagnostic fields + """ + manager = UserFactory(email="manager@example.com") + with open("./api/tests/files/canteen_manager_import.csv") as diag_file: + response = self.client.post(reverse("import_diagnostics"), {"file": diag_file}) + self.assertEqual(response.status_code, status.HTTP_200_OK) + body = response.json() + self.assertEqual(body["count"], 0) + self.assertEqual(len(body["errors"]), 0, body["errors"]) + self.assertEqual(Diagnostic.objects.count(), 0) + self.assertEqual(Canteen.objects.count(), 1) + self.assertIn(manager, Canteen.objects.first().managers.all()) + @authenticate def test_staff_import(self, _): """ diff --git a/api/views/diagnosticimport.py b/api/views/diagnosticimport.py index 4b79875cfd..e830fcb5b1 100644 --- a/api/views/diagnosticimport.py +++ b/api/views/diagnosticimport.py @@ -332,7 +332,7 @@ def _validate_canteen(row): def _get_manager_emails_to_notify(self, row): try: manager_emails = [] - if len(row) > self.manager_column_idx + 1 and row[self.manager_column_idx]: + if len(row) > self.manager_column_idx and row[self.manager_column_idx]: manager_emails = ImportDiagnosticsView._get_manager_emails(row[self.manager_column_idx]) except Exception: raise ValidationError(