|
16 | 16 | ArtifactListFolderResponse, |
17 | 17 | ArtifactListResponse, |
18 | 18 | Checksums, |
| 19 | + OriginalChecksums, |
19 | 20 | ) |
20 | 21 |
|
21 | 22 | URL = "http://localhost:8080/artifactory" |
@@ -609,6 +610,113 @@ def test_checksum_defined_file(file_path: Path, expected_sha1: str, expected_md5 |
609 | 610 | assert result == expected |
610 | 611 |
|
611 | 612 |
|
| 613 | +@pytest.mark.parametrize( |
| 614 | + "file_info,expected_checksums", |
| 615 | + [ |
| 616 | + pytest.param( |
| 617 | + { |
| 618 | + **FILE_INFO_RESPONSE.copy(), |
| 619 | + "originalChecksums": { |
| 620 | + "md5": "4cf609e0fe1267df8815bc650f5851e9", |
| 621 | + "sha256": "396cf16e8ce000342c95ffc7feb2a15701d0994b70c1b13fea7112f85ac8e858", |
| 622 | + }, |
| 623 | + }, |
| 624 | + { |
| 625 | + "md5": "4cf609e0fe1267df8815bc650f5851e9", |
| 626 | + "sha256": "396cf16e8ce000342c95ffc7feb2a15701d0994b70c1b13fea7112f85ac8e858", |
| 627 | + }, |
| 628 | + id="md5", |
| 629 | + ), |
| 630 | + pytest.param( |
| 631 | + { |
| 632 | + **FILE_INFO_RESPONSE.copy(), |
| 633 | + "originalChecksums": { |
| 634 | + "sha1": "962c287c760e03b03c17eb920f5358d05f44dd3b", |
| 635 | + "sha256": "396cf16e8ce000342c95ffc7feb2a15701d0994b70c1b13fea7112f85ac8e858", |
| 636 | + }, |
| 637 | + }, |
| 638 | + { |
| 639 | + "sha1": "962c287c760e03b03c17eb920f5358d05f44dd3b", |
| 640 | + "sha256": "396cf16e8ce000342c95ffc7feb2a15701d0994b70c1b13fea7112f85ac8e858", |
| 641 | + }, |
| 642 | + id="sha1", |
| 643 | + ), |
| 644 | + pytest.param( |
| 645 | + { |
| 646 | + **FILE_INFO_RESPONSE.copy(), |
| 647 | + "originalChecksums": {"sha256": "396cf16e8ce000342c95ffc7feb2a15701d0994b70c1b13fea7112f85ac8e858"}, |
| 648 | + }, |
| 649 | + {"sha256": "396cf16e8ce000342c95ffc7feb2a15701d0994b70c1b13fea7112f85ac8e858"}, |
| 650 | + id="sha256", |
| 651 | + ), |
| 652 | + pytest.param( |
| 653 | + { |
| 654 | + **FILE_INFO_RESPONSE.copy(), |
| 655 | + "originalChecksums": { |
| 656 | + "md5": "4cf609e0fe1267df8815bc650f5851e9", |
| 657 | + "sha1": "962c287c760e03b03c17eb920f5358d05f44dd3b", |
| 658 | + "sha256": "396cf16e8ce000342c95ffc7feb2a15701d0994b70c1b13fea7112f85ac8e858", |
| 659 | + }, |
| 660 | + }, |
| 661 | + { |
| 662 | + "sha256": "396cf16e8ce000342c95ffc7feb2a15701d0994b70c1b13fea7112f85ac8e858", |
| 663 | + "md5": "4cf609e0fe1267df8815bc650f5851e9", |
| 664 | + "sha1": "962c287c760e03b03c17eb920f5358d05f44dd3b", |
| 665 | + }, |
| 666 | + id="md5&sha1", |
| 667 | + ), |
| 668 | + ], |
| 669 | +) |
| 670 | +@responses.activate |
| 671 | +def test_deploy_artifact_with_checksum_algorithms_success(file_info: dict, expected_checksums: dict): |
| 672 | + responses.add(responses.PUT, f"{URL}/{ARTIFACT_PATH}", status=200) |
| 673 | + responses.add( |
| 674 | + responses.GET, |
| 675 | + f"{URL}/api/storage/{ARTIFACT_PATH}", |
| 676 | + json=file_info, |
| 677 | + status=200, |
| 678 | + ) |
| 679 | + expected = OriginalChecksums(**expected_checksums) |
| 680 | + artifactory = ArtifactoryArtifact(AuthModel(url=URL, auth=AUTH)) |
| 681 | + artifact = artifactory.deploy( |
| 682 | + Path(LOCAL_FILE_LOCATION), |
| 683 | + Path(ARTIFACT_PATH), |
| 684 | + checksum_algorithms=file_info["originalChecksums"].keys(), |
| 685 | + ) |
| 686 | + assert expected == artifact.originalChecksums |
| 687 | + |
| 688 | + |
| 689 | +@pytest.mark.parametrize( |
| 690 | + "file_info", |
| 691 | + [ |
| 692 | + pytest.param( |
| 693 | + { |
| 694 | + **FILE_INFO_RESPONSE.copy(), |
| 695 | + "originalChecksums": {"sha224": "d14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f"}, |
| 696 | + }, |
| 697 | + id="sha224", |
| 698 | + ), |
| 699 | + ], |
| 700 | +) |
| 701 | +@responses.activate |
| 702 | +def test_deploy_artifact_with_checksum_algorithms_error(file_info: dict): |
| 703 | + responses.add(responses.PUT, f"{URL}/{ARTIFACT_PATH}", status=409) |
| 704 | + |
| 705 | + responses.add( |
| 706 | + responses.GET, |
| 707 | + f"{URL}/api/storage/{ARTIFACT_PATH}", |
| 708 | + json=file_info, |
| 709 | + status=200, |
| 710 | + ) |
| 711 | + with pytest.raises(Exception): |
| 712 | + artifactory = ArtifactoryArtifact(AuthModel(url=URL, auth=AUTH)) |
| 713 | + artifactory.deploy( |
| 714 | + Path(LOCAL_FILE_LOCATION), |
| 715 | + Path(ARTIFACT_PATH), |
| 716 | + checksum_algorithms=file_info["originalChecksums"].keys(), |
| 717 | + ) |
| 718 | + |
| 719 | + |
612 | 720 | @responses.activate |
613 | 721 | def test_deploy_artifact_with_checksum_success(mocker): |
614 | 722 | responses.add(responses.PUT, f"{URL}/{ARTIFACT_PATH}", status=200) |
|
0 commit comments