move sso code so it won't fail tests if sso dependencies are missing

This commit is contained in:
Laura Klünder 2025-04-25 16:16:25 +02:00
parent 2fc4e89317
commit f83a5e90ae
2 changed files with 21 additions and 19 deletions

View file

@ -1,13 +1,9 @@
from django.conf import settings
from social_core.utils import SETTING_PREFIX as SOCIAL_AUTH_SETTING_PREFIX
from social_core.backends.utils import load_backends
from social_django.strategy import DjangoStrategy
_sso_services = None
def get_sso_services() -> dict[str, str]:
global _sso_services
from social_core.backends.utils import load_backends
from social_django.utils import load_strategy
if _sso_services is None:
@ -18,17 +14,3 @@ def get_sso_services() -> dict[str, str]:
return _sso_services
class C3navStrategy(DjangoStrategy):
"""A subclass of DjangoStrategy that uses our config parser in addition to django settings"""
_list_keys = {'authentication_backends', 'pipeline'}
def get_setting(self, name: str):
config_name = name.removeprefix(SOCIAL_AUTH_SETTING_PREFIX + '_').lower()
value = settings.C3NAV_CONFIG.get('sso', config_name,
fallback=None)
if value is not None:
if config_name in self._list_keys:
value = tuple(item.strip() for item in value.split(','))
else:
value = super().get_setting(name)
return value

View file

@ -0,0 +1,20 @@
from social_core.utils import SETTING_PREFIX as SOCIAL_AUTH_SETTING_PREFIX
from social_django.strategy import DjangoStrategy
from django.conf import settings
class C3navStrategy(DjangoStrategy):
"""A subclass of DjangoStrategy that uses our config parser in addition to django settings"""
_list_keys = {'authentication_backends', 'pipeline'}
def get_setting(self, name: str):
config_name = name.removeprefix(SOCIAL_AUTH_SETTING_PREFIX + '_').lower()
value = settings.C3NAV_CONFIG.get('sso', config_name,
fallback=None)
if value is not None:
if config_name in self._list_keys:
value = tuple(item.strip() for item in value.split(','))
else:
value = super().get_setting(name)
return value