feat: import integrated structures from a ZIP archive
Some checks failed
Mostovik Backend CI/CD / Tests and lint (push) Failing after 3m15s
Mostovik Backend CI/CD / Build linux/amd64 release images (push) Has been skipped
Mostovik Backend CI/CD / Deploy dev (push) Has been skipped
Mostovik Backend CI/CD / Deploy and verify internal main (push) Has been skipped
Some checks failed
Mostovik Backend CI/CD / Tests and lint (push) Failing after 3m15s
Mostovik Backend CI/CD / Build linux/amd64 release images (push) Has been skipped
Mostovik Backend CI/CD / Deploy dev (push) Has been skipped
Mostovik Backend CI/CD / Deploy and verify internal main (push) Has been skipped
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
from io import BytesIO
|
||||
from unittest.mock import patch
|
||||
from zipfile import ZIP_DEFLATED, ZipFile
|
||||
|
||||
from apps.parsers.integrated_structure_workbook import (
|
||||
IntegratedWorkbookError,
|
||||
@@ -42,6 +43,16 @@ def workbook_bytes(*, okpo="00084008", doc_id=93, document_stage=1137):
|
||||
return stream.getvalue()
|
||||
|
||||
|
||||
def archive_bytes(raw, attachments=()):
|
||||
stream = BytesIO()
|
||||
with ZipFile(stream, "w", compression=ZIP_DEFLATED) as archive:
|
||||
archive.writestr("test.xlsx", raw)
|
||||
for attachment in attachments:
|
||||
attachment.seek(0)
|
||||
archive.writestr(attachment.name, attachment.read())
|
||||
return stream.getvalue()
|
||||
|
||||
|
||||
class IntegratedWorkbookTest(SimpleTestCase):
|
||||
def test_parses_relations_and_preserves_zero_padded_okpo(self):
|
||||
result = parse_integrated_workbook(BytesIO(workbook_bytes()))
|
||||
@@ -244,14 +255,14 @@ class IntegratedStructureImportTest(TestCase):
|
||||
client.force_authenticate(user)
|
||||
response = client.post(
|
||||
url,
|
||||
{"workbook": SimpleUploadedFile("test.xlsx", workbook_bytes())},
|
||||
{"archive": SimpleUploadedFile("test.zip", archive_bytes(workbook_bytes()))},
|
||||
format="multipart",
|
||||
)
|
||||
self.assertEqual(response.status_code, 403)
|
||||
client.force_authenticate(admin)
|
||||
response = client.post(
|
||||
url,
|
||||
{"workbook": SimpleUploadedFile("test.xlsx", workbook_bytes())},
|
||||
{"archive": SimpleUploadedFile("test.zip", archive_bytes(workbook_bytes()))},
|
||||
format="multipart",
|
||||
)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
@@ -275,7 +286,7 @@ class IntegratedStructureImportTest(TestCase):
|
||||
):
|
||||
response = client.post(
|
||||
"/api/v1/parsers/upload/integrated_structure_documents/",
|
||||
{"workbook": SimpleUploadedFile("test.xlsx", workbook_bytes())},
|
||||
{"archive": SimpleUploadedFile("test.zip", archive_bytes(workbook_bytes()))},
|
||||
format="multipart",
|
||||
)
|
||||
self.assertEqual(response.status_code, 500)
|
||||
|
||||
Reference in New Issue
Block a user