Skip to content

Commit

Permalink
fix(Import cantines): reparer le cas où on veut ajouter des gestionna…
Browse files Browse the repository at this point in the history
…ires mais on n'a pas des colonnes vides en plus (#4754)
  • Loading branch information
hfroot authored Dec 11, 2024
1 parent 11f7b15 commit 9d25df1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions api/tests/files/canteen_manager_import.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
21340172201787,A canteen,,54460,,700,14000,,site,conceded,,manager@example.com
16 changes: 16 additions & 0 deletions api/tests/test_import_diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, _):
"""
Expand Down
2 changes: 1 addition & 1 deletion api/views/diagnosticimport.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 9d25df1

Please sign in to comment.