Add Redmine API token authentication
This commit is contained in:
@@ -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("") == "Иванов И.И."
|
||||
|
||||
Reference in New Issue
Block a user