From c0545407f2018c0e3f7171cfb857b60c034e3d61 Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Mon, 16 Nov 2020 12:38:43 +0100 Subject: [PATCH 1/4] tests: add conector_params fixture (#48567) Connector parameters can be set through command line --connector-params key=value or pytest.ini: [pytest.ini] addopts = --connectors-praams key=value --- tests/conftest.py | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/tests/conftest.py b/tests/conftest.py index 4f3f5406..5d54cd29 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,3 +1,7 @@ +import argparse +from io import BytesIO +import re + import pytest from httmock import urlmatch, HTTMock, response, remember_called @@ -6,7 +10,6 @@ import django_webtest from django.core.files import File from django.core.cache import cache from django.utils import six -from io import BytesIO from utils import make_resource @@ -14,6 +17,26 @@ if six.PY2: collect_ignore = ['wcs/'] +def pytest_addoption(parser): + def key_value_option(string): + if not re.match(r'\w+=.*', string): + raise argparse.ArgumentTypeError('invalid key=value option') + return string.split('=', 1) + + class KeyValueOption(argparse.Action): + def __call__(self, parser, namespace, values, option_string=None): + key, value = values + d = getattr(namespace, self.dest) + d[key] = value + + parser.addoption('--connector-params', action=KeyValueOption, type=key_value_option, default={}) + + +@pytest.fixture +def connector_params(pytestconfig): + return pytestconfig.getoption('connector_params').copy() + + @pytest.fixture(autouse=True) def media(settings, tmpdir): settings.MEDIA_ROOT = str(tmpdir.mkdir('media')) @@ -194,3 +217,16 @@ def clear_cache(): yield finally: InMemoryCache._cache = {} + + +@pytest.fixture +def rsa13(db): + return utils.make_resource( + RSA13Resource, + title='Test', + slug='test', + description='Test', + webservice_base_url='https://rsa-cd13.com', + basic_auth_username='username', + basic_auth_password='password', + ) -- 2.29.2