aider-gitea/test/test_daemon_mode.py

37 lines
1.3 KiB
Python

import unittest
from unittest.mock import patch, MagicMock
import sys
import aider_gitea.__main__ as main_module
class TestDaemonMode(unittest.TestCase):
@patch('aider_gitea.__main__.secrets.gitea_token', return_value='dummy_token')
@patch('aider_gitea.__main__.GiteaClient')
@patch('aider_gitea.__main__.SeenIssuesDB')
@patch('aider_gitea.__main__.process_issue')
def test_daemon_mode(self, mock_process_issue, MockSeenIssuesDB, MockGiteaClient):
mock_args = MagicMock()
mock_args.daemon = True
mock_args.gitea_url = "http://example.com"
mock_args.owner = "owner"
mock_args.repo = "repo"
mock_args.base_branch = "main"
mock_client = MockGiteaClient.return_value
mock_client.get_issues.return_value = [
{"number": 1, "title": "Test Issue", "body": "This is a test issue", "labels": [{"name": "aider"}]}
]
mock_db = MockSeenIssuesDB.return_value
mock_db.has_seen.return_value = False
with patch('sys.argv', ['main.py', '--gitea-url', 'http://example.com', '--owner', 'owner', '--repo', 'repo']), \
patch('time.sleep', return_value=None):
with self.assertRaises(SystemExit):
main_module.main()
mock_process_issue.assert_called_once()
if __name__ == '__main__':
unittest.main()