Protect against discovered miss-use of state
This commit is contained in:
parent
87a0c8f4b6
commit
f2d7e1d490
3 changed files with 6 additions and 6 deletions
|
@ -96,7 +96,7 @@ def members_to_groups_validate(matchees: list[Member], tmp_state: state.State, p
|
||||||
], ids=['single', "larger_groups", "100_members", "5_group", "pairs", "356_big_groups"])
|
], ids=['single', "larger_groups", "100_members", "5_group", "pairs", "356_big_groups"])
|
||||||
def test_members_to_groups_no_history(matchees, per_group):
|
def test_members_to_groups_no_history(matchees, per_group):
|
||||||
"""Test simple group matching works"""
|
"""Test simple group matching works"""
|
||||||
tmp_state = state.State()
|
tmp_state = state.State(state._EMPTY_DICT)
|
||||||
members_to_groups_validate(matchees, tmp_state, per_group)
|
members_to_groups_validate(matchees, tmp_state, per_group)
|
||||||
|
|
||||||
|
|
||||||
|
@ -328,7 +328,7 @@ def items_found_in_lists(list_of_lists, items):
|
||||||
], ids=['simple_history', 'fallback', 'example_1', 'example_2', 'example_3'])
|
], ids=['simple_history', 'fallback', 'example_1', 'example_2', 'example_3'])
|
||||||
def test_unique_regressions(history_data, matchees, per_group, checks):
|
def test_unique_regressions(history_data, matchees, per_group, checks):
|
||||||
"""Test a bunch of unqiue failures that happened in the past"""
|
"""Test a bunch of unqiue failures that happened in the past"""
|
||||||
tmp_state = state.State()
|
tmp_state = state.State(state._EMPTY_DICT)
|
||||||
|
|
||||||
# Replay the history
|
# Replay the history
|
||||||
for d in history_data:
|
for d in history_data:
|
||||||
|
@ -380,7 +380,7 @@ def test_stess_random_groups(per_group, num_members, num_history):
|
||||||
member.roles = [Role(i) for i in rand.sample(range(1, 8), 3)]
|
member.roles = [Role(i) for i in rand.sample(range(1, 8), 3)]
|
||||||
|
|
||||||
# For each history item match up groups and log those
|
# For each history item match up groups and log those
|
||||||
cumulative_state = state.State()
|
cumulative_state = state.State(state._EMPTY_DICT)
|
||||||
for i in range(num_history+1):
|
for i in range(num_history+1):
|
||||||
|
|
||||||
# Grab the num of members and replay
|
# Grab the num of members and replay
|
||||||
|
@ -394,7 +394,7 @@ def test_stess_random_groups(per_group, num_members, num_history):
|
||||||
|
|
||||||
|
|
||||||
def test_auth_scopes():
|
def test_auth_scopes():
|
||||||
tmp_state = state.State()
|
tmp_state = state.State(state._EMPTY_DICT)
|
||||||
|
|
||||||
id = "1"
|
id = "1"
|
||||||
assert not tmp_state.get_user_has_scope(id, state.AuthScope.MATCHER)
|
assert not tmp_state.get_user_has_scope(id, state.AuthScope.MATCHER)
|
||||||
|
|
|
@ -20,7 +20,7 @@ async def bot():
|
||||||
b = commands.Bot(command_prefix="$",
|
b = commands.Bot(command_prefix="$",
|
||||||
intents=intents)
|
intents=intents)
|
||||||
await b._async_setup_hook()
|
await b._async_setup_hook()
|
||||||
await b.add_cog(OwnerCog(b, state.State()))
|
await b.add_cog(OwnerCog(b, state.State(state._EMPTY_DICT)))
|
||||||
dpytest.configure(b)
|
dpytest.configure(b)
|
||||||
yield b
|
yield b
|
||||||
await dpytest.empty_queue()
|
await dpytest.empty_queue()
|
||||||
|
|
|
@ -174,7 +174,7 @@ def datetime_to_ts(ts: datetime) -> str:
|
||||||
|
|
||||||
|
|
||||||
class State():
|
class State():
|
||||||
def __init__(self, data: dict = _EMPTY_DICT):
|
def __init__(self, data: dict):
|
||||||
"""Initialise and validate the state"""
|
"""Initialise and validate the state"""
|
||||||
self.validate(data)
|
self.validate(data)
|
||||||
self._dict = copy.deepcopy(data)
|
self._dict = copy.deepcopy(data)
|
||||||
|
|
Loading…
Add table
Reference in a new issue