From df666249b292b60a5c93ee2b4a4028781e4f6d7c Mon Sep 17 00:00:00 2001 From: "sentry-autofix-experimental[bot]" <157164994+sentry-autofix-experimental[bot]@users.noreply.github.com> Date: Wed, 16 Oct 2024 17:26:43 +0000 Subject: [PATCH] This step creates a new file `test_github_comments.py` in the `tests/unit/torngit/` directory. The file contains a test class `TestGithubComments` with a single test method `test_build_comment_request_body_with_generate_tests_action`. The test method does the following: 1. Sets up the necessary input parameters for the `build_comment_request_body` function. 2. Calls the `build_comment_request_body` function with these parameters. 3. Asserts that the returned result contains the correct "Generate Tests" action with the expected properties. 4. Verifies that the comment body is constructed correctly with the header, content, and footer. This test ensures that the changes made to the `build_comment_request_body` function in `github.py` are working as expected, specifically the addition of the "Generate Tests" action. --- tests/unit/torngit/test_github_comments.py | 33 ++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 tests/unit/torngit/test_github_comments.py diff --git a/tests/unit/torngit/test_github_comments.py b/tests/unit/torngit/test_github_comments.py new file mode 100644 index 00000000..dbffceaf --- /dev/null +++ b/tests/unit/torngit/test_github_comments.py @@ -0,0 +1,33 @@ +import pytest +from unittest.mock import AsyncMock, MagicMock +from shared.torngit.github import build_comment_request_body + +class TestGithubComments: + @pytest.mark.asyncio + async def test_build_comment_request_body_with_generate_tests_action(self): + # Arrange + comment = "Test comment" + bot_name = "codecov-bot" + is_bot_comment = True + is_pull = True + is_analysis_requested = True + has_commit_data = True + include_button = True + comment_header = "Comment header" + comment_footer = "Comment footer" + repo = MagicMock() + + # Act + result = await build_comment_request_body( + comment, bot_name, is_bot_comment, is_pull, is_analysis_requested, + has_commit_data, include_button, comment_header, comment_footer, repo + ) + + # Assert + assert "actions" in result + assert len(result["actions"]) == 1 + action = result["actions"][0] + assert action["name"] == "Generate Tests" + assert action["type"] == "copilot-chat" + assert action["prompt"] == f"@{bot_name} generate tests for PR" + assert result["body"] == f"{comment_header}\n{comment}\n{comment_footer}"