Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fix : améliorer le message d'erreur avec un mauvais format du fichier import achatss #3878

Merged
merged 1 commit into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions api/tests/files/corrupt_purchase_import.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
"cantine SIRET,""description"",""fournisseur"",""date"",""prix HT"",""famille"",""caractéristiques"",""definition de local"""
"82399356058716,""weird formatting"",""Le bon traiteur"",""2022-05-02"",""90.11"",""PRODUITS_LAITIERS"",""LOCAL"",""REGION"""
13 changes: 13 additions & 0 deletions api/tests/test_import_purchases.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,19 @@ def test_import_bad_purchases(self):
"Format fichier : 7-8 colonnes attendues, 6 trouvées.",
)

@authenticate
def test_import_corrupt_purchases_file(self):
"""
A reasonable error should be thrown
"""
CanteenFactory.create(siret="82399356058716", managers=[authenticate.user])
with open("./api/tests/files/corrupt_purchase_import.csv") as purchase_file:
response = self.client.post(reverse("import_purchases"), {"file": purchase_file})
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(Purchase.objects.count(), 0)
errors = response.json()["errors"]
self.assertEqual(errors.pop(0)["message"], "Format fichier : 7-8 colonnes attendues, 1 trouvées.")

@authenticate
def test_warn_duplicate_file(self):
"""
Expand Down
1 change: 1 addition & 0 deletions api/views/purchaseimport.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ def _process_chunk(self, chunk):

csvreader = csv.reader(io.StringIO("".join(chunk)), self.dialect)
for row_number, row in enumerate(csvreader, start=1):
siret = None
# If header, pass
if row_number == 1 and row[0].lower().__contains__("siret"):
continue
Expand Down
Loading