def test_admin_userpermission_change_invalid_permission(): ''' Checks when an invalid permission is sent to admin_userpermission_change ''' with pytest.raises(ValueError, match='Permission ID is invalid'): # Initialising global_var.initialise_all() # Creating a valid user who can change permissions user = auth_register("*****@*****.**", "pass123", "Rayden", "Smith") get_user_by_u_id(user["u_id"]).permission = SLACKR_OWNER # Calling admin_userpermission_change with an invalid permission admin_userpermission_change(get_user_token_by_u_id(user["u_id"]), \ user["u_id"], -1)
def test_admin_userpermission_change_invalid_token(): ''' Checks when an invalid token is sent to admin_userpermission_change ''' with pytest.raises(AccessError, match='Invalid token'): # Initialising global_var.initialise_all() # Creating a valid user who can change permissions user = auth_register("*****@*****.**", "pass123", "Rayden", "Smith") get_user_by_u_id(user["u_id"]).permission = SLACKR_USER # Calling admin_userpermission_change with an invalid token admin_userpermission_change("invalid token", \ user["u_id"], SLACKR_ADMIN)
def test_admin_userpermission_change_user_member(): ''' Checks when an unauthorised user is sent to admin_userpermission_change ''' with pytest.raises(AccessError, \ match='Current user is not an admin or owner'): # Initialising global_var.initialise_all() # Creating a user who cannot change permissions user = auth_register("*****@*****.**", "pass123", "Rayden", "Smith") get_user_by_u_id(user["u_id"]).permission = SLACKR_USER # Calling admin_userpermission_change with a normal 'user' user admin_userpermission_change(get_user_token_by_u_id(user["u_id"]), \ user["u_id"], SLACKR_OWNER)
def admin_userpermission_change(): ''' Given a User by their user ID, set their permissions to new permissions described by permission_id ''' token = request.form.get("token") u_id = to_int(request.form.get("u_id")) permission_id = to_int(request.form.get("permission_id")) return dumps( permission.admin_userpermission_change(token, u_id, permission_id))
def test_admin_userpermission_change_user_permission_possible_permissions(): ''' Testing if it is possible to go through the entire permission set ''' # Initialising global_var.initialise_all() # Creating a valid user who can change permissions owner = auth_register("*****@*****.**", "pass123", "Rayden", "Smith") get_user_by_u_id(owner["u_id"]).permission = SLACKR_OWNER # Creating normal member user = auth_register("*****@*****.**", "pass123", "Rayden", "Smith") get_user_by_u_id(user["u_id"]).permission = SLACKR_USER # Changing normal member to admin admin_userpermission_change(get_user_token_by_u_id(owner["u_id"]), \ user["u_id"], SLACKR_ADMIN) assert get_user_by_u_id(user["u_id"]).permission == SLACKR_ADMIN # Changing admin to owner admin_userpermission_change(get_user_token_by_u_id(owner["u_id"]), \ user["u_id"], SLACKR_OWNER) assert get_user_by_u_id(user["u_id"]).permission == SLACKR_OWNER # Changing owner to member admin_userpermission_change(get_user_token_by_u_id(owner["u_id"]), \ user["u_id"], SLACKR_USER) assert get_user_by_u_id(user["u_id"]).permission == SLACKR_USER
def test_admin_userpermission_change_user_admin(): ''' Testing successful case of changing permissions by an admin of slackr ''' # Initialising global_var.initialise_all() # Creating a valid admin who can change permissions admin1 = auth_register("*****@*****.**", "pass123", "Rayden", "Smith") get_user_by_u_id(admin1["u_id"]).permission = SLACKR_ADMIN # Creating normal member user = auth_register("*****@*****.**", "pass123", "Rayden", "Smith") get_user_by_u_id(user["u_id"]).permission = SLACKR_USER # Creating another admin admin2 = auth_register("*****@*****.**", "pass123", "Rayden", "Smith") get_user_by_u_id(admin2["u_id"]).permission = SLACKR_ADMIN # Creating another owner owner = auth_register("*****@*****.**", "pass123", "Rayden", "Smith") get_user_by_u_id(owner["u_id"]).permission = SLACKR_OWNER # Admin changing permission of member admin_userpermission_change(get_user_token_by_u_id(admin1["u_id"]), \ user["u_id"], SLACKR_OWNER) assert get_user_by_u_id(user["u_id"]).permission == SLACKR_OWNER # Admin changing permission of another admin admin_userpermission_change(get_user_token_by_u_id(admin1["u_id"]), \ admin2["u_id"], SLACKR_OWNER) assert get_user_by_u_id(admin2["u_id"]).permission == SLACKR_OWNER # Admin changing permission of owner admin_userpermission_change(get_user_token_by_u_id(admin1["u_id"]), \ owner["u_id"], SLACKR_ADMIN) assert get_user_by_u_id(owner["u_id"]).permission == SLACKR_ADMIN