This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
"""AppSettings key-value store — model behaviour.
|
||||
|
||||
ADMIN-001. The admin panel relies on AppSettings for global toggles
|
||||
(tryouts_open, season_active, season_name, season_start, season_end).
|
||||
These tests verify the key-value store itself, independent of any route.
|
||||
"""
|
||||
|
||||
import pytest
|
||||
|
||||
from app.extensions import db
|
||||
from app.models import AppSettings
|
||||
|
||||
|
||||
class TestAppSettingsGetSet:
|
||||
def test_get_returns_default_for_missing_key(self, app):
|
||||
with app.app_context():
|
||||
assert AppSettings.get('nonexistent', 'fallback') == 'fallback'
|
||||
|
||||
def test_set_and_get_roundtrip(self, app):
|
||||
with app.app_context():
|
||||
AppSettings.set('test_key', 'hello')
|
||||
assert AppSettings.get('test_key') == 'hello'
|
||||
|
||||
def test_set_overwrites_existing_key(self, app):
|
||||
with app.app_context():
|
||||
AppSettings.set('overwrite_key', 'first')
|
||||
AppSettings.set('overwrite_key', 'second')
|
||||
assert AppSettings.get('overwrite_key') == 'second'
|
||||
|
||||
def test_set_none_value_is_stored_as_none(self, app):
|
||||
with app.app_context():
|
||||
AppSettings.set('nullable_key', None)
|
||||
assert AppSettings.get('nullable_key') is None
|
||||
|
||||
|
||||
class TestAppSettingsBool:
|
||||
def test_get_bool_parses_true_values(self, app):
|
||||
with app.app_context():
|
||||
for val in ('true', 'True', 'TRUE', '1', 'yes', 'on'):
|
||||
AppSettings.set('bool_test', val)
|
||||
assert AppSettings.get_bool('bool_test'), f'{val!r} should be True'
|
||||
|
||||
def test_get_bool_parses_false_values(self, app):
|
||||
with app.app_context():
|
||||
for val in ('false', 'False', 'FALSE', '0', 'no', 'off', 'anything_else'):
|
||||
AppSettings.set('bool_test', val)
|
||||
assert not AppSettings.get_bool('bool_test'), f'{val!r} should be False'
|
||||
|
||||
def test_get_bool_defaults_to_false_for_missing_key(self, app):
|
||||
with app.app_context():
|
||||
assert not AppSettings.get_bool('does_not_exist')
|
||||
|
||||
def test_get_bool_respects_custom_default(self, app):
|
||||
with app.app_context():
|
||||
assert AppSettings.get_bool('does_not_exist', default=True)
|
||||
|
||||
def test_set_bool_stores_as_string(self, app):
|
||||
with app.app_context():
|
||||
AppSettings.set_bool('bool_key', True)
|
||||
assert AppSettings.get('bool_key') == 'true'
|
||||
AppSettings.set_bool('bool_key', False)
|
||||
assert AppSettings.get('bool_key') == 'false'
|
||||
Reference in New Issue
Block a user