From e2b3bdb8111c68ea9ea248e6ff8cd8f917921167 Mon Sep 17 00:00:00 2001 From: Jon Michael Aanes Date: Tue, 15 Apr 2025 00:21:48 +0200 Subject: [PATCH] Ruff --- aider_gitea/gitea_client.py | 12 +++++++----- test/test_gitea_client.py | 36 +++++++++++++++++++----------------- 2 files changed, 26 insertions(+), 22 deletions(-) diff --git a/aider_gitea/gitea_client.py b/aider_gitea/gitea_client.py index 3254324..587db06 100644 --- a/aider_gitea/gitea_client.py +++ b/aider_gitea/gitea_client.py @@ -129,18 +129,20 @@ class GiteaClient: if repo['owner']['login'].lower() != owner.lower(): continue yield repo['name'] - - def get_pull_request_comments(self, owner: str, repo: str, pull_number: int) -> list[dict]: + + def get_pull_request_comments( + self, owner: str, repo: str, pull_number: int, + ) -> list[dict]: """Get comments for a specific pull request. - + Args: owner (str): Owner of the repository. repo (str): Name of the repository. pull_number (int): The pull request number. - + Returns: list[dict]: A list of comment dictionaries containing comment data. - + Raises: requests.HTTPError: If the API request fails. """ diff --git a/test/test_gitea_client.py b/test/test_gitea_client.py index 951657e..9eefae0 100644 --- a/test/test_gitea_client.py +++ b/test/test_gitea_client.py @@ -1,32 +1,32 @@ -import pytest from unittest.mock import MagicMock + from aider_gitea.gitea_client import GiteaClient class TestGiteaClient: def setup_method(self): """Set up test fixtures.""" - self.gitea_url = "https://gitea.example.com" - self.token = "test_token" + self.gitea_url = 'https://gitea.example.com' + self.token = 'test_token' self.client = GiteaClient(self.gitea_url, self.token) - self.owner = "test_owner" - self.repo = "test_repo" + self.owner = 'test_owner' + self.repo = 'test_repo' def test_get_pull_request_comments(self, monkeypatch): """Test retrieving comments for a pull request.""" pull_number = 123 expected_comments = [ { - "id": 1, - "body": "This is a test comment", - "user": {"login": "test_user"}, - "created_at": "2023-01-01T00:00:00Z", + 'id': 1, + 'body': 'This is a test comment', + 'user': {'login': 'test_user'}, + 'created_at': '2023-01-01T00:00:00Z', }, { - "id": 2, - "body": "Another test comment", - "user": {"login": "another_user"}, - "created_at": "2023-01-02T00:00:00Z", + 'id': 2, + 'body': 'Another test comment', + 'user': {'login': 'another_user'}, + 'created_at': '2023-01-02T00:00:00Z', }, ] @@ -37,14 +37,16 @@ class TestGiteaClient: # Mock the session.get method mock_get = MagicMock(return_value=mock_response) - monkeypatch.setattr(self.client.session, "get", mock_get) + monkeypatch.setattr(self.client.session, 'get', mock_get) # Call the method - comments = self.client.get_pull_request_comments(self.owner, self.repo, pull_number) + comments = self.client.get_pull_request_comments( + self.owner, self.repo, pull_number, + ) # Verify the result assert comments == expected_comments - + # Verify the correct URL was called - expected_url = f"{self.gitea_url}/api/v1/repos/{self.owner}/{self.repo}/pulls/{pull_number}/comments" + expected_url = f'{self.gitea_url}/api/v1/repos/{self.owner}/{self.repo}/pulls/{pull_number}/comments' mock_get.assert_called_once_with(expected_url)