From 52d3cd0fc4ccf96c54df7c411e4103d9cea13509 Mon Sep 17 00:00:00 2001 From: JerrySentry Date: Tue, 23 Apr 2024 12:22:43 -0400 Subject: [PATCH] fix: Handle flare when commit report not available --- graphs/tests/test_graph_handler.py | 33 ++++++++++++++++++++++++++++++ graphs/views.py | 4 ++++ 2 files changed, 37 insertions(+) diff --git a/graphs/tests/test_graph_handler.py b/graphs/tests/test_graph_handler.py index cfbbbfdfb5..3101cd2835 100644 --- a/graphs/tests/test_graph_handler.py +++ b/graphs/tests/test_graph_handler.py @@ -657,3 +657,36 @@ def test_pull_no_repo_graph(self): response.data["detail"] == "Not found. Note: private repositories require ?token arguments" ) + + @patch("services.report.build_report_from_commit") + def test_pull_file_not_found_in_storage(self, mocked_build_report): + mocked_build_report.return_value = None + gh_owner = OwnerFactory(service="github") + repo = RepositoryFactory( + author=gh_owner, + active=True, + private=True, + name="repo1", + image_token="12345678", + branch="master", + ) + CommitWithReportFactory(repository=repo, author=gh_owner) + PullFactory(pullid=10, repository_id=repo.repoid, _flare=None) + + response = self._get_pull( + "tree", + kwargs={ + "service": "gh", + "owner_username": gh_owner.username, + "repo_name": "repo1", + "ext": "svg", + "pull": 10, + }, + data={"token": "12345678"}, + ) + + assert response.status_code == status.HTTP_404_NOT_FOUND + assert ( + response.data["detail"] + == "Not found. Note: file for chunks not found in storage" + ) diff --git a/graphs/views.py b/graphs/views.py index 2cc140bbb2..5bdc81b3de 100644 --- a/graphs/views.py +++ b/graphs/views.py @@ -214,6 +214,10 @@ def get_commit_flare(self): ) report = report_service.build_report_from_commit(commit) + + if report is None: + raise NotFound("Not found. Note: file for chunks not found in storage") + return report.flare(None, [70, 100]) def get_pull_flare(self, pullid):