Add unit-tests
This commit is contained in:
36
tests/test_client.py
Normal file
36
tests/test_client.py
Normal file
@@ -0,0 +1,36 @@
|
||||
import pytest
|
||||
from unittest import mock
|
||||
from redmine_reporter.client import fetch_issues_with_spent_time
|
||||
|
||||
|
||||
@mock.patch("redmine_reporter.client.Redmine")
|
||||
def test_fetch_issues_with_spent_time(mock_redmine_class):
|
||||
# Подготовка моков
|
||||
mock_redmine = mock_redmine_class.return_value
|
||||
mock_user = mock.MagicMock()
|
||||
mock_user.id = 123
|
||||
mock_redmine.user.get.return_value = mock_user
|
||||
|
||||
# Два time entry на одну задачу
|
||||
mock_entry1 = mock.MagicMock()
|
||||
mock_entry1.issue.id = 101
|
||||
mock_entry1.hours = 2.0
|
||||
mock_entry2 = mock.MagicMock()
|
||||
mock_entry2.issue.id = 101
|
||||
mock_entry2.hours = 1.5
|
||||
mock_redmine.time_entry.filter.return_value = [mock_entry1, mock_entry2]
|
||||
|
||||
# Мок задачи
|
||||
mock_issue = mock.MagicMock()
|
||||
mock_issue.id = 101
|
||||
mock_issue.project = "Проект X"
|
||||
mock_issue.subject = "Тестовая задача"
|
||||
mock_issue.status = "New"
|
||||
mock_redmine.issue.filter.return_value = [mock_issue]
|
||||
|
||||
result = fetch_issues_with_spent_time("2026-01-01", "2026-01-31")
|
||||
|
||||
assert result is not None
|
||||
assert len(result) == 1
|
||||
issue, total_hours = result[0]
|
||||
assert total_hours == 3.5
|
||||
Reference in New Issue
Block a user