def test_get_batch__not_empty__slow_response_retry(credentials, mocker): """Test project batches slow response retry.""" runner = CliRunner() with runner.isolated_filesystem(): batch_id = str(uuid4()) mocked_get_batch = mocker.patch.object( APIClient, "get_batch", side_effect=APIClientTimeout( "Could not connect to the api server"), ) mocked_download_file = mocker.patch( "gencove.command.projects.get_batch.main.download.utils." "download_file") res = runner.invoke( get_batch, [ batch_id, *credentials, "--output-filename", "test.zip", ], ) assert res.exit_code == 1 assert mocked_get_batch.call_count == 2 mocked_download_file.assert_not_called()
def test_get_metadata__slow_response_retry(mocker): """Test sample get metadata slow response retry.""" sample_id = str(uuid4()) runner = CliRunner() mocked_login = mocker.patch.object(APIClient, "login", return_value=None) metadata = {"somekey": "somevalue"} mocked_get_metadata = mocker.patch.object( APIClient, "get_metadata", side_effect=APIClientTimeout("Could not connect to the api server"), ) res = runner.invoke( get_metadata, [ sample_id, "--email", "*****@*****.**", "--password", "123", "--output-filename", "-", ], ) assert res.exit_code == 1 mocked_login.assert_called_once() assert mocked_get_metadata.call_count == 2 output_line = io.BytesIO() sys.stdout = output_line echo(json.dumps(metadata, indent=4)) assert output_line.getvalue() not in res.output.encode()
def test_status_merged_vcf__slow_response_retry(mocker): """Test status merged VCF slow response retry.""" project_id = str(uuid4()) runner = CliRunner() mocked_login = mocker.patch.object(APIClient, "login", return_value=None) mocked_retrieve_merged_vcf = mocker.patch.object( APIClient, "retrieve_merged_vcf", side_effect=APIClientTimeout("Could not connect to the api server"), ) res = runner.invoke( status_merged_vcf, [ project_id, "--email", "*****@*****.**", "--password", "123", ], ) assert res.exit_code == 1 mocked_login.assert_called_once() assert mocked_retrieve_merged_vcf.call_count == 5
def test_get_merged_vcf__slow_response_retry(mocker): """Test project download merged VCF slow response retry.""" project_id = str(uuid4()) runner = CliRunner() mocked_login = mocker.patch.object(APIClient, "login", return_value=None) mocked_get_project = mocker.patch.object( APIClient, "get_project", side_effect=APIClientTimeout("Could not connect to the api server"), ) with runner.isolated_filesystem(): mocked_download_file = mocker.patch( "gencove.command.projects.get_merged_vcf.main.download.utils." "download_file" ) res = runner.invoke( get_merged_vcf, [ project_id, "--email", "*****@*****.**", "--password", "123", ], ) assert res.exit_code == 1 mocked_login.assert_called_once() assert mocked_get_project.call_count == 5 mocked_download_file.assert_not_called()
def test_list_projects_slow_response_dump_log(mocker, credentials, dump_filename): """Test projects slow response dumps a log filet.""" del os.environ["GENCOVE_SAVE_DUMP_LOG"] runner = CliRunner() mocker.patch.object( APIClient, "list_projects", side_effect=APIClientTimeout("Could not connect to the api server"), ) python_version = sys.version_info logs = [ f"Python version: {python_version.major}.{python_version.minor}.{python_version.micro}", # noqa: E501 # pylint: disable=line-too-long f"CLI version: {version()}", f"OS details: {platform()}", f"boto3 version: {boto3.__version__}", "Retrieving projects", "Get projects page", "Could not connect to the api server", ] with runner.isolated_filesystem(): res = runner.invoke(list_projects, credentials) assert res.exit_code == 1 assert ( f"Please attach the debug log file located in {dump_filename} to a bug report." # noqa: E501 # pylint: disable=line-too-long in res.output) with open(dump_filename, encoding="utf8") as log_file: log_content = log_file.read() for log in logs: assert log in log_content
def test_upload_and_run_immediately_slow_response_retry( credentials, mocker, project_id, recording, vcr ): """Upload and assign right away and retry on slow response.""" runner = CliRunner() with runner.isolated_filesystem(): os.mkdir("cli_test_data") with open("cli_test_data/test.fastq.gz", "w") as fastq_file: fastq_file.write("AAABBB") mocked_get_credentials = mocker.patch( "gencove.command.upload.main.get_s3_client_refreshable", side_effect=get_s3_client_refreshable, ) mocked_upload_file = mocker.patch( "gencove.command.upload.main.upload_file", side_effect=upload_file ) if not recording: # Mock get_upload credentials only if using the cassettes, since # we mock the return value. upload_details_response = get_vcr_response( "/api/v2/uploads-post-data/", vcr ) mocked_get_upload_details = mocker.patch.object( APIClient, "get_upload_details", return_value=UploadsPostData(**upload_details_response), ) mocked_get_sample_sheet = mocker.patch.object( APIClient, "get_sample_sheet", side_effect=APIClientTimeout( "Could not connect to the api server" ), ) res = runner.invoke( upload, [ "cli_test_data", *credentials, "--run-project-id", project_id, "--no-progress", ], ) assert res.exit_code == 0 mocked_get_credentials.assert_called_once() mocked_upload_file.assert_called_once() if not recording: mocked_get_upload_details.assert_called_once() assert mocked_get_sample_sheet.call_count == 5 assert "there was an error automatically running them" in res.output
def test_list_uploads_slow_response_retry(mocker, credentials): """Test list uploads slow response retry.""" runner = CliRunner() mocked_get_sample_sheet = mocker.patch.object( APIClient, "get_sample_sheet", side_effect=APIClientTimeout("Could not connect to the api server"), ) res = runner.invoke(list_uploads, credentials) assert res.exit_code == 1 assert mocked_get_sample_sheet.call_count == 5 assert ( res.output == "ERROR: Could not connect to the api server\nAborted!\n")
def test_basespace_list__slow_response_retry_list(mocker): """Test BaseSpace projects slow response retry on the list.""" runner = CliRunner() mocked_login = mocker.patch.object(APIClient, "login", return_value=None) mocked_list_basespace_projects = mocker.patch.object( APIClient, "list_basespace_projects", side_effect=APIClientTimeout("Could not connect to the api server"), ) res = runner.invoke(basespace_list, ["--email", "*****@*****.**", "--password", "123"]) assert res.exit_code == 1 mocked_login.assert_called_once() assert mocked_list_basespace_projects.call_count == 2
def test_list_projects_slow_response_retry_list(mocker, credentials): """Test projects slow response retry on the list.""" runner = CliRunner() mocked_get_projects = mocker.patch.object( APIClient, "list_projects", side_effect=APIClientTimeout("Could not connect to the api server"), ) mocked_get_pipeline_capabilities = mocker.patch.object( APIClient, "get_pipeline_capabilities") res = runner.invoke(list_projects, credentials) assert res.exit_code == 1 assert mocked_get_projects.call_count == 2 mocked_get_pipeline_capabilities.assert_not_called()
def test_list_project_samples_slow_response_retry(mocker, credentials): """Test project samples slow response retry.""" runner = CliRunner() mocked_get_project_samples = mocker.patch.object( APIClient, "get_project_samples", side_effect=APIClientTimeout("Could not connect to the api server"), ) res = runner.invoke( list_project_samples, [str(uuid4()), *credentials], ) assert res.exit_code == 1 assert mocked_get_project_samples.call_count == 2
def test_list_project_batch_types__not_empty_slow_response_retry( mocker, credentials): """Test project batch types being outputed to the shell.""" runner = CliRunner() mocked_get_project_batch_types = mocker.patch.object( APIClient, "get_project_batch_types", side_effect=APIClientTimeout("Could not connect to the api server"), ) res = runner.invoke( list_project_batch_types, [str(uuid4()), *credentials], ) assert res.exit_code == 1 assert mocked_get_project_batch_types.call_count == 2
def test_autoimport_list_uploads_slow_response_retry(mocker, credentials): """Test list jobs slow response retry.""" runner = CliRunner() mocked_list_s3_autoimport_jobs = mocker.patch.object( APIClient, "list_s3_autoimport_jobs", side_effect=APIClientTimeout("Could not connect to the api server"), ) res = runner.invoke(autoimport_list, credentials) assert res.exit_code == 1 assert mocked_list_s3_autoimport_jobs.call_count == 2 assert ("\n".join([ "ERROR: There was an error listing S3 autoimport jobs.", "ERROR: Could not connect to the api server", "Aborted!\n", ]) == res.output)
def test_list_projects_slow_response_retry_pipeline(mocker, credentials, recording, vcr): """Test projects slow repsonse retry on the pipeline capabilities.""" runner = CliRunner() if not recording: # Mock list_projects only if using the cassettes, since we mock the # return value. list_projects_response = get_vcr_response("/api/v2/projects/", vcr) mocked_get_projects = mocker.patch.object( APIClient, "list_projects", return_value=Projects(**list_projects_response), ) mocked_get_pipeline_capabilities = mocker.patch.object( APIClient, "get_pipeline_capabilities", side_effect=APIClientTimeout("Could not connect to the api server"), ) res = runner.invoke(list_projects, credentials) assert res.exit_code == 1 if not recording: mocked_get_projects.assert_called_once() assert mocked_get_pipeline_capabilities.call_count == 3