matchy/tests/state_test.py

67 lines
2 KiB
Python
Raw Normal View History

"""
Test functions for the state module
"""
import matchy.state as state
import tempfile
import os
def test_basic_state():
"""Simple validate basic state load"""
with tempfile.TemporaryDirectory() as tmp:
path = os.path.join(tmp, 'tmp.json')
state.load_from_file(path)
def test_simple_load_reload():
"""Test a basic load, save, reload"""
with tempfile.TemporaryDirectory() as tmp:
path = os.path.join(tmp, 'tmp.json')
st = state.load_from_file(path)
2024-08-16 23:21:20 +01:00
state._save(st._file, st._dict)
state._save(st._file, st._dict)
st = state.load_from_file(path)
2024-08-16 23:21:20 +01:00
state._save(st._file, st._dict)
st = state.load_from_file(path)
def test_authscope():
"""Test setting and getting an auth scope"""
with tempfile.TemporaryDirectory() as tmp:
path = os.path.join(tmp, 'tmp.json')
st = state.load_from_file(path)
2024-08-16 23:21:20 +01:00
state._save(st._file, st._dict)
assert not st.get_user_has_scope(1, state.AuthScope.MATCHER)
st = state.load_from_file(path)
st.set_user_scope(1, state.AuthScope.MATCHER)
2024-08-16 23:21:20 +01:00
state._save(st._file, st._dict)
st = state.load_from_file(path)
assert st.get_user_has_scope(1, state.AuthScope.MATCHER)
st.set_user_scope(1, state.AuthScope.MATCHER, False)
assert not st.get_user_has_scope(1, state.AuthScope.MATCHER)
def test_channeljoin():
"""Test setting and getting an active channel"""
with tempfile.TemporaryDirectory() as tmp:
path = os.path.join(tmp, 'tmp.json')
st = state.load_from_file(path)
2024-08-16 23:21:20 +01:00
state._save(st._file, st._dict)
assert not st.get_user_active_in_channel(1, "2")
st = state.load_from_file(path)
2024-08-11 19:02:47 +01:00
st.set_user_active_in_channel(1, "2", True)
2024-08-16 23:21:20 +01:00
state._save(st._file, st._dict)
st = state.load_from_file(path)
assert st.get_user_active_in_channel(1, "2")
2024-08-11 19:02:47 +01:00
st.set_user_active_in_channel(1, "2", False)
assert not st.get_user_active_in_channel(1, "2")