def test_get_artifact_file_info_success(): responses.add( responses.GET, f"{URL}/api/storage/{ARTIFACT_PATH}", status=200, json=FILE_INFO_RESPONSE, ) artifactory = ArtifactoryArtifact(AuthModel(url=URL, auth=AUTH)) artifact = artifactory.info(ARTIFACT_PATH) assert artifact.dict() == FILE_INFO.dict()
def test_get_artifact_single_property_success(): responses.add( responses.GET, f"{URL}/api/storage/{ARTIFACT_PATH}?properties=prop1", json=ARTIFACT_ONE_PROPERTY.dict(), status=200, ) artifactory = ArtifactoryArtifact(AuthModel(url=URL, auth=AUTH)) artifact_properties = artifactory.properties(ARTIFACT_PATH, ["prop1"]) assert artifact_properties.dict() == ARTIFACT_ONE_PROPERTY.dict()
def test_get_artifact_folder_info_success(): responses.add( responses.GET, f"{URL}/api/storage/{ARTIFACT_REPO}", status=200, json=FOLDER_INFO_RESPONSE, ) artifactory = ArtifactoryArtifact(AuthModel(url=URL, auth=AUTH)) artifact = artifactory.info(ARTIFACT_REPO) assert isinstance(artifact, ArtifactFolderInfoResponse) assert artifact.dict() == FOLDER_INFO.dict()
def test_get_artifact_property_not_found_error(): responses.add( responses.GET, f"{URL}/api/storage/{ARTIFACT_PATH}?properties=a_property_not_found", json={"errors": [{"status": 404, "message": "No properties could be found."}]}, status=404, ) artifactory = ArtifactoryArtifact(AuthModel(url=URL, auth=AUTH)) with pytest.raises(PropertyNotFoundException): artifactory.properties(ARTIFACT_PATH, properties=["a_property_not_found"])
def test_get_artifact_stats_success(): responses.add( responses.GET, f"{URL}/api/storage/{ARTIFACT_PATH}?stats", json=ARTIFACT_STATS.dict(), status=200, ) artifactory = ArtifactoryArtifact(AuthModel(url=URL, auth=AUTH)) artifact_stats = artifactory.stats(ARTIFACT_PATH) assert artifact_stats.dict() == ARTIFACT_STATS.dict()
def test_get_artifact_all_properties_success(): responses.add( responses.GET, f"{URL}/api/storage/{ARTIFACT_PATH}?properties", json=ARTIFACT_MULTIPLE_PROPERTIES.dict(), status=200, ) artifactory = ArtifactoryArtifact(AuthModel(url=URL, auth=AUTH)) artifact_properties = artifactory.properties(ARTIFACT_PATH) assert artifact_properties.dict() == ARTIFACT_MULTIPLE_PROPERTIES.dict()
def test_download_artifact_success(tmp_path): artifact_name = ARTIFACT_PATH.split("/")[1] responses.add(responses.GET, f"{URL}/{ARTIFACT_PATH}", json=artifact_name, status=200) artifactory = ArtifactoryArtifact(AuthModel(url=URL, auth=AUTH)) artifact = artifactory.download(ARTIFACT_PATH, str(tmp_path.resolve())) assert artifact == f"{tmp_path.resolve()}/{artifact_name}" assert (tmp_path / artifact_name).is_file()
def test_get_artifact_multiple_properties_with_non_existing_properties_success( ): responses.add( responses.GET, f"{URL}/api/storage/{ARTIFACT_PATH}?properties=prop1,prop2,non_existing_prop", json=ARTIFACT_MULTIPLE_PROPERTIES.dict(), status=200, ) artifactory = ArtifactoryArtifact(AuthModel(url=URL, auth=AUTH)) artifact_properties = artifactory.properties( ARTIFACT_PATH, ["prop1", "prop2", "non_existing_prop"]) assert artifact_properties.dict() == ARTIFACT_MULTIPLE_PROPERTIES.dict()
def test_deploy_artifact_success(mocker): responses.add(responses.PUT, f"{URL}/{ARTIFACT_PATH}", status=200) responses.add( responses.GET, f"{URL}/api/storage/{ARTIFACT_PATH}", json=FILE_INFO_RESPONSE, status=200, ) artifactory = ArtifactoryArtifact(AuthModel(url=URL, auth=AUTH)) mocker.spy(artifactory, "info") artifact = artifactory.deploy(LOCAL_FILE_LOCATION, ARTIFACT_PATH) artifactory.info.assert_called_once_with(ARTIFACT_PATH) assert artifact.dict() == FILE_INFO.dict()
def test_deploy_artifact_success(mocker): responses.add(responses.PUT, f"{URL}/{ARTIFACT_PATH}", status=200) responses.add( responses.GET, f"{URL}/api/storage/{ARTIFACT_PATH}?properties[=x[,y]]", json=ARTIFACT_PROPERTIES.dict(), status=200, ) artifactory = ArtifactoryArtifact(AuthModel(url=URL, auth=AUTH)) mocker.spy(artifactory, "properties") artifact = artifactory.deploy(LOCAL_FILE_LOCATION, ARTIFACT_PATH) artifactory.properties.assert_called_once_with(ARTIFACT_PATH) assert artifact.dict() == ARTIFACT_PROPERTIES.dict()
def test_set_property_fail_bad_value(): properties_param_str = urllib.parse.quote_plus( f"{BAD_PROPERTY_NAME}={BAD_PROPERTY_VALUE};" ) responses.add( responses.PUT, f"{URL}/api/storage/{ARTIFACT_PATH}?recursive=1&properties={properties_param_str}", status=400, ) artifactory = ArtifactoryArtifact(AuthModel(url=URL, auth=AUTH)) with pytest.raises(BadPropertiesException): set_property_response = artifactory.set_properties( ARTIFACT_PATH, {BAD_PROPERTY_NAME: [BAD_PROPERTY_VALUE]} ) assert set_property_response is None
def test_download_folder_success(tmp_path): # artifact_name = ARTIFACT_PATH.split("/")[1] responses.add( responses.GET, f"{URL}/api/storage/{ARTIFACT_REPO}", status=200, json=FOLDER_INFO_RESPONSE, ) responses.add( responses.GET, f"{URL}/api/storage/{ARTIFACT_REPO}/child1", status=200, json=CHILD1_FOLDER_INFO_RESPONSE, ) responses.add( responses.GET, f"{URL}/api/storage/{ARTIFACT_REPO}/child2", status=200, json=CHILD2_INFO_RESPONSE, ) responses.add( responses.GET, f"{URL}/api/storage/{ARTIFACT_REPO}/child1/grandchild", status=200, json=GRANDCHILD_INFO_RESPONSE, ) responses.add(responses.GET, f"{URL}/{ARTIFACT_REPO}", json="/", status=200) responses.add( responses.GET, f"{URL}/{ARTIFACT_REPO}/child1/grandchild", json="/child1/grandchild", status=200, ) responses.add(responses.GET, f"{URL}/{ARTIFACT_REPO}/child2", json="/child2", status=200) artifactory = ArtifactoryArtifact(AuthModel(url=URL, auth=AUTH)) artifact = artifactory.download(f"{ARTIFACT_REPO}/", str(tmp_path.resolve())) assert artifact == f"{tmp_path.resolve()}/{ARTIFACT_REPO}" assert (tmp_path / f"{ARTIFACT_REPO}" / "child1" / "grandchild").is_file() assert (tmp_path / f"{ARTIFACT_REPO}" / "child2").is_file()
def test_set_property_fail_artifact_not_found(): properties_param_str = "" for k, v in ARTIFACT_ONE_PROPERTY.properties.items(): values_str = ",".join(v) properties_param_str += urllib.parse.quote_plus(f"{k}={values_str};") responses.add( responses.PUT, f"{URL}/api/storage/{NX_ARTIFACT_PATH}?recursive=1&properties={properties_param_str}", status=404, ) artifactory = ArtifactoryArtifact(AuthModel(url=URL, auth=AUTH)) with pytest.raises(ArtifactNotFoundException): set_property_response = artifactory.set_properties( NX_ARTIFACT_PATH, ARTIFACT_ONE_PROPERTY.properties ) assert set_property_response is None
def test_move_artifact_success(): responses.add( responses.POST, f"{URL}/api/move/{ARTIFACT_PATH}?to={ARTIFACT_NEW_PATH}&dry=0", status=200, ) responses.add( responses.GET, f"{URL}/api/storage/{ARTIFACT_NEW_PATH}", status=200, json=FILE_INFO_RESPONSE, ) artifactory = ArtifactoryArtifact(AuthModel(url=URL, auth=AUTH)) artifact_moved = artifactory.move(ARTIFACT_PATH, ARTIFACT_NEW_PATH) assert artifact_moved.dict() == FILE_INFO.dict()
def test_copy_artifact_success(): responses.add( responses.POST, f"{URL}/api/copy/{ARTIFACT_PATH}?to={ARTIFACT_NEW_PATH}&dry=0", status=200, ) responses.add( responses.GET, f"{URL}/api/storage/{ARTIFACT_NEW_PATH}?properties[=x[,y]]", status=200, json=NEW_ARTIFACT_PROPERTIES.dict(), ) artifactory = ArtifactoryArtifact(AuthModel(url=URL, auth=AUTH)) artifact_copied = artifactory.copy(ARTIFACT_PATH, ARTIFACT_NEW_PATH) assert artifact_copied.dict() == NEW_ARTIFACT_PROPERTIES.dict()
def test_update_property_fail_artifact_not_found(): responses.add( responses.PATCH, f"{URL}/api/metadata/{NX_ARTIFACT_PATH}?recursive=1", match=[ responses.matchers.json_params_matcher( {"props": ARTIFACT_ONE_PROPERTY.properties} ) ], status=400, ) artifactory = ArtifactoryArtifact(AuthModel(url=URL, auth=AUTH)) with pytest.raises(ArtifactoryException): update_properties_response = artifactory.update_properties( NX_ARTIFACT_PATH, ARTIFACT_ONE_PROPERTY.properties ) assert update_properties_response is None
def test_update_property_fail_bad_value(): responses.add( responses.PATCH, f"{URL}/api/metadata/{ARTIFACT_PATH}?recursive=1", match=[ responses.matchers.json_params_matcher( {"props": {BAD_PROPERTY_NAME: [BAD_PROPERTY_VALUE]}} ) ], status=400, ) artifactory = ArtifactoryArtifact(AuthModel(url=URL, auth=AUTH)) with pytest.raises(ArtifactoryException): update_properties_response = artifactory.update_properties( ARTIFACT_PATH, {BAD_PROPERTY_NAME: [BAD_PROPERTY_VALUE]} ) assert update_properties_response is None
def test_set_property_success(): properties_param_str = "" for k, v in ARTIFACT_MULTIPLE_PROPERTIES.properties.items(): values_str = ",".join(v) properties_param_str += urllib.parse.quote_plus(f"{k}={values_str};") responses.add( responses.PUT, f"{URL}/api/storage/{ARTIFACT_PATH}?recursive=1&properties={properties_param_str}", status=200, ) responses.add( responses.GET, f"{URL}/api/storage/{ARTIFACT_PATH}?properties=", json=ARTIFACT_MULTIPLE_PROPERTIES.dict(), status=200, ) artifactory = ArtifactoryArtifact(AuthModel(url=URL, auth=AUTH)) set_properties_response = artifactory.set_properties( ARTIFACT_PATH, ARTIFACT_MULTIPLE_PROPERTIES.properties ) assert set_properties_response == ARTIFACT_MULTIPLE_PROPERTIES
def test_update_property_success(): responses.add( responses.PATCH, f"{URL}/api/metadata/{ARTIFACT_PATH}?recursive=1", match=[ responses.matchers.json_params_matcher( {"props": ARTIFACT_MULTIPLE_PROPERTIES.properties} ) ], status=200, ) responses.add( responses.GET, f"{URL}/api/storage/{ARTIFACT_PATH}?properties=", json=ARTIFACT_MULTIPLE_PROPERTIES.dict(), status=200, ) artifactory = ArtifactoryArtifact(AuthModel(url=URL, auth=AUTH)) update_properties_response = artifactory.update_properties( ARTIFACT_PATH, ARTIFACT_MULTIPLE_PROPERTIES.properties ) assert update_properties_response == ARTIFACT_MULTIPLE_PROPERTIES
def test_delete_artifact_success(): responses.add(responses.DELETE, f"{URL}/{ARTIFACT_PATH}", status=200) artifactory = ArtifactoryArtifact(AuthModel(url=URL, auth=AUTH)) artifactory.delete(ARTIFACT_PATH)