Files
mailcow-dockerized/tests/python/backup/support.py
T
FreddleSpl0it 6cf0390d58 [Web][Restic][Dovecot][Dockerapi] Add restic backups with restore in the UI
- Scheduled, encrypted backups to S3, SFTP, REST or a local folder (new restic-mailcow container)
- Restore of mailboxes and whole domains in the UI, also deleted ones, for admins and domain admins
- Scope set by RESTIC_BACKUP_MODE in mailcow.conf (all, data, config)
- Optional backup before updates (update.sh), helper-scripts/restic.sh for a full restore
2026-11-08 22:56:27 +01:00

52 lines
1.1 KiB
Python

# Shared helpers of the backup runner tests: fake database rows and a settable clock
import datetime
import os
import time
class Cursor:
def __init__(self, rows):
self.rows = rows
self.rowcount = len(rows)
self.lastrowid = 1
def fetchone(self):
return self.rows[0] if self.rows else None
def fetchall(self):
return self.rows
def __iter__(self):
return iter(self.rows)
class FakeDatetime(datetime.datetime):
current = None
@classmethod
def now(cls, tz=None):
return cls.current
class Clock:
# datetime module for a runner: datetime.now() returns the set time
timedelta = datetime.timedelta
date = datetime.date
datetime = FakeDatetime
# Local time zone of the process for one test (cleaned up with the test case); the fake clock is reset as well
def use_timezone(test, name):
old = os.environ.get('TZ')
def restore():
if old is None:
os.environ.pop('TZ', None)
else:
os.environ['TZ'] = old
time.tzset()
FakeDatetime.current = None
test.addCleanup(restore)
os.environ['TZ'] = name
time.tzset()