105 lines
2.5 KiB
Python
105 lines
2.5 KiB
Python
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
from contextlib import contextmanager
|
||
|
|
|
||
|
|
from datetime import datetime, timezone
|
||
|
|
|
||
|
|
import types
|
||
|
|
|
||
|
|
from ariadne.manager import provisioning as prov
|
||
|
|
|
||
|
|
from ariadne.services.vaultwarden import VaultwardenInvite, VaultwardenLookup
|
||
|
|
|
||
|
|
class DummyResult:
|
||
|
|
def __init__(self, row=None):
|
||
|
|
self._row = row
|
||
|
|
|
||
|
|
def fetchone(self):
|
||
|
|
return self._row
|
||
|
|
|
||
|
|
def fetchall(self):
|
||
|
|
return []
|
||
|
|
|
||
|
|
class DummyConn:
|
||
|
|
def __init__(self, row, locked=True):
|
||
|
|
self._row = row
|
||
|
|
self._locked = locked
|
||
|
|
self.executed = []
|
||
|
|
|
||
|
|
def execute(self, query, params=None):
|
||
|
|
self.executed.append((query, params))
|
||
|
|
if "pg_try_advisory_lock" in query:
|
||
|
|
return DummyResult({"locked": self._locked})
|
||
|
|
if "SELECT username" in query:
|
||
|
|
return DummyResult(self._row)
|
||
|
|
return DummyResult()
|
||
|
|
|
||
|
|
class DummyDB:
|
||
|
|
def __init__(self, row, locked=True):
|
||
|
|
self._row = row
|
||
|
|
self._locked = locked
|
||
|
|
|
||
|
|
@contextmanager
|
||
|
|
def connection(self):
|
||
|
|
yield DummyConn(self._row, locked=self._locked)
|
||
|
|
|
||
|
|
def fetchone(self, query, params=None):
|
||
|
|
return None
|
||
|
|
|
||
|
|
def fetchall(self, query, params=None):
|
||
|
|
return []
|
||
|
|
|
||
|
|
class DummyStorage:
|
||
|
|
def record_task_run(self, *args, **kwargs):
|
||
|
|
return None
|
||
|
|
|
||
|
|
def record_event(self, *args, **kwargs):
|
||
|
|
return None
|
||
|
|
|
||
|
|
def mark_welcome_sent(self, *args, **kwargs):
|
||
|
|
return None
|
||
|
|
|
||
|
|
def list_provision_candidates(self):
|
||
|
|
return []
|
||
|
|
|
||
|
|
class DummyAdmin:
|
||
|
|
def __init__(self):
|
||
|
|
self.groups = []
|
||
|
|
|
||
|
|
def ready(self):
|
||
|
|
return True
|
||
|
|
|
||
|
|
def find_user(self, username):
|
||
|
|
return {"id": "1"}
|
||
|
|
|
||
|
|
def find_user_by_email(self, email):
|
||
|
|
return None
|
||
|
|
|
||
|
|
def get_user(self, user_id):
|
||
|
|
return {"id": "1", "attributes": {}}
|
||
|
|
|
||
|
|
def create_user(self, payload):
|
||
|
|
return "1"
|
||
|
|
|
||
|
|
def update_user(self, user_id, payload):
|
||
|
|
return None
|
||
|
|
|
||
|
|
def reset_password(self, user_id, password, temporary=False):
|
||
|
|
return None
|
||
|
|
|
||
|
|
def set_user_attribute(self, username, key, value):
|
||
|
|
return None
|
||
|
|
|
||
|
|
def get_group_id(self, group_name: str):
|
||
|
|
return group_name
|
||
|
|
|
||
|
|
def add_user_to_group(self, user_id, group_id):
|
||
|
|
self.groups.append(group_id)
|
||
|
|
|
||
|
|
def _patch_mailu_ready(monkeypatch, settings, value=None) -> None:
|
||
|
|
if value is None:
|
||
|
|
value = bool(getattr(settings, "mailu_sync_url", ""))
|
||
|
|
monkeypatch.setattr(prov.mailu, "ready", lambda: value)
|
||
|
|
|
||
|
|
__all__ = [name for name in globals() if not name.startswith("__")]
|