def test_process_non_registry_dependency_http(mock_unrd, mock_gncifn, exists): checksum = ( "325f07861e0ab888d90606b1074fde956fd3954dcc4c6e418dbff9d8aa8342b5507481408832bfaac8e48f344" "dc650c8df0f8182c0271ed9fa233aa32c329839") nexus_component_info = { "assets": [{ "checksum": { "sha512": checksum }, "downloadUrl": ("https://nexus.domain.local/repository/cachito-js-hosted/rxjs/-/" "rxjs-6.5.5-external-sha512-325f07861e0ab888d90606b1074fde956fd3954dcc4c6e418d" "bff9d8aa8342b5507481408832bfaac8e48f344.tgz"), }], "version": ("6.5.5-external-sha512-325f07861e0ab888d90606b1074fde956fd3954dcc4c6e418dbff9d8aa8342" "b5507481408832bfaac8e48f344"), } if exists: mock_gncifn.return_value = nexus_component_info else: mock_gncifn.side_effect = [None, nexus_component_info] dep_name = "rxjs" dep_info = { "version": "https://github.com/ReactiveX/rxjs/archive/6.5.5.tar.gz", "requires": { "tslib": "^1.9.0" }, "integrity": ("sha512-Ml8Hhh4KuIjZBgaxB0/elW/TlU3MTG5Bjb/52KqDQrVQdIFAiDK/qsjkjzRNxlDI3w+BgsAnHtn6I" "zqjLDKYOQ=="), } dep = general_js.JSDependency(name=dep_name, source=dep_info["version"], integrity=dep_info["integrity"]) new_dep = general_js.process_non_registry_dependency(dep) assert new_dep == general_js.JSDependency( name=dep.name, source= ("https://nexus.domain.local/repository/cachito-js-hosted/rxjs/-/rxjs-6.5.5-" "external-sha512-325f07861e0ab888d90606b1074fde956fd3954dcc4c6e418dbff9d8aa8342b55074" "81408832bfaac8e48f344.tgz"), version= ("6.5.5-external-sha512-325f07861e0ab888d90606b1074fde956fd3954dcc4c6e418dbff9d8" "aa8342b5507481408832bfaac8e48f344"), integrity= ("sha512-Ml8Hhh4KuIjZBgaxB0/elW/TlU3MTG5Bjb/52KqDQrVQdIFAiDK/qsjkjzRNxlDI3w+BgsAnHtn6I" "zqjLDKYOQ=="), ) suffix = ( "-external-sha512-325f07861e0ab888d90606b1074fde956fd3954dcc4c6e418dbff9d8aa8342b5" "507481408832bfaac8e48f344dc650c8df0f8182c0271ed9fa233aa32c329839") suffix_search = f"*{suffix}" if exists: mock_gncifn.assert_called_once_with("rxjs", suffix_search) # Verify no upload occurs when the component already exists in Nexus mock_unrd.assert_not_called() else: assert mock_gncifn.call_count == 2 mock_gncifn.assert_has_calls([ mock.call("rxjs", suffix_search), mock.call("rxjs", suffix_search, max_attempts=5) ]) mock_unrd.assert_called_once_with( "https://github.com/ReactiveX/rxjs/archive/6.5.5.tar.gz", suffix, False, general.ChecksumInfo( "sha512", "325f07861e0ab888d90606b1074fde956fd3954dcc4c6e418dbff9d8aa8342b5507481408832bf" "aac8e48f344dc650c8df0f8182c0271ed9fa233aa32c329839", ), )
expected = "Failed to prepare Nexus for Cachito to stage JavaScript content" with pytest.raises(CachitoError, match=expected): _, password = general_js.prepare_nexus_for_js_request(1) @mock.patch("cachito.workers.pkg_managers.general_js.verify_checksum") @mock.patch( "cachito.workers.pkg_managers.general_js.tempfile.TemporaryDirectory") @mock.patch("cachito.workers.pkg_managers.general_js.run_cmd") @mock.patch("cachito.workers.pkg_managers.general_js.find_package_json") @mock.patch( "cachito.workers.pkg_managers.general_js.nexus.upload_asset_only_component" ) @pytest.mark.parametrize("checksum_info", [None, general.ChecksumInfo("sha512", "12345")]) def test_upload_non_registry_dependency(mock_ua, mock_fpj, mock_run_cmd, mock_td, mock_vc, checksum_info, tmpdir): tarfile_path = os.path.join(tmpdir, "star-wars-5.0.0.tgz") with tarfile.open(tarfile_path, "x:gz") as archive: tar_info = tarfile.TarInfo("package/salutation.html") content = b"<h1>Bonjour monsieur Solo!</h1>" tar_info.size = len(content) archive.addfile(tar_info, io.BytesIO(content)) tar_info = tarfile.TarInfo("package/package.json") content = b'{"version": "5.0.0"}' tar_info.size = len(content) archive.addfile(tar_info, io.BytesIO(content))