@@ -16,6 +16,7 @@
import contextlib
import os
import re
import pytest
@@ -23,6 +24,8 @@ from . import testutil
from conservancy_beancount import config as config_mod
RT_AUTH_METHODS = frozenset(['basic', 'gssapi', 'rt'])
RT_ENV_KEYS = (
'RTSERVER',
'RTUSER',
@@ -44,6 +47,13 @@ RT_FILE_CREDS = (
'basic',
)
RT_GENERIC_CREDS = config_mod.RTCredentials(
'https://example.org/genericrt',
'genericuser',
'generic password',
None,
@pytest.fixture
def rt_environ():
return dict(zip(RT_ENV_KEYS, RT_ENV_CREDS))
@@ -109,3 +119,42 @@ def test_rt_credentials_from_all_sources_mixed(tmp_path):
config = config_mod.Config()
rt_credentials = config.rt_credentials()
assert rt_credentials == (server, 'mixedup', 'mixed up', 'rt')
def check_rt_client_url(credentials, client):
pattern = '^{}/?$'.format(re.escape(credentials[0].rstrip('/') + '/REST/1.0'))
assert re.match(pattern, client.url)
@pytest.mark.parametrize('authmethod', RT_AUTH_METHODS)
def test_rt_client(authmethod):
rt_credentials = RT_GENERIC_CREDS._replace(auth=authmethod)
rt_client = config.rt_client(rt_credentials, testutil.RTClient)
check_rt_client_url(RT_GENERIC_CREDS, rt_client)
assert rt_client.auth_method == ('HTTPBasicAuth' if authmethod == 'basic' else 'login')
assert rt_client.last_login == (
RT_GENERIC_CREDS.user,
RT_GENERIC_CREDS.passwd,
True,
def test_default_rt_client(rt_environ):
with update_environ(**rt_environ):
rt_client = config.rt_client(client=testutil.RTClient)
check_rt_client_url(RT_ENV_CREDS, rt_client)
assert rt_client.last_login[:-1] == RT_ENV_CREDS[1:3]
assert rt_client.last_login[-1]
def test_rt_client_login_failure(authmethod):
rt_credentials = RT_GENERIC_CREDS._replace(
auth=authmethod,
passwd='bad{}'.format(authmethod),
assert config.rt_client(rt_credentials, testutil.RTClient) is None
def test_no_rt_client_without_server():
rt_credentials = RT_GENERIC_CREDS._replace(server=None, auth='rt')