From afe858fc9f8ac93ce1c512cf043d85872842451c Mon Sep 17 00:00:00 2001 From: Helmut Merz Date: Thu, 1 Oct 2026 09:17:18 +0200 Subject: [PATCH] clean separation of zope.testrunner tests (in scopes/tests) and pytest tests (in tests) --- pyproject.toml | 14 +++---- runtests.sh | 3 +- tests/config.py | 64 +++++++++++++++++++++++++++++ {scopes/tests => tests}/test_api.py | 0 4 files changed, 73 insertions(+), 8 deletions(-) create mode 100644 tests/config.py rename {scopes/tests => tests}/test_api.py (100%) diff --git a/pyproject.toml b/pyproject.toml index 64f2375..4c3ad1b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -11,7 +11,7 @@ license = {text = "MIT"} keywords = ["scopes"] authors = [{name = "Helmut Merz", email = "helmutm@cy55.de"}] -dependencies = ["SQLAlchemy", "pydantic-settings"] +dependencies = ["SQLAlchemy", "pydantic", "pydantic-settings"] [project.optional-dependencies] postgres = [ @@ -19,7 +19,7 @@ postgres = [ "transaction", "zope.sqlalchemy", ] -app = [ +app = [ # TODO: rename to zope "python-dotenv", "waitress", "zope.authentication", @@ -27,9 +27,9 @@ app = [ "zope.publisher", "zope.traversing", ] -auth = ["pyjwt[crypto]", "cryptography", "requests"] api = ["fastapi[standard]"] -test = ["zope.testrunner", "pydantic-settings"] +auth = ["pyjwt[crypto]", "cryptography", "requests"] +test = ["zope.testrunner"] # TODO: rename to zopetest, or merge with apitest apitest = ["pytest", "httpx2"] [tool.setuptools] @@ -37,7 +37,7 @@ packages = ["scopes"] [tool.pytest.ini_options] addopts = ["-s"] -#test_paths = ["tests"] -python_files = ["test_api.py"] -# use .pytest.ini file with `python_files = test_*.py` to run all tests +testpaths = ["tests"] +#python_files = ["test_api.py"] +# use .pytest.ini file for local test config diff --git a/runtests.sh b/runtests.sh index b9df66b..ce2a1fe 100755 --- a/runtests.sh +++ b/runtests.sh @@ -1,5 +1,6 @@ # runtests.sh # run all unit / doc tests -zope-testrunner --test-path=. -m !test_api $* +#zope-testrunner --test-path=. -m !test_api $* +zope-testrunner --test-path=. $* diff --git a/tests/config.py b/tests/config.py new file mode 100644 index 0000000..ff4f320 --- /dev/null +++ b/tests/config.py @@ -0,0 +1,64 @@ +# py-scopes/tests/config.py + +import logging +from pydantic_settings import BaseSettings, SettingsConfigDict + +class Settings(BaseSettings): + model_config = SettingsConfigDict(env_file='.env') + + base_url: str = 'https://test.cy7.eu' + + log_file: str = 'scopes/tests/log/scopes-test.log' + log_level: str = 'INFO' + log_format: str = '%(asctime)s %(levelname)s %(name)s %(message)s' + log_dateformat: str = '%Y-%m-%dT%H:%M:%S' + + + dbengine: str = 'sqlite' + dbname: str = 'var/test.db' + dbuser: str | None = None + dbpassword: str | None = None + dbschema: str | None = None + +settings = Settings() + +from os import getenv +import sys + +base_url = settings.base_url + +logging.basicConfig(filename=settings.log_file, level=settings.log_level, + format=settings.log_format, datefmt=settings.log_dateformat) + +# SQLite storage settings +dbengine = settings.dbengine +dbname = settings.dbname +dbuser = settings.dbuser +dbpassword = settings.dbpassword +dbschema = settings.dbschema + +# special testing stuff +from scopes.tests import data_auth # add oidc URIs and keys to dummy_requests data +from scopes.tests import dummy_requests +sys.modules['requests'] = dummy_requests + +# authentication settings +oidc_provider = 'test://oidc' +oidc_client_id = getenv('OIDC_CLIENT_ID', '12345') +oidc_params = dict( + op_config_url=oidc_provider + '/.well-known/openid-configuration', + op_uris=None, + op_keys=None, + op_project_scope='urn:zitadel:iam:org:project:id:zitadel:aud', + callback_url=getenv('OIDC_CALLBACK_URL', base_url + '/auth/callback'), + client_id=oidc_client_id, + principal_prefix=getenv('OIDC_PRINCIPAL_PREFIX', 'loops.'), + cookie_name=getenv('OIDC_COOKIE_NAME', 'oidc_' + oidc_client_id), + cookie_domain=getenv('OIDC_COOKIE_DOMAIN', None), + cookie_lifetime=getenv('OIDC_COOKIE_LIFETIME', '86400'), + cookie_crypt=getenv('OIDC_COOKIE_CRYPT', None), + private_key_file=getenv('OIDC_SERVICE_USER_PRIVATE_KEY_FILE', + 'scopes/tests/test-private-key.json'), + organization_id=getenv('OIDC_ORGANIZATION_ID', '12346'), + project_id=getenv('OIDC_PROJECT_ID', None), +) diff --git a/scopes/tests/test_api.py b/tests/test_api.py similarity index 100% rename from scopes/tests/test_api.py rename to tests/test_api.py