|
9 | 9 |
|
10 | 10 | from unstract.sdk.constants import MimeType |
11 | 11 | from unstract.sdk.exceptions import FileOperationError |
12 | | -from unstract.sdk.file_storage.constants import StorageType |
| 12 | +from unstract.sdk.file_storage.constants import FileOperationParams, StorageType |
13 | 13 | from unstract.sdk.file_storage.env_helper import EnvHelper |
14 | 14 | from unstract.sdk.file_storage.impl import FileStorage |
15 | 15 | from unstract.sdk.file_storage.provider import FileStorageProvider |
@@ -488,29 +488,51 @@ def test_file(provider): |
488 | 488 |
|
489 | 489 |
|
490 | 490 | @pytest.mark.parametrize( |
491 | | - "file_storage, lpath, rpath", |
| 491 | + "file_storage, lpath, rpath, recursive, expected_result", |
492 | 492 | [ |
493 | 493 | ( |
494 | 494 | file_storage(provider=FileStorageProvider.GCS), |
495 | 495 | TEST_CONSTANTS.READ_TEXT_FILE, |
496 | 496 | TEST_CONSTANTS.TEST_FOLDER, |
| 497 | + True, |
| 498 | + True, |
497 | 499 | ), |
498 | 500 | ( |
499 | 501 | file_storage(provider=FileStorageProvider.LOCAL), |
500 | 502 | TEST_CONSTANTS.READ_TEXT_FILE, |
501 | 503 | TEST_CONSTANTS.TEST_FOLDER, |
| 504 | + True, |
| 505 | + True, |
| 506 | + ), |
| 507 | + ( |
| 508 | + file_storage(provider=FileStorageProvider.LOCAL), |
| 509 | + TEST_CONSTANTS.READ_FOLDER_PATH, |
| 510 | + TEST_CONSTANTS.TEST_FOLDER, |
| 511 | + True, |
| 512 | + True, |
| 513 | + ), |
| 514 | + ( |
| 515 | + file_storage(provider=FileStorageProvider.LOCAL), |
| 516 | + TEST_CONSTANTS.READ_FOLDER_PATH, |
| 517 | + TEST_CONSTANTS.TEST_FOLDER, |
| 518 | + False, |
| 519 | + False, |
502 | 520 | ), |
503 | 521 | ( |
504 | 522 | file_storage(provider=FileStorageProvider.MINIO), |
505 | 523 | TEST_CONSTANTS.READ_TEXT_FILE, |
506 | 524 | TEST_CONSTANTS.TEST_FOLDER, |
| 525 | + True, |
| 526 | + True, |
507 | 527 | ), |
508 | 528 | ], |
509 | 529 | ) |
510 | | -def test_cp(file_storage, lpath, rpath): |
511 | | - file_storage.cp(lpath, rpath, overwrite=True) |
512 | | - assert file_storage.exists(rpath) is True |
513 | | - file_storage.rm(rpath, recursive=True) |
| 530 | +def test_cp(file_storage, lpath, rpath, recursive, expected_result): |
| 531 | + file_storage.cp(lpath, rpath, recursive=recursive, overwrite=True) |
| 532 | + actual_result = file_storage.exists(rpath) |
| 533 | + assert actual_result == expected_result |
| 534 | + if actual_result: |
| 535 | + file_storage.rm(rpath, recursive=True) |
514 | 536 | assert file_storage.exists(rpath) is False |
515 | 537 |
|
516 | 538 |
|
@@ -566,49 +588,59 @@ def test_file_size(file_storage, path, expected_size): |
566 | 588 |
|
567 | 589 |
|
568 | 590 | @pytest.mark.parametrize( |
569 | | - "file_storage, path, expected_mime_type", |
| 591 | + "file_storage, path, read_length, expected_mime_type", |
570 | 592 | [ |
571 | 593 | ( |
572 | 594 | file_storage(provider=FileStorageProvider.GCS), |
573 | 595 | TEST_CONSTANTS.READ_PDF_FILE, |
| 596 | + FileOperationParams.MIME_TYPE_DEFAULT_READ_LENGTH, |
574 | 597 | MimeType.PDF, |
575 | 598 | ), |
576 | 599 | ( |
577 | 600 | file_storage(provider=FileStorageProvider.GCS), |
578 | 601 | TEST_CONSTANTS.READ_TEXT_FILE, |
| 602 | + FileOperationParams.READ_ENTIRE_LENGTH, |
579 | 603 | MimeType.TEXT, |
580 | 604 | ), |
581 | 605 | ( |
582 | 606 | file_storage(provider=FileStorageProvider.GCS), |
583 | 607 | TEST_CONSTANTS.READ_PDF_FILE, |
| 608 | + FileOperationParams.MIME_TYPE_DEFAULT_READ_LENGTH, |
584 | 609 | MimeType.PDF, |
585 | 610 | ), |
586 | 611 | ( |
587 | 612 | file_storage(provider=FileStorageProvider.LOCAL), |
588 | 613 | TEST_CONSTANTS.READ_TEXT_FILE, |
| 614 | + 50, |
589 | 615 | MimeType.TEXT, |
590 | 616 | ), |
591 | 617 | ( |
592 | 618 | file_storage(provider=FileStorageProvider.MINIO), |
593 | 619 | TEST_CONSTANTS.READ_PDF_FILE, |
| 620 | + FileOperationParams.MIME_TYPE_DEFAULT_READ_LENGTH, |
594 | 621 | MimeType.PDF, |
595 | 622 | ), |
596 | 623 | ( |
597 | 624 | file_storage(provider=FileStorageProvider.MINIO), |
598 | 625 | TEST_CONSTANTS.READ_TEXT_FILE, |
| 626 | + FileOperationParams.READ_ENTIRE_LENGTH, |
599 | 627 | MimeType.TEXT, |
600 | 628 | ), |
601 | 629 | ( |
602 | 630 | file_storage(provider=FileStorageProvider.MINIO), |
603 | 631 | TEST_CONSTANTS.READ_PDF_FILE, |
| 632 | + FileOperationParams.MIME_TYPE_DEFAULT_READ_LENGTH, |
604 | 633 | MimeType.PDF, |
605 | 634 | ), |
606 | 635 | ], |
607 | 636 | ) |
608 | | -def test_file_mime_type(file_storage, path, expected_mime_type): |
| 637 | +def test_file_mime_type(file_storage, path, read_length, expected_mime_type): |
609 | 638 | mime_type = file_storage.mime_type(path=path) |
610 | 639 | file_storage.mkdir(path=TEST_CONSTANTS.READ_FOLDER_PATH) |
611 | 640 | assert mime_type == expected_mime_type |
| 641 | + mime_type_read_length = file_storage.mime_type(path=path, read_length=read_length) |
| 642 | + file_storage.mkdir(path=TEST_CONSTANTS.READ_FOLDER_PATH) |
| 643 | + assert mime_type_read_length == expected_mime_type |
612 | 644 |
|
613 | 645 |
|
614 | 646 | @pytest.mark.parametrize( |
|
0 commit comments