Skip to content

Commit

Permalink
Merge pull request #3673 from unicef/ch32250-improve-supply-items-lis…
Browse files Browse the repository at this point in the history
…t-validation

[PMP] Supply list upload: Successful upload for inappropriate list
  • Loading branch information
robertavram authored Jun 4, 2024
2 parents b15c3a5 + 6335817 commit 537b304
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-03-26 12:56+0000\n"
"POT-Creation-Date: 2024-05-21 04:41+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down Expand Up @@ -2110,6 +2110,9 @@ msgstr "تم إرسال PD بالفعل إلى الشريك."
msgid "Meeting date is not available."
msgstr "تاريخ الاجتماع غير متاح."

msgid "No valid data found in the file."
msgstr ""

msgid "Action is not allowed"
msgstr "الإجراء غير مسموح به"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ msgid ""
msgstr ""
"Project-Id-Version: et-partners2-bk\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-03-26 12:56+0000\n"
"POT-Creation-Date: 2024-05-21 04:41+0000\n"
"Language: es\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
Expand Down Expand Up @@ -2160,6 +2160,9 @@ msgstr "El PD ya se ha enviado al socio."
msgid "Meeting date is not available."
msgstr "La fecha de la reunión no está disponible."

msgid "No valid data found in the file."
msgstr ""

msgid "Action is not allowed"
msgstr "No se permite la acción"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-03-26 12:56+0000\n"
"POT-Creation-Date: 2024-05-21 04:41+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down Expand Up @@ -2175,6 +2175,9 @@ msgstr "PD a déjà été envoyé au partenaire."
msgid "Meeting date is not available."
msgstr "La date de la réunion n'est pas disponible."

msgid "No valid data found in the file."
msgstr ""

msgid "Action is not allowed"
msgstr "L'action n'est pas autorisée"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-03-26 12:56+0000\n"
"POT-Creation-Date: 2024-05-21 04:41+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down Expand Up @@ -2186,6 +2186,9 @@ msgstr "O PD já foi enviado ao parceiro."
msgid "Meeting date is not available."
msgstr "A data da reunião não está disponível."

msgid "No valid data found in the file."
msgstr ""

msgid "Action is not allowed"
msgstr "A ação não é permitida"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-03-26 12:56+0000\n"
"POT-Creation-Date: 2024-05-21 04:41+0000\n"
"Language: ru\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
Expand Down Expand Up @@ -2155,6 +2155,9 @@ msgstr "PD уже отправлен партнеру."
msgid "Meeting date is not available."
msgstr "Дата встречи неизвестна."

msgid "No valid data found in the file."
msgstr ""

msgid "Action is not allowed"
msgstr "Действие не разрешено"

Expand Down
24 changes: 24 additions & 0 deletions src/etools/applications/partners/tests/test_v3_interventions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1671,6 +1671,30 @@ def test_upload_invalid_file(self):
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
self.assertIn("supply_items_file", response.data)

def test_upload_no_valid_data(self):
response = self.forced_auth_req(
"post",
reverse(
"pmp_v3:intervention-supply-item-upload",
args=[self.intervention.pk],
),
data={
"supply_items_file": SimpleUploadedFile(
'my_list.csv',
u'''"unknown column","column2"\n
42,"qwert"\n
43,"asdf"\n
'''.encode('utf-8'),
content_type="multipart/form-data",
),
},
user=self.unicef_user,
request_format=None,
)
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
self.assertIn("supply_items_file", response.data)
self.assertEqual(response.data["supply_items_file"], "No valid data found in the file.")

def test_upload_invalid_file_row(self):
supply_items_file = SimpleUploadedFile(
'my_list.csv',
Expand Down
5 changes: 5 additions & 0 deletions src/etools/applications/partners/views/interventions_v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,11 @@ def post(self, request, *args, **kwargs):
{"supply_items_file": err.detail},
status.HTTP_400_BAD_REQUEST,
)
if not file_data:
return Response(
{"supply_items_file": _("No valid data found in the file.")},
status.HTTP_400_BAD_REQUEST,
)

# update all supply items related to intervention
for title, unit_number, unit_price, product_number in file_data:
Expand Down

0 comments on commit 537b304

Please sign in to comment.