fix: align media upload and gosedo records
All checks were successful
All checks were successful
This commit is contained in:
@@ -18,6 +18,7 @@ from apps.parsers.gosedo import (
|
||||
stable_gosedo_uid,
|
||||
)
|
||||
from apps.parsers.media_news import (
|
||||
MEDIA_NEWS_MAX_BYTES,
|
||||
import_media_news,
|
||||
normalize_news_text,
|
||||
stable_media_external_id,
|
||||
@@ -619,6 +620,58 @@ class MediaNewsPermissionsTest(APITestCase):
|
||||
task_id,
|
||||
)
|
||||
|
||||
def test_upload_rejects_non_xlsx_before_saving_or_queueing(self):
|
||||
self.client.force_authenticate(self.admin)
|
||||
with patch("apps.parsers.views._save_uploaded_parser_file") as save_file, patch(
|
||||
"apps.parsers.tasks.parse_media_news.apply_async"
|
||||
) as apply_async:
|
||||
response = self.client.post(
|
||||
self.url,
|
||||
{"file": SimpleUploadedFile("media.csv", b"headline")},
|
||||
format="multipart",
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
|
||||
self.assertEqual(response.data["errors"][0]["code"], "invalid_file_type")
|
||||
save_file.assert_not_called()
|
||||
apply_async.assert_not_called()
|
||||
|
||||
def test_upload_rejects_oversized_xlsx_before_saving_or_queueing(self):
|
||||
self.client.force_authenticate(self.admin)
|
||||
with patch("apps.parsers.views.MEDIA_NEWS_MAX_BYTES", 1), patch(
|
||||
"apps.parsers.views._save_uploaded_parser_file"
|
||||
) as save_file, patch(
|
||||
"apps.parsers.tasks.parse_media_news.apply_async"
|
||||
) as apply_async:
|
||||
response = self.client.post(
|
||||
self.url,
|
||||
{"file": SimpleUploadedFile("media.xlsx", b"xx")},
|
||||
format="multipart",
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
|
||||
self.assertEqual(response.data["errors"][0]["code"], "file_too_large")
|
||||
save_file.assert_not_called()
|
||||
apply_async.assert_not_called()
|
||||
|
||||
def test_upload_accepts_xlsx_at_size_limit(self):
|
||||
self.client.force_authenticate(self.admin)
|
||||
with patch("apps.parsers.views.MEDIA_NEWS_MAX_BYTES", 1), patch(
|
||||
"apps.parsers.views._save_uploaded_parser_file",
|
||||
return_value="parser_uploads/media.xlsx",
|
||||
), patch(
|
||||
"apps.parsers.tasks.parse_media_news.apply_async",
|
||||
side_effect=lambda **kwargs: SimpleNamespace(id=kwargs["task_id"]),
|
||||
):
|
||||
response = self.client.post(
|
||||
self.url,
|
||||
{"file": SimpleUploadedFile("media.xlsx", b"x")},
|
||||
format="multipart",
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)
|
||||
self.assertEqual(MEDIA_NEWS_MAX_BYTES, 25 * 1024 * 1024)
|
||||
|
||||
def test_gosedo_manual_run_is_admin_only_and_returns_task_ids(self):
|
||||
url = reverse(
|
||||
"api_v1:parsers:run-parser",
|
||||
|
||||
Reference in New Issue
Block a user