Add Redmine API token authentication

This commit is contained in:
Кокос Артем Николаевич
2026-05-22 17:18:30 +07:00
parent 7bc6e024c0
commit 8bc8181ce3
14 changed files with 190 additions and 43 deletions

View File

@@ -1,4 +1,3 @@
import os
import pytest
from unittest import mock
from redmine_reporter.config import Config
@@ -11,24 +10,49 @@ from redmine_reporter.config import Config
@mock.patch.multiple(
Config,
REDMINE_URL="https://red.eltex.loc",
REDMINE_API_KEY=None,
REDMINE_USER="test",
REDMINE_PASSWORD="secret",
)
def test_config_valid():
def test_config_valid_with_password_fallback():
Config.validate() # не должно быть исключения
@mock.patch.multiple(
Config,
REDMINE_URL="https://red.eltex.loc",
REDMINE_API_KEY="token",
REDMINE_USER=None,
REDMINE_PASSWORD=None,
)
def test_config_valid_with_api_key():
Config.validate() # не должно быть исключения
@mock.patch.multiple(
Config,
REDMINE_URL="",
REDMINE_API_KEY=None,
REDMINE_USER=None,
REDMINE_PASSWORD=None,
)
def test_config_missing():
def test_config_missing_url():
with pytest.raises(ValueError, match="REDMINE_URL"):
Config.validate()
@mock.patch.multiple(
Config,
REDMINE_URL="https://red.eltex.loc",
REDMINE_API_KEY=None,
REDMINE_USER=None,
REDMINE_PASSWORD=None,
)
def test_config_missing_auth():
with pytest.raises(ValueError, match="REDMINE_API_KEY"):
Config.validate()
@mock.patch.multiple(Config, REDMINE_AUTHOR="Иванов И.И.")
def test_get_author():
assert Config.get_author("") == "Иванов И.И."