def test_spinning(self): auth_client = tools.generate_authed_client() resp = auth_client.get("/api/spinning") tools.assure_ok_response(resp) tools.assure_bool(resp)
def test_metrics(self): resp = noauth_client.get("/api/metrics") tools.assure_ok_response(resp) # Basic sanity check assert resp.headers["content-type"] == "text/plain; charset=utf-8"
def test_post_endpoint(self): resp = tools.make_bot_request( tools.generate_guildapi_path() + "config/general", method = "POST", body = post_body ) tools.assure_ok_response(resp) tools.assure_fields_and_types(resp.json(), ["status", "modified_values"])
def test_logout(self): auth_client = tools.generate_authed_client() resp = auth_client.get("/api/logout") tools.assure_ok_response(resp) assert resp.content == successful_action_response.body # Assure that the session was cleared properly assert resp.cookies.items() == []
def test_endpoint(self): resp = tools.make_bot_request("/api/guilds/") tools.assure_ok_response(resp) for _, guild_info in resp.json().items(): # Assure the proper fields and types exist on all guilds tools.assure_fields_and_types(guild_info, ["id", "name", "permissions", "icon"]) # Make sure the permissions are in the expected range, subject to change. assert guild_info["permissions"] <= 15
def test_whoami(self): resp = tools.make_bot_request("/api/whoami") tools.assure_ok_response(resp) # Make sure all expected fields exist, and that they are the right type resp: dict = resp.json() tools.assure_fields_and_types( resp, ["username", "discrim", "avatar_url", "bot_admin_status"]) # Make sure the discriminator can always be converted into a number assert int(resp["discrim"])
def test_endpoint(self): resp = tools.make_bot_request(tools.generate_guildapi_path() + "info") tools.assure_ok_response(resp) resp: dict = resp.json() # Assure the keys are the right type # Check the top-level type of the response tools.assure_fields_and_types( resp, [ "name", "id", "server_icon", "owner", "members", "text_channels", "additional_text_channels", "voice_channels", "creation_date", "age_days", "vip_features", "role_list", "emojis", "member_statuses", "user_perms", "user_level" ] ) # Check the structures and their fields and types tools.assure_fields_and_types(resp["owner"], ["id", "name"]) tools.assure_fields(resp["member_statuses"], ["online", "idle", "dnd", "offline"]) for _, v in resp["member_statuses"].items(): assert type(v) == tools.field_types["member_statuses_count"] tools.assure_fields_and_types(resp["text_channels"], ["name", "can_log"], deep=True) tools.assure_fields_and_types(resp["additional_text_channels"], ["name", "can_log"], deep=True) tools.assure_fields_and_types( resp["role_list"], ["id", "name", "color", "members", "is_admin", "is_mod", "can_be_self_role"], deep=True ) for emoji in resp["emojis"]: tools.assure_types(emoji)
def test_patch_endpoint(self): # Test proper usage resp = tools.make_bot_request( tools.generate_guildapi_path() + "config/general", method = "PATCH", body = patch_body ) tools.assure_ok_response(resp) tools.assure_fields_and_types(resp.json(), ["status", "modified_values"]) # Test duplicate update requests resp = tools.make_bot_request( tools.generate_guildapi_path() + "config/general", method = "PATCH", body = patch_body ) assert resp.status_code == 400 tools.assure_fields_and_types(resp.json(), ["status", "errors"])
def test_generalinfo(self): resp = tools.make_bot_request("/api/general_info") tools.assure_ok_response(resp) tools.assure_fields_and_types(resp.json(), ["languages", "logging"])