v7.3: graceful shutdown/restart with countdown, custom/scheduled notifications, update guard, file jail, security hardening, experimental tab removed
This commit is contained in:
1 parent
aee4028f5c
commit
54d9d5db25
31 files changed
+2764
-2363
No files matched your search
@@ -0,0 +1,50 @@
|
||||
"""Tests for the battlegroup update guard (block while game pods run)."""
|
||||
|
||||
from app.services.k8s import K8sService
|
||||
|
||||
NS = 'funcom-seabass-sh-b17a5f036d1f7882-ccdijf'
|
||||
|
||||
|
||||
class FakeSSH:
|
||||
def __init__(self, out='', rc=0):
|
||||
self.out = out
|
||||
self.rc = rc
|
||||
self.commands = []
|
||||
|
||||
def run(self, command, timeout=30):
|
||||
self.commands.append(command)
|
||||
return self.out, '', self.rc
|
||||
|
||||
|
||||
def make_k8s(out='', rc=0):
|
||||
return K8sService(ssh_service=FakeSSH(out, rc), namespace=NS)
|
||||
|
||||
|
||||
class TestRunningGamePods:
|
||||
def test_detects_running_game_pods(self):
|
||||
out = (
|
||||
f'sh-b17a5f036d1f7882-ccdijf-sg-overmap-pod-2 Running\n'
|
||||
f'sh-b17a5f036d1f7882-ccdijf-sg-survival-1-pod-1 Running\n'
|
||||
f'sh-b17a5f036d1f7882-ccdijf-bgd-deploy-xxx Running\n'
|
||||
f'sh-b17a5f036d1f7882-ccdijf-mq-game-sts-0 Running\n'
|
||||
)
|
||||
running = make_k8s(out).get_running_game_pods()
|
||||
# Only sg-*-pod-* count as game servers; infra pods do not block.
|
||||
assert running == [
|
||||
'sh-b17a5f036d1f7882-ccdijf-sg-overmap-pod-2',
|
||||
'sh-b17a5f036d1f7882-ccdijf-sg-survival-1-pod-1',
|
||||
]
|
||||
|
||||
def test_empty_when_no_game_pods_running(self):
|
||||
out = (
|
||||
f'sh-b17a5f036d1f7882-ccdijf-bgd-deploy-xxx Running\n'
|
||||
f'sh-b17a5f036d1f7882-ccdijf-sg-overmap-pod-2 Completed\n'
|
||||
f'sh-b17a5f036d1f7882-ccdijf-mq-game-sts-0 Running\n'
|
||||
)
|
||||
assert make_k8s(out).get_running_game_pods() == []
|
||||
|
||||
def test_empty_when_no_pods(self):
|
||||
assert make_k8s('').get_running_game_pods() == []
|
||||
|
||||
def test_none_when_status_unknown(self):
|
||||
assert make_k8s('', rc=1).get_running_game_pods() is None
|
||||
@@ -0,0 +1,240 @@
|
||||
"""Tests for graceful shutdown/restart lifecycle service."""
|
||||
|
||||
import time
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
import pytest
|
||||
|
||||
from app.services.lifecycle import (
|
||||
COUNTDOWN_MARKS,
|
||||
FINAL_DURATION,
|
||||
LifecycleService,
|
||||
)
|
||||
|
||||
|
||||
class FakeSSH:
|
||||
def __init__(self):
|
||||
self.commands = []
|
||||
|
||||
def run(self, command, timeout=30):
|
||||
self.commands.append(command)
|
||||
return ('ok', '', 0)
|
||||
|
||||
|
||||
class FakeAdmin:
|
||||
def __init__(self):
|
||||
self.broadcasts = []
|
||||
|
||||
def send_global_broadcast(self, title, message, duration=30):
|
||||
self.broadcasts.append((title, message, duration))
|
||||
return True, 'sent'
|
||||
|
||||
|
||||
def make_service(tmp_path):
|
||||
ssh = FakeSSH()
|
||||
admin = FakeAdmin()
|
||||
svc = LifecycleService(
|
||||
ssh, admin,
|
||||
{'kubernetes': {'battlegroup_script': '/home/dune/.dune/bin/battlegroup'}},
|
||||
state_dir=str(tmp_path),
|
||||
)
|
||||
return svc, ssh, admin
|
||||
|
||||
|
||||
class TestCountdownTable:
|
||||
def test_marks_match_spec(self):
|
||||
"""15m..30s last 10s, 10s lasts 5s, final lasts 10s."""
|
||||
assert [(s, d) for s, _, d in COUNTDOWN_MARKS] == [
|
||||
(900, 10), (600, 10), (300, 10), (180, 10),
|
||||
(120, 10), (60, 10), (30, 10), (10, 5),
|
||||
]
|
||||
assert FINAL_DURATION == 10
|
||||
|
||||
def test_manual_messages(self):
|
||||
title, msg = LifecycleService._message_for(
|
||||
'restart', '5 minutes', 10, False, '', final=False)
|
||||
assert 'restart' in title.lower()
|
||||
assert '5 minutes' in msg
|
||||
title, msg = LifecycleService._message_for(
|
||||
'shutdown', '30 seconds', 10, False, '', final=False)
|
||||
assert 'shut' in msg.lower()
|
||||
|
||||
def test_scheduled_messages_mention_schedule(self):
|
||||
title, msg = LifecycleService._message_for(
|
||||
'restart', '5 minutes', 10, True, 'daily 05:00', final=False)
|
||||
assert 'Scheduled' in title
|
||||
assert 'daily 05:00' in msg
|
||||
|
||||
|
||||
class TestActiveJob:
|
||||
def test_start_and_cancel(self, tmp_path):
|
||||
svc, _, _ = make_service(tmp_path)
|
||||
try:
|
||||
result = svc.start_restart(reason='manual')
|
||||
assert result['success']
|
||||
assert svc.status()['active'] is True
|
||||
assert svc.status()['kind'] == 'restart'
|
||||
# Second job must be rejected while one is active.
|
||||
again = svc.start_shutdown()
|
||||
assert not again['success']
|
||||
finally:
|
||||
cancelled = svc.cancel()
|
||||
assert cancelled['success']
|
||||
assert svc.status()['active'] is False
|
||||
|
||||
def test_cancel_without_active(self, tmp_path):
|
||||
svc, _, _ = make_service(tmp_path)
|
||||
assert not svc.cancel()['success']
|
||||
|
||||
def test_first_notice_sent_immediately(self, tmp_path):
|
||||
"""The 15-minute notice is due at job start: it must be sent, not skipped."""
|
||||
svc, _, admin = make_service(tmp_path)
|
||||
try:
|
||||
assert svc.start_restart(reason='manual')['success']
|
||||
deadline = time.time() + 10
|
||||
while time.time() < deadline and not admin.broadcasts:
|
||||
time.sleep(0.2)
|
||||
assert admin.broadcasts, 'expected the 15-minute notice right after start'
|
||||
title, message, duration = admin.broadcasts[0]
|
||||
assert '15 minutes' in message and duration == 10
|
||||
finally:
|
||||
svc.cancel()
|
||||
|
||||
def test_cancel_sends_ingame_notice(self, tmp_path):
|
||||
svc, _, admin = make_service(tmp_path)
|
||||
assert svc.start_shutdown(reason='manual')['success']
|
||||
deadline = time.time() + 10
|
||||
while time.time() < deadline and not admin.broadcasts:
|
||||
time.sleep(0.2)
|
||||
result = svc.cancel()
|
||||
assert result['success']
|
||||
assert result['notice_sent'] is True
|
||||
assert any('called off' in msg.lower() for _, msg, _ in admin.broadcasts)
|
||||
|
||||
def test_short_countdown_runs_to_execute(self, tmp_path):
|
||||
"""12s countdown: stale marks skipped, late marks sent, action executed."""
|
||||
import time as _time
|
||||
svc, ssh, admin = make_service(tmp_path)
|
||||
action_at = _time.time() + 12
|
||||
assert svc.start_restart_at(action_at, reason='manual')['success']
|
||||
deadline = _time.time() + 40
|
||||
while _time.time() < deadline and svc.status().get('active', False):
|
||||
_time.sleep(0.5)
|
||||
assert not svc.status().get('active', False)
|
||||
assert any('battlegroup' in cmd and 'restart' in cmd for cmd in ssh.commands)
|
||||
assert any('restarting now' in msg.lower() for _, msg, _ in admin.broadcasts)
|
||||
|
||||
|
||||
class TestScheduleCalc:
|
||||
def test_daily_next_run(self, tmp_path):
|
||||
svc, _, _ = make_service(tmp_path)
|
||||
now = datetime(2026, 9, 21, 4, 0, 0) # Monday
|
||||
cfg = {'mode': 'daily', 'daily_times': ['05:00']}
|
||||
assert svc.compute_next_run(cfg, now) == '2026-09-21T05:00:00'
|
||||
|
||||
def test_daily_rolls_to_tomorrow(self, tmp_path):
|
||||
svc, _, _ = make_service(tmp_path)
|
||||
now = datetime(2026, 9, 21, 6, 0, 0)
|
||||
cfg = {'mode': 'daily', 'daily_times': ['05:00']}
|
||||
assert svc.compute_next_run(cfg, now) == '2026-09-22T05:00:00'
|
||||
|
||||
def test_weekly_next_run(self, tmp_path):
|
||||
svc, _, _ = make_service(tmp_path)
|
||||
now = datetime(2026, 9, 21, 4, 0, 0) # Monday (weekday 0)
|
||||
cfg = {'mode': 'weekly', 'weekly_days': [6], 'weekly_times': ['05:00']}
|
||||
nxt = datetime.fromisoformat(svc.compute_next_run(cfg, now))
|
||||
assert nxt.weekday() == 6
|
||||
assert (nxt.hour, nxt.minute) == (5, 0)
|
||||
|
||||
def test_monthly_next_run(self, tmp_path):
|
||||
svc, _, _ = make_service(tmp_path)
|
||||
now = datetime(2026, 9, 21, 6, 0, 0)
|
||||
cfg = {'mode': 'monthly', 'monthly_days': [1], 'monthly_time': '05:00'}
|
||||
nxt = datetime.fromisoformat(svc.compute_next_run(cfg, now))
|
||||
assert (nxt.month, nxt.day, nxt.hour) == (10, 1, 5)
|
||||
|
||||
def test_once_future_and_past(self, tmp_path):
|
||||
svc, _, _ = make_service(tmp_path)
|
||||
now = datetime(2026, 9, 21, 4, 0, 0)
|
||||
future = (now + timedelta(hours=2)).isoformat()
|
||||
assert svc.compute_next_run({'mode': 'once', 'once_at': future}, now) == future
|
||||
past = (now - timedelta(hours=1)).isoformat()
|
||||
assert svc.compute_next_run({'mode': 'once', 'once_at': past}, now) == ''
|
||||
|
||||
def test_update_schedule_rejects_bad_mode(self, tmp_path):
|
||||
svc, _, _ = make_service(tmp_path)
|
||||
with pytest.raises(ValueError):
|
||||
svc.update_schedule({'mode': 'yearly'})
|
||||
|
||||
def test_disable_preserves_settings(self, tmp_path):
|
||||
svc, _, _ = make_service(tmp_path)
|
||||
svc.update_schedule({'enabled': True, 'mode': 'daily',
|
||||
'daily_times': ['06:00']})
|
||||
cfg = svc.set_enabled(False)
|
||||
assert cfg['enabled'] is False
|
||||
assert cfg['daily_times'] == ['06:00']
|
||||
assert cfg['mode'] == 'daily'
|
||||
cfg = svc.set_enabled(True)
|
||||
assert cfg['enabled'] is True
|
||||
assert cfg['daily_times'] == ['06:00']
|
||||
|
||||
def test_clear_disarms_but_keeps_settings(self, tmp_path):
|
||||
svc, _, _ = make_service(tmp_path)
|
||||
svc.update_schedule({'enabled': True, 'mode': 'weekly',
|
||||
'weekly_days': [1, 3],
|
||||
'weekly_times': ['07:00']})
|
||||
cfg = svc.clear_schedule()
|
||||
assert cfg['enabled'] is False
|
||||
assert cfg['next_run'] == ''
|
||||
assert cfg['mode'] == 'weekly'
|
||||
assert cfg['weekly_days'] == [1, 3]
|
||||
assert cfg['weekly_times'] == ['07:00']
|
||||
|
||||
def test_once_accepts_utc_and_local_strings(self, tmp_path):
|
||||
svc, _, _ = make_service(tmp_path)
|
||||
now = datetime.now().replace(second=0, microsecond=0)
|
||||
future_local = (now + timedelta(hours=2)).replace(microsecond=0)
|
||||
assert svc.compute_next_run(
|
||||
{'mode': 'once', 'once_at': future_local.isoformat()}, now) != ''
|
||||
future_utc = future_local.strftime('%Y-%m-%dT%H:%M:%SZ')
|
||||
assert svc.compute_next_run(
|
||||
{'mode': 'once', 'once_at': future_utc}, now) != ''
|
||||
|
||||
|
||||
class TestSchedulerFire:
|
||||
def test_fire_inside_window_starts_countdown(self, tmp_path):
|
||||
svc, _, _ = make_service(tmp_path)
|
||||
try:
|
||||
action_at = (datetime.now() + timedelta(minutes=10)).replace(
|
||||
second=0, microsecond=0)
|
||||
svc.update_schedule({
|
||||
'enabled': True, 'mode': 'once',
|
||||
'once_at': action_at.isoformat(),
|
||||
})
|
||||
result = svc.check_and_fire()
|
||||
assert result and result['success']
|
||||
assert svc.status()['active'] is True
|
||||
assert svc.status()['reason'] == 'scheduled'
|
||||
# Second tick must not double-fire the same occurrence.
|
||||
assert svc.check_and_fire() is None
|
||||
finally:
|
||||
svc.cancel()
|
||||
|
||||
def test_no_fire_outside_window(self, tmp_path):
|
||||
svc, _, _ = make_service(tmp_path)
|
||||
action_at = datetime.now() + timedelta(hours=5)
|
||||
svc.update_schedule({
|
||||
'enabled': True, 'mode': 'once',
|
||||
'once_at': action_at.replace(second=0, microsecond=0).isoformat(),
|
||||
})
|
||||
assert svc.check_and_fire() is None
|
||||
assert svc.status()['active'] is False
|
||||
|
||||
def test_disabled_schedule_never_fires(self, tmp_path):
|
||||
svc, _, _ = make_service(tmp_path)
|
||||
action_at = datetime.now() + timedelta(minutes=5)
|
||||
svc.update_schedule({
|
||||
'enabled': False, 'mode': 'once',
|
||||
'once_at': action_at.replace(second=0, microsecond=0).isoformat(),
|
||||
})
|
||||
assert svc.check_and_fire() is None
|
||||
@@ -0,0 +1,138 @@
|
||||
"""Tests for scheduled custom notifications."""
|
||||
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
import pytest
|
||||
|
||||
from app.services.scheduled_broadcast import ScheduledBroadcastService
|
||||
|
||||
|
||||
class FakeAdmin:
|
||||
def __init__(self):
|
||||
self.broadcasts = []
|
||||
|
||||
def send_global_broadcast(self, title, message, duration=30):
|
||||
self.broadcasts.append((title, message, duration))
|
||||
return True, 'sent'
|
||||
|
||||
|
||||
def make_service(tmp_path):
|
||||
admin = FakeAdmin()
|
||||
svc = ScheduledBroadcastService(admin, state_dir=str(tmp_path))
|
||||
return svc, admin
|
||||
|
||||
|
||||
def base_entry(**overrides):
|
||||
entry = {
|
||||
'title': 'Notice',
|
||||
'message': 'Hello players',
|
||||
'duration': 30,
|
||||
'mode': 'daily',
|
||||
'daily_times': ['12:00'],
|
||||
}
|
||||
entry.update(overrides)
|
||||
return entry
|
||||
|
||||
|
||||
class TestEntryCrud:
|
||||
def test_save_and_list(self, tmp_path):
|
||||
svc, _ = make_service(tmp_path)
|
||||
entry = svc.save_entry(base_entry())
|
||||
assert entry['id']
|
||||
assert entry['next_run']
|
||||
assert [e['id'] for e in svc.list_entries()] == [entry['id']]
|
||||
|
||||
def test_requires_title_and_message(self, tmp_path):
|
||||
svc, _ = make_service(tmp_path)
|
||||
with pytest.raises(ValueError):
|
||||
svc.save_entry(base_entry(title=''))
|
||||
with pytest.raises(ValueError):
|
||||
svc.save_entry(base_entry(message=''))
|
||||
|
||||
def test_duration_clamped(self, tmp_path):
|
||||
svc, _ = make_service(tmp_path)
|
||||
assert svc.save_entry(base_entry(duration=999))['duration'] == 300
|
||||
assert svc.save_entry(base_entry(duration=1))['duration'] == 5
|
||||
|
||||
def test_rejects_bad_mode(self, tmp_path):
|
||||
svc, _ = make_service(tmp_path)
|
||||
with pytest.raises(ValueError):
|
||||
svc.save_entry(base_entry(mode='yearly'))
|
||||
|
||||
def test_delete(self, tmp_path):
|
||||
svc, _ = make_service(tmp_path)
|
||||
entry = svc.save_entry(base_entry())
|
||||
assert svc.delete_entry(entry['id']) is True
|
||||
assert svc.list_entries() == []
|
||||
assert svc.delete_entry(entry['id']) is False
|
||||
|
||||
def test_enable_disable_preserves_settings(self, tmp_path):
|
||||
svc, _ = make_service(tmp_path)
|
||||
entry = svc.save_entry(base_entry(daily_times=['06:00', '18:00']))
|
||||
disabled = svc.set_enabled(entry['id'], False)
|
||||
assert disabled['enabled'] is False
|
||||
assert disabled['daily_times'] == ['06:00', '18:00']
|
||||
assert disabled['title'] == 'Notice'
|
||||
assert disabled['message'] == 'Hello players'
|
||||
enabled = svc.set_enabled(entry['id'], True)
|
||||
assert enabled['enabled'] is True
|
||||
assert enabled['daily_times'] == ['06:00', '18:00']
|
||||
|
||||
|
||||
class TestFiring:
|
||||
def test_daily_fires_at_time(self, tmp_path):
|
||||
svc, admin = make_service(tmp_path)
|
||||
target = (datetime.now() + timedelta(minutes=1)).replace(second=0, microsecond=0)
|
||||
entry = svc.save_entry(base_entry(
|
||||
daily_times=[target.strftime('%H:%M')]))
|
||||
assert entry['next_run'] != ''
|
||||
fired = svc.check_and_fire(target + timedelta(seconds=5))
|
||||
assert len(fired) == 1
|
||||
assert admin.broadcasts and admin.broadcasts[0][:2] == ('Notice', 'Hello players')
|
||||
# Must not fire twice for the same occurrence.
|
||||
assert svc.check_and_fire(target + timedelta(seconds=10)) == []
|
||||
# ... but the next occurrence is armed.
|
||||
updated = svc.list_entries()[0]
|
||||
assert updated['next_run'] and updated['next_run'] != entry['next_run']
|
||||
|
||||
def test_once_past_never_arms(self, tmp_path):
|
||||
svc, _ = make_service(tmp_path)
|
||||
now = datetime.now().replace(second=0, microsecond=0)
|
||||
entry = svc.save_entry(base_entry(
|
||||
mode='once', once_at=(now - timedelta(minutes=1)).isoformat()))
|
||||
assert entry['next_run'] == ''
|
||||
|
||||
def test_once_fires_then_disables_keeping_settings(self, tmp_path):
|
||||
svc, admin = make_service(tmp_path)
|
||||
now = datetime.now().replace(second=0, microsecond=0)
|
||||
entry = svc.save_entry(base_entry(
|
||||
mode='once', once_at=(now + timedelta(minutes=1)).isoformat()))
|
||||
assert entry['next_run'] != ''
|
||||
fired = svc.check_and_fire(now + timedelta(minutes=2))
|
||||
assert len(fired) == 1
|
||||
updated = [e for e in svc.list_entries() if e['id'] == entry['id']][0]
|
||||
assert updated['enabled'] is False
|
||||
assert updated['title'] == 'Notice' # settings kept for reuse
|
||||
assert updated['once_at'] != ''
|
||||
|
||||
def test_disabled_entry_never_fires(self, tmp_path):
|
||||
svc, admin = make_service(tmp_path)
|
||||
target = (datetime.now() + timedelta(minutes=1)).replace(second=0, microsecond=0)
|
||||
svc.save_entry(base_entry(
|
||||
enabled=False, daily_times=[target.strftime('%H:%M')]))
|
||||
assert svc.check_and_fire(target + timedelta(seconds=5)) == []
|
||||
assert admin.broadcasts == []
|
||||
|
||||
def test_missed_window_rolls_forward_without_firing(self, tmp_path):
|
||||
svc, admin = make_service(tmp_path)
|
||||
now = datetime.now().replace(second=0, microsecond=0)
|
||||
svc.save_entry(base_entry(
|
||||
daily_times=[(now - timedelta(hours=3)).strftime('%H:%M')]))
|
||||
# Force the stored next_run into the past to simulate downtime.
|
||||
entries = svc.list_entries()
|
||||
past = (now - timedelta(hours=2)).isoformat()
|
||||
entries[0]['next_run'] = past
|
||||
entries[0]['last_fired_for'] = ''
|
||||
svc._save(entries)
|
||||
assert svc.check_and_fire(now) == []
|
||||
assert admin.broadcasts == []
|
||||
@@ -0,0 +1,76 @@
|
||||
"""Tests for no-behavior-change security validations."""
|
||||
|
||||
import pytest
|
||||
|
||||
from app.routes.api import fb_within_roots
|
||||
from app.services.backup import is_valid_backup_name
|
||||
|
||||
|
||||
class TestFileBrowserJail:
|
||||
ROOTS = ['/srv', '/home/dune/.dune']
|
||||
|
||||
def test_inside_roots(self):
|
||||
assert fb_within_roots('/srv', self.ROOTS)
|
||||
assert fb_within_roots('/srv/', self.ROOTS)
|
||||
assert fb_within_roots('/srv/sub/dir/file.txt', self.ROOTS)
|
||||
assert fb_within_roots('/home/dune/.dune/settings.conf', self.ROOTS)
|
||||
|
||||
def test_outside_roots(self):
|
||||
assert not fb_within_roots('/', self.ROOTS)
|
||||
assert not fb_within_roots('/etc/passwd', self.ROOTS)
|
||||
assert not fb_within_roots('/etc/shadow', self.ROOTS)
|
||||
assert not fb_within_roots('/home/dune/.ssh/id_rsa', self.ROOTS)
|
||||
assert not fb_within_roots('/home/dune/.dune-evil/x', self.ROOTS)
|
||||
assert not fb_within_roots('/srv-evil/x', self.ROOTS)
|
||||
assert not fb_within_roots('', self.ROOTS)
|
||||
|
||||
def test_prefix_trick_rejected(self):
|
||||
# '/srv-evil' must not match root '/srv'
|
||||
assert not fb_within_roots('/srv-evil', ['/srv'])
|
||||
assert fb_within_roots('/srv/a', ['/srv'])
|
||||
|
||||
|
||||
class TestBackupNameWhitelist:
|
||||
def test_valid_names(self):
|
||||
assert is_valid_backup_name('backup-21-09-2026_103000')
|
||||
assert is_valid_backup_name('backup-01-01-2000_000000')
|
||||
|
||||
def test_rejects_traversal_and_shell(self):
|
||||
assert not is_valid_backup_name('../../settings')
|
||||
assert not is_valid_backup_name('backup-21-09-2026_103000; id')
|
||||
assert not is_valid_backup_name('x; id>/tmp/pwn; echo ')
|
||||
assert not is_valid_backup_name('')
|
||||
assert not is_valid_backup_name(None)
|
||||
assert not is_valid_backup_name('backup-21-09-2026_103000.tar.gz')
|
||||
assert not is_valid_backup_name('something-else')
|
||||
|
||||
|
||||
class TestOnceAtValidation:
|
||||
def test_lifecycle_rejects_garbage(self, tmp_path):
|
||||
from app.services.lifecycle import LifecycleService
|
||||
|
||||
class FakeSSH:
|
||||
def run(self, *a, **k):
|
||||
return '', '', 0
|
||||
|
||||
class FakeAdmin:
|
||||
def send_global_broadcast(self, *a, **k):
|
||||
return True, 'sent'
|
||||
|
||||
svc = LifecycleService(FakeSSH(), FakeAdmin(), {}, state_dir=str(tmp_path))
|
||||
with pytest.raises(ValueError):
|
||||
svc.update_schedule({'mode': 'once', 'once_at': 'not-a-date'})
|
||||
|
||||
def test_broadcast_rejects_garbage(self, tmp_path):
|
||||
from app.services.scheduled_broadcast import ScheduledBroadcastService
|
||||
|
||||
class FakeAdmin:
|
||||
def send_global_broadcast(self, *a, **k):
|
||||
return True, 'sent'
|
||||
|
||||
svc = ScheduledBroadcastService(FakeAdmin(), state_dir=str(tmp_path))
|
||||
with pytest.raises(ValueError):
|
||||
svc.save_entry({
|
||||
'title': 't', 'message': 'm', 'mode': 'once',
|
||||
'once_at': 'not-a-date',
|
||||
})
|
||||
Reference in new issue
Block a user