From 0c14dc91e5b3a14b6d7381a02a155b2f8dc90e68 Mon Sep 17 00:00:00 2001 From: Joseph Sawaya Date: Mon, 24 Feb 2025 10:18:54 -0500 Subject: [PATCH] deps: update shared --- graphql_api/tests/test_test_analytics.py | 2 +- requirements.in | 2 +- requirements.txt | 2 +- staticanalysis/tests/test_views.py | 2 +- upload/tests/test_serializers.py | 12 +++++++---- upload/tests/test_upload_download.py | 4 ++-- upload/tests/views/test_bundle_analysis.py | 24 +++++++++++----------- upload/tests/views/test_test_results.py | 20 +++++++++--------- upload/tests/views/test_upload_coverage.py | 4 ++-- upload/tests/views/test_uploads.py | 14 ++++++------- upload/views/legacy.py | 3 ++- utils/test_results.py | 4 ++-- 12 files changed, 49 insertions(+), 44 deletions(-) diff --git a/graphql_api/tests/test_test_analytics.py b/graphql_api/tests/test_test_analytics.py index 7a714908ec..777d8f41d0 100644 --- a/graphql_api/tests/test_test_analytics.py +++ b/graphql_api/tests/test_test_analytics.py @@ -51,7 +51,7 @@ def __call__(self, updated_at: datetime.datetime) -> dict[str, Any]: @pytest.fixture def mock_storage(mocker): - m = mocker.patch("utils.test_results.StorageService") + m = mocker.patch("utils.test_results.get_appropriate_storage_service") storage_server = MemoryStorageService({}) m.return_value = storage_server yield storage_server diff --git a/requirements.in b/requirements.in index 37317aa8d9..1c8b7ca3e9 100644 --- a/requirements.in +++ b/requirements.in @@ -25,7 +25,7 @@ freezegun google-cloud-pubsub gunicorn>=22.0.0 https://github.com/codecov/opentelem-python/archive/refs/tags/v0.0.4a1.tar.gz#egg=codecovopentelem -https://github.com/codecov/shared/archive/47fa7fd405cd4a37ab6df9f200d6b600795f2786.tar.gz#egg=shared +https://github.com/codecov/shared/archive/015d76ed1b6d8c85b5abd5f0825136ae7d6e0f4c.tar.gz#egg=shared https://github.com/photocrowd/django-cursor-pagination/archive/f560902696b0c8509e4d95c10ba0d62700181d84.tar.gz idna>=3.7 minio diff --git a/requirements.txt b/requirements.txt index 0768d5ea5d..3086edca95 100644 --- a/requirements.txt +++ b/requirements.txt @@ -419,7 +419,7 @@ sentry-sdk[celery]==2.13.0 # shared setproctitle==1.1.10 # via -r requirements.in -shared @ https://github.com/codecov/shared/archive/47fa7fd405cd4a37ab6df9f200d6b600795f2786.tar.gz +shared @ https://github.com/codecov/shared/archive/015d76ed1b6d8c85b5abd5f0825136ae7d6e0f4c.tar.gz # via -r requirements.in simplejson==3.17.2 # via -r requirements.in diff --git a/staticanalysis/tests/test_views.py b/staticanalysis/tests/test_views.py index a6995c7313..7e04738df1 100644 --- a/staticanalysis/tests/test_views.py +++ b/staticanalysis/tests/test_views.py @@ -16,7 +16,7 @@ def test_simple_static_analysis_call_no_uploads_yet(db, mocker): mocked_task_service = mocker.patch.object(TaskService, "schedule_task") mocked_presigned_put = mocker.patch( - "shared.api_archive.archive.StorageService.create_presigned_put", + "shared.storage.MinioStorageService.create_presigned_put", return_value="banana.txt", ) commit = CommitFactory.create(repository__active=True) diff --git a/upload/tests/test_serializers.py b/upload/tests/test_serializers.py index d8104cca68..8d58606153 100644 --- a/upload/tests/test_serializers.py +++ b/upload/tests/test_serializers.py @@ -46,7 +46,7 @@ def get_fake_upload_with_flags(): def test_serialize_upload(transactional_db, mocker): mocker.patch( - "shared.api_archive.archive.StorageService.create_presigned_put", + "shared.storage.MinioStorageService.create_presigned_put", return_value="presigned put", ) fake_upload = get_fake_upload() @@ -63,7 +63,7 @@ def test_serialize_upload(transactional_db, mocker): def test_upload_serializer_contains_expected_fields_no_flags(transactional_db, mocker): mocker.patch( - "shared.api_archive.archive.StorageService.create_presigned_put", + "shared.storage.MinioStorageService.create_presigned_put", return_value="presigned put", ) upload = get_fake_upload() @@ -90,7 +90,7 @@ def test_upload_serializer_contains_expected_fields_with_flags( transactional_db, mocker ): mocker.patch( - "shared.api_archive.archive.StorageService.create_presigned_put", + "shared.storage.MinioStorageService.create_presigned_put", return_value="presigned put", ) upload = get_fake_upload_with_flags() @@ -114,6 +114,10 @@ def test_upload_serializer_contains_expected_fields_with_flags( def test_upload_serializer_null_build_url_empty_flags(transactional_db, mocker): + mocker.patch( + "shared.storage.MinioStorageService.create_presigned_put", + return_value="presigned put", + ) data = { "ci_url": None, "flags": [], @@ -128,7 +132,7 @@ def test_upload_serializer_null_build_url_empty_flags(transactional_db, mocker): def test__create_existing_flags_map(transactional_db, mocker): mocker.patch( - "shared.api_archive.archive.StorageService.create_presigned_put", + "shared.storage.MinioStorageService.create_presigned_put", return_value="presigned put", ) upload = get_fake_upload_with_flags() diff --git a/upload/tests/test_upload_download.py b/upload/tests/test_upload_download.py index fda2cd3539..b255f84608 100644 --- a/upload/tests/test_upload_download.py +++ b/upload/tests/test_upload_download.py @@ -69,7 +69,7 @@ def test_invalid_repo(self): assert response.status_code == 404 @patch("shared.api_archive.archive.ArchiveService.get_archive_hash") - @patch("shared.api_archive.archive.StorageService.create_presigned_get") + @patch("shared.storage.MinioStorageService.create_presigned_get") def test_invalid_archive_path(self, create_presigned_get, get_archive_hash): create_presigned_get.side_effect = [ minio.error.S3Error( @@ -93,7 +93,7 @@ def test_invalid_archive_path(self, create_presigned_get, get_archive_hash): assert response.status_code == 404 @patch("shared.api_archive.archive.ArchiveService.get_archive_hash") - @patch("shared.api_archive.archive.StorageService.create_presigned_get") + @patch("shared.storage.MinioStorageService.create_presigned_get") def test_valid_repo_archive_path(self, create_presigned_get, get_archive_hash): create_presigned_get.return_value = "presigned-url" get_archive_hash.return_value = "hasssshhh" diff --git a/upload/tests/views/test_bundle_analysis.py b/upload/tests/views/test_bundle_analysis.py index ff62d28c9c..b42cf7703d 100644 --- a/upload/tests/views/test_bundle_analysis.py +++ b/upload/tests/views/test_bundle_analysis.py @@ -24,7 +24,7 @@ def test_upload_bundle_analysis_success(db, client, mocker, mock_redis): "upload.views.bundle_analysis.BUNDLE_ANALYSIS_UPLOAD_VIEWS_COUNTER.labels" ) create_presigned_put = mocker.patch( - "shared.api_archive.archive.StorageService.create_presigned_put", + "shared.storage.MinioStorageService.create_presigned_put", return_value="test-presigned-put", ) @@ -112,7 +112,7 @@ def test_upload_bundle_analysis_success_shelter(db, client, mocker, mock_redis): "upload.views.bundle_analysis.BUNDLE_ANALYSIS_UPLOAD_VIEWS_COUNTER.labels" ) create_presigned_put = mocker.patch( - "shared.api_archive.archive.StorageService.create_presigned_put", + "shared.storage.MinioStorageService.create_presigned_put", return_value="test-presigned-put", ) @@ -198,7 +198,7 @@ def test_upload_bundle_analysis_success_shelter(db, client, mocker, mock_redis): def test_upload_bundle_analysis_org_token(db, client, mocker, mock_redis): mocker.patch.object(TaskService, "upload") mocker.patch( - "shared.api_archive.archive.StorageService.create_presigned_put", + "shared.storage.MinioStorageService.create_presigned_put", return_value="test-presigned-put", ) mock_metrics = mocker.patch( @@ -236,7 +236,7 @@ def test_upload_bundle_analysis_org_token(db, client, mocker, mock_redis): def test_upload_bundle_analysis_existing_commit(db, client, mocker, mock_redis): upload = mocker.patch.object(TaskService, "upload") mocker.patch( - "shared.api_archive.archive.StorageService.create_presigned_put", + "shared.storage.MinioStorageService.create_presigned_put", return_value="test-presigned-put", ) mock_metrics = mocker.patch( @@ -282,7 +282,7 @@ def test_upload_bundle_analysis_existing_commit(db, client, mocker, mock_redis): def test_upload_bundle_analysis_missing_args(db, client, mocker, mock_redis): upload = mocker.patch.object(TaskService, "upload") mocker.patch( - "shared.api_archive.archive.StorageService.create_presigned_put", + "shared.storage.MinioStorageService.create_presigned_put", return_value="test-presigned-put", ) mock_metrics = mocker.patch( @@ -331,7 +331,7 @@ def test_upload_bundle_analysis_missing_args(db, client, mocker, mock_redis): def test_upload_bundle_analysis_invalid_token(db, client, mocker, mock_redis): upload = mocker.patch.object(TaskService, "upload") mocker.patch( - "shared.api_archive.archive.StorageService.create_presigned_put", + "shared.storage.MinioStorageService.create_presigned_put", return_value="test-presigned-put", ) @@ -361,7 +361,7 @@ def test_upload_bundle_analysis_github_oidc_auth( ): mocker.patch.object(TaskService, "upload") mocker.patch( - "shared.api_archive.archive.StorageService.create_presigned_put", + "shared.storage.MinioStorageService.create_presigned_put", return_value="test-presigned-put", ) mock_metrics = mocker.patch( @@ -405,7 +405,7 @@ def test_upload_bundle_analysis_measurement_datasets_created( ): mocker.patch.object(TaskService, "upload") mocker.patch( - "shared.api_archive.archive.StorageService.create_presigned_put", + "shared.storage.MinioStorageService.create_presigned_put", return_value="test-presigned-put", ) mock_metrics = mocker.patch( @@ -466,7 +466,7 @@ def test_upload_bundle_analysis_measurement_timeseries_disabled( ): mocker.patch.object(TaskService, "upload") mocker.patch( - "shared.api_archive.archive.StorageService.create_presigned_put", + "shared.storage.MinioStorageService.create_presigned_put", return_value="test-presigned-put", ) mock_metrics = mocker.patch( @@ -525,7 +525,7 @@ def test_upload_bundle_analysis_no_repo(db, client, mocker, mock_redis): upload = mocker.patch.object(TaskService, "upload") mocker.patch.object(TaskService, "upload") mocker.patch( - "shared.api_archive.archive.StorageService.create_presigned_put", + "shared.storage.MinioStorageService.create_presigned_put", return_value="test-presigned-put", ) mock_metrics = mocker.patch( @@ -570,7 +570,7 @@ def test_upload_bundle_analysis_tokenless_success(db, client, mocker, mock_redis ) create_presigned_put = mocker.patch( - "shared.api_archive.archive.StorageService.create_presigned_put", + "shared.storage.MinioStorageService.create_presigned_put", return_value="test-presigned-put", ) @@ -621,7 +621,7 @@ def test_upload_bundle_analysis_true_tokenless_success(db, client, mocker, mock_ upload = mocker.patch.object(TaskService, "upload") create_presigned_put = mocker.patch( - "shared.api_archive.archive.StorageService.create_presigned_put", + "shared.storage.MinioStorageService.create_presigned_put", return_value="test-presigned-put", ) diff --git a/upload/tests/views/test_test_results.py b/upload/tests/views/test_test_results.py index d9323404c0..031f968818 100644 --- a/upload/tests/views/test_test_results.py +++ b/upload/tests/views/test_test_results.py @@ -22,7 +22,7 @@ def test_upload_test_results(db, client, mocker, mock_redis): upload = mocker.patch.object(TaskService, "upload") mock_prometheus_metrics = mocker.patch("upload.metrics.API_UPLOAD_COUNTER.labels") create_presigned_put = mocker.patch( - "shared.api_archive.archive.StorageService.create_presigned_put", + "shared.storage.MinioStorageService.create_presigned_put", return_value="test-presigned-put", ) @@ -119,7 +119,7 @@ def test_upload_test_results(db, client, mocker, mock_redis): def test_test_results_org_token(db, client, mocker, mock_redis): mocker.patch.object(TaskService, "upload") mocker.patch( - "shared.api_archive.archive.StorageService.create_presigned_put", + "shared.storage.MinioStorageService.create_presigned_put", return_value="test-presigned-put", ) @@ -149,7 +149,7 @@ def test_test_results_github_oidc_token( ): mocker.patch.object(TaskService, "upload") mocker.patch( - "shared.api_archive.archive.StorageService.create_presigned_put", + "shared.storage.MinioStorageService.create_presigned_put", return_value="test-presigned-put", ) @@ -180,7 +180,7 @@ def test_test_results_github_oidc_token( def test_test_results_upload_token_not_required(db, client, mocker, mock_redis): mocker.patch.object(TaskService, "upload") mocker.patch( - "shared.api_archive.archive.StorageService.create_presigned_put", + "shared.storage.MinioStorageService.create_presigned_put", return_value="test-presigned-put", ) @@ -230,7 +230,7 @@ def test_upload_test_results_no_repo(db, client, mocker, mock_redis): upload = mocker.patch.object(TaskService, "upload") mocker.patch.object(TaskService, "upload") mocker.patch( - "shared.api_archive.archive.StorageService.create_presigned_put", + "shared.storage.MinioStorageService.create_presigned_put", return_value="test-presigned-put", ) @@ -256,7 +256,7 @@ def test_upload_test_results_no_repo(db, client, mocker, mock_redis): def test_upload_test_results_missing_args(db, client, mocker, mock_redis): upload = mocker.patch.object(TaskService, "upload") mocker.patch( - "shared.api_archive.archive.StorageService.create_presigned_put", + "shared.storage.MinioStorageService.create_presigned_put", return_value="test-presigned-put", ) @@ -292,7 +292,7 @@ def test_upload_test_results_missing_args(db, client, mocker, mock_redis): def test_upload_test_results_missing_branch_no_commit(db, client, mocker, mock_redis): upload = mocker.patch.object(TaskService, "upload") mocker.patch( - "shared.api_archive.archive.StorageService.create_presigned_put", + "shared.storage.MinioStorageService.create_presigned_put", return_value="test-presigned-put", ) @@ -321,7 +321,7 @@ def test_upload_test_results_missing_branch_no_commit(db, client, mocker, mock_r def test_upload_test_results_branch_none_no_commit(db, client, mocker, mock_redis): upload = mocker.patch.object(TaskService, "upload") mocker.patch( - "shared.api_archive.archive.StorageService.create_presigned_put", + "shared.storage.MinioStorageService.create_presigned_put", return_value="test-presigned-put", ) @@ -353,7 +353,7 @@ def test_update_repo_fields_when_upload_is_triggered( ) -> None: mocker.patch.object(TaskService, "upload") mocker.patch( - "shared.api_archive.archive.StorageService.create_presigned_put", + "shared.storage.MinioStorageService.create_presigned_put", return_value="test-presigned-put", ) @@ -382,7 +382,7 @@ def test_update_repo_fields_when_upload_is_triggered( def test_upload_test_results_file_not_found(db, client, mocker, mock_redis): upload = mocker.patch.object(TaskService, "upload") create_presigned_put = mocker.patch( - "shared.api_archive.archive.StorageService.create_presigned_put", + "shared.storage.MinioStorageService.create_presigned_put", return_value="test-presigned-put", ) diff --git a/upload/tests/views/test_upload_coverage.py b/upload/tests/views/test_upload_coverage.py index b597232bae..2a750c94e2 100644 --- a/upload/tests/views/test_upload_coverage.py +++ b/upload/tests/views/test_upload_coverage.py @@ -98,7 +98,7 @@ def test_upload_coverage_post(db, mocker): CanDoCoverageUploadsPermission, "has_permission", return_value=True ) presigned_put_mock = mocker.patch( - "shared.api_archive.archive.StorageService.create_presigned_put", + "shared.storage.MinioStorageService.create_presigned_put", return_value="presigned put", ) upload_task_mock = mocker.patch( @@ -197,7 +197,7 @@ def test_upload_coverage_post_shelter(db, mocker): CanDoCoverageUploadsPermission, "has_permission", return_value=True ) presigned_put_mock = mocker.patch( - "shared.api_archive.archive.StorageService.create_presigned_put", + "shared.storage.MinioStorageService.create_presigned_put", return_value="presigned put", ) upload_task_mock = mocker.patch( diff --git a/upload/tests/views/test_uploads.py b/upload/tests/views/test_uploads.py index bd9a452b80..f832e8e996 100644 --- a/upload/tests/views/test_uploads.py +++ b/upload/tests/views/test_uploads.py @@ -207,7 +207,7 @@ def test_uploads_post(db, mocker, mock_redis): CanDoCoverageUploadsPermission, "has_permission", return_value=True ) presigned_put_mock = mocker.patch( - "shared.api_archive.archive.StorageService.create_presigned_put", + "shared.storage.MinioStorageService.create_presigned_put", return_value="presigned put", ) upload_task_mock = mocker.patch( @@ -307,7 +307,7 @@ def test_uploads_post(db, mocker, mock_redis): ) def test_uploads_post_tokenless(db, mocker, mock_redis, private, branch, branch_sent): presigned_put_mock = mocker.patch( - "shared.api_archive.archive.StorageService.create_presigned_put", + "shared.storage.MinioStorageService.create_presigned_put", return_value="presigned put", ) upload_task_mock = mocker.patch( @@ -452,7 +452,7 @@ def test_uploads_post_token_required_auth_check( upload_token_required_for_public_repos, ): presigned_put_mock = mocker.patch( - "shared.api_archive.archive.StorageService.create_presigned_put", + "shared.storage.MinioStorageService.create_presigned_put", return_value="presigned put", ) upload_task_mock = mocker.patch( @@ -600,7 +600,7 @@ def test_uploads_post_github_oidc_auth( mock_redis, ): presigned_put_mock = mocker.patch( - "shared.api_archive.archive.StorageService.create_presigned_put", + "shared.storage.MinioStorageService.create_presigned_put", return_value="presigned put", ) upload_task_mock = mocker.patch( @@ -726,7 +726,7 @@ def test_uploads_post_shelter(db, mocker, mock_redis): CanDoCoverageUploadsPermission, "has_permission", return_value=True ) presigned_put_mock = mocker.patch( - "shared.api_archive.archive.StorageService.create_presigned_put", + "shared.storage.MinioStorageService.create_presigned_put", return_value="presigned put", ) mocker.patch("upload.views.uploads.trigger_upload_task", return_value=True) @@ -883,7 +883,7 @@ def test_uploads_post_github_enterprise_oidc_auth_jwks_url( analytics_service_mock, ): self.mocker.patch( - "shared.api_archive.archive.StorageService.create_presigned_put", + "shared.storage.MinioStorageService.create_presigned_put", return_value="presigned put", ) self.mocker.patch("upload.views.uploads.trigger_upload_task", return_value=True) @@ -941,7 +941,7 @@ def test_uploads_post_github_enterprise_oidc_auth_no_url( ): mock_config_helper(self.mocker, configs={"github_enterprise.url": None}) self.mocker.patch( - "shared.api_archive.archive.StorageService.create_presigned_put", + "shared.storage.MinioStorageService.create_presigned_put", return_value="presigned put", ) self.mocker.patch("upload.views.uploads.trigger_upload_task", return_value=True) diff --git a/upload/views/legacy.py b/upload/views/legacy.py index 3681a85cdc..ce56a6fc4f 100644 --- a/upload/views/legacy.py +++ b/upload/views/legacy.py @@ -388,6 +388,7 @@ async def get_repo(self): raise Http404("Requested report could not be found") return repo + @sync_to_async def validate_path(self, repo): msg = "Requested report could not be found" if not self.path: @@ -435,7 +436,7 @@ async def get(self, request, *args, **kwargs): self.read_params() repo = await self.get_repo() - self.validate_path(repo) + await self.validate_path(repo) response = HttpResponse(status=302) response["Location"] = await self.get_presigned_url(repo) diff --git a/utils/test_results.py b/utils/test_results.py index c9c45c6a77..d776882b95 100644 --- a/utils/test_results.py +++ b/utils/test_results.py @@ -1,6 +1,6 @@ import polars as pl from django.conf import settings -from shared.api_archive.storage import StorageService +from shared.storage import get_appropriate_storage_service from shared.storage.exceptions import FileNotInStorageError from services.redis_configuration import get_redis_connection @@ -55,7 +55,7 @@ def get_results( if result is None: # try storage - storage_service = StorageService() + storage_service = get_appropriate_storage_service() key = storage_key(repoid, branch, interval_start, interval_end) try: result = storage_service.read_file(