def test_fetch_app_source_request_timed_out(mock_git): url = 'https://github.com/release-engineering/retrodep.git' ref = 'c50b93a32df1c9d700e3e80996845bc2e13be848' mock_git.return_value.fetch_source.side_effect = Timeout( 'The request timed out') with pytest.raises( CachitoError, match='The connection timed out while downloading the source'): tasks.fetch_app_source(url, ref)
def test_fetch_app_source_request_timed_out(mock_git, mock_set_request_state, gitsubmodule): url = "https://github.com/release-engineering/retrodep.git" ref = "c50b93a32df1c9d700e3e80996845bc2e13be848" mock_git.return_value.fetch_source.side_effect = Timeout( "The request timed out") with pytest.raises( CachitoError, match="The connection timed out while downloading the source"): tasks.fetch_app_source(url, ref, 1, gitsubmodule)
def test_fetch_app_source(mock_git, mock_set_request_state, request_id_to_update): url = 'https://github.com/release-engineering/retrodep.git' ref = 'c50b93a32df1c9d700e3e80996845bc2e13be848' tasks.fetch_app_source(url, ref, request_id_to_update=request_id_to_update) mock_git.assert_called_once_with(url, ref) mock_git.return_value.fetch_source.assert_called_once_with() if request_id_to_update: mock_set_request_state.assert_called_once_with( 1, 'in_progress', 'Fetching the application source') else: mock_set_request_state.assert_not_called()
def test_fetch_app_source(mock_set_request_state, fake_repo, gitsubmodule): request_id = 1 repo_dir, repo_name = fake_repo tasks.fetch_app_source(f"file://{repo_dir}", "master", request_id, gitsubmodule) # Verify the archive file is created from fetched app source. sources_dir = SourcesDir(repo_name, "master") assert sources_dir.archive_path.name == "master.tar.gz" # Verify the archive file is extracted into request bundle directory. bundle_dir = RequestBundleDir(request_id) assert bundle_dir.joinpath("app", "readme.rst").exists() assert bundle_dir.joinpath("app", "main.py").exists() # Clean up bundle dir after unpacking archive shutil.rmtree(bundle_dir)
def test_fetch_app_source( mock_git, mock_set_request_state, mock_extract_app_src, mock_exists, mock_makedirs, dir_exists, ): mock_exists.return_value = dir_exists url = 'https://github.com/release-engineering/retrodep.git' ref = 'c50b93a32df1c9d700e3e80996845bc2e13be848' tasks.fetch_app_source(url, ref, 1) mock_git.assert_called_once_with(url, ref) mock_git.return_value.fetch_source.assert_called_once_with() mock_set_request_state.assert_called_once_with( 1, 'in_progress', 'Fetching the application source') bundle_dir = '/tmp/cachito-archives/bundles/temp/1' mock_exists.assert_called_once_with(bundle_dir) if dir_exists: mock_makedirs.assert_not_called() else: mock_makedirs.assert_called_once_with(bundle_dir, exist_ok=True) mock_extract_app_src.assert_called_once_with(mock_git().archive_path, bundle_dir)