|
1 | 1 | import json |
2 | 2 | from io import BytesIO |
3 | 3 |
|
| 4 | +from django.core.files.uploadedfile import SimpleUploadedFile |
4 | 5 | import hypothesis.strategies as st |
5 | 6 | import jsonschema_specifications |
6 | 7 | from hypothesis import HealthCheck, given, settings |
7 | 8 | from hypothesis.extra.django import TestCase, from_model |
8 | 9 | from hypothesis_jsonschema import from_schema |
9 | 10 |
|
10 | | -from ..import_export import export_data, import_data |
| 11 | +from ..import_export import export_data, import_data, import_upload |
11 | 12 | from ..models import ObjectType, ObjectTypeVersion |
12 | 13 | from ..utils import check_json_schema |
13 | 14 |
|
@@ -267,3 +268,31 @@ def test_export_import_with_new_uuid(self, original_type: ObjectType) -> None: |
267 | 268 | assert imported_version.json_schema == original_version.json_schema |
268 | 269 | assert imported_version.status == original_version.status |
269 | 270 | assert imported_version.published_at == original_version.published_at |
| 271 | + |
| 272 | + |
| 273 | + @given(objecttypes(), objecttypes()) |
| 274 | + @settings(suppress_health_check=[HealthCheck.too_slow]) |
| 275 | + def test_import_upload_list_of_files(self, ot1, ot2): |
| 276 | + output1 = BytesIO() |
| 277 | + output2 = BytesIO() |
| 278 | + |
| 279 | + export_data(output1, objecttypes=[ot1]) |
| 280 | + export_data(output2, objecttypes=[ot2]) |
| 281 | + |
| 282 | + file1 = SimpleUploadedFile( |
| 283 | + "file1.zip", output1.getvalue(), content_type="application/zip" |
| 284 | + ) |
| 285 | + file2 = SimpleUploadedFile( |
| 286 | + "file2.zip", output2.getvalue(), content_type="application/zip" |
| 287 | + ) |
| 288 | + |
| 289 | + ObjectType.objects.all().delete() |
| 290 | + |
| 291 | + errors = [] |
| 292 | + def report_error(msg): |
| 293 | + errors.append(msg) |
| 294 | + |
| 295 | + import_upload([file1, file2], keep_uuid=True, report_error_to_user=report_error) |
| 296 | + |
| 297 | + assert set(ObjectType.objects.all().values_list("name", flat=True)) == {ot1.name.strip(), ot2.name.strip()} |
| 298 | + assert errors == [] |
0 commit comments