async def test_save_to_dict_with_plugin(self, create_handler: AntiSpamHandler): await create_handler.cache.set_guild(Guild(1, Options())) class Plugin(BasePlugin): async def save_to_dict(self): return {"Plugin me"} create_handler.register_plugin(Plugin()) data = await create_handler.save_to_dict() with open("tests/raw.json", "r") as file: stored_data = json.load(file) stored_data["pre_invoke_plugins"]["Plugin"] = {"Plugin me"} assert data == stored_data create_handler.unregister_plugin("Plugin") create_handler.register_plugin(Plugin(is_pre_invoke=False)) stored_data["pre_invoke_plugins"] = {} stored_data["after_invoke_plugins"]["Plugin"] = {"Plugin me"} data_two = await create_handler.save_to_dict() assert data_two == stored_data
def test_unregister_extension(self, create_handler: AntiSpamHandler): class Test(BasePlugin): def __init__(self, invoke=True): self.is_pre_invoke = invoke create_handler.register_plugin(Test(invoke=False)) assert len(create_handler.after_invoke_extensions.values()) == 1 create_handler.unregister_plugin("Test") assert len(create_handler.after_invoke_extensions.values()) == 0 with pytest.raises(PluginError): create_handler.unregister_plugin("Invalid Extension") create_handler.register_plugin(Test()) assert len(create_handler.pre_invoke_plugins.values()) == 1 create_handler.unregister_plugin("Test") assert len(create_handler.pre_invoke_plugins.values()) == 0