Пример #1
0
def test_userpermission_change_demote(
        reset, create_private_channel, make_user_cd, make_user_ef):
    '''
    Testing demoting a user restricts him to join private channels
    '''
    # creating a private channel
    channel_id, owner_info = create_private_channel
    # since owner is the first user who signs up in this
    # test, he should be a slackr owner

    # create new user
    user_info = make_user_cd

    # promoting user
    userpermission_change(owner_info['token'], user_info['u_id'], SLACKR_OWNER)

    # Inviting new user
    channel_invite(owner_info['token'],
                   channel_id['channel_id'], user_info['u_id'])

    # demoting user
    userpermission_change(owner_info['token'],
                          user_info['u_id'], SLACKR_MEMBER)

    # User leaves the channel
    channel_leave(user_info['token'], channel_id['channel_id'])

    # testing joining a private channel
    with pytest.raises(AccessError):
        channel_join(user_info['token'], channel_id['channel_id'])
Пример #2
0
def test_userpermission_change_demote_own(reset, make_user_ab):
    '''
    Testing we cannot demote ones ownself
    '''
    # creating admin
    admin_info = make_user_ab
    with pytest.raises(InputError):
        userpermission_change(
            admin_info['token'],
            admin_info['u_id'],
            SLACKR_MEMBER)
Пример #3
0
def test_userpermission_change_invalid_token(
        reset, create_public_channel, make_user_ab):
    '''
    Testing using an invalid token
    '''

    # creating a public channel
    owner_info = create_public_channel[1]
    user1 = make_user_ab
    with pytest.raises(AccessError):
        userpermission_change(
            owner_info['token'] + 'a', user1['u_id'], SLACKR_OWNER)
Пример #4
0
def u_per_change():
    '''
    A wrapper for userpermission_change
    '''
    payload = request.get_json()

    if not payload['token'] or not payload['u_id'] or not payload['permission_id']:
        raise RequestError(description=f"Missing data in request body")

    other.userpermission_change(
        payload['token'], int(payload['u_id']), int(payload['permission_id']))
    return json.dumps({})
Пример #5
0
def test_userpermission_change_invalid_u_id(
        reset, create_public_channel, make_user_ab):
    '''
    Changing permissions of a non-existent user
    '''

    # creating a public channel
    owner_info = create_public_channel[1]
    # since owner is the first user who signs up in this
    # test, he should be a slackr owner

    # giving admin permissions to a non-existent user
    with pytest.raises(InputError):
        userpermission_change(
            owner_info['token'], owner_info['u_id'] + 2, SLACKR_OWNER)
Пример #6
0
def test_userpermission_change_invalid_permission_type(
        reset, create_public_channel, make_user_ab):
    '''
    Testing changing a user's permissions to an invalid one
    '''
    # creating a public channel
    owner_info = create_public_channel[1]
    # since owner is the first user who signs up in this
    # test, he should be a slackr owner

    # create a general user
    user_info = make_user_ab

    with pytest.raises(InputError):
        userpermission_change(
            owner_info['token'], user_info['u_id'], "You should complain")
Пример #7
0
def test_userpermission_change_permission_denied(reset, create_public_channel,
                                                 make_user_ab, make_user_cd):
    '''
    Trying to change another user's permissions as a non-slackr-owner
    '''
    # creating a public channel
    create_public_channel  # pylint: disable=pointless-statement
    # since owner is the first user who signs up in this
    # test, he should be a slackr owner

    # create 2 general users
    user_ab_info = make_user_ab
    user_cd_info = make_user_cd
    # changing permissions
    with pytest.raises(AccessError):
        userpermission_change(
            user_cd_info['token'], user_ab_info['u_id'], SLACKR_OWNER)
Пример #8
0
def test_userpermission_change_promote(
        reset, create_private_channel, make_user_ab, make_user_cd):
    '''
    Testing promoting a user allows him to join private channels
    '''
    # creating a public channel
    channel_id, owner_info = create_private_channel
    # since owner is the first user who signs up in this
    # test, he should be a slackr owner

    # create a general user
    general_user = make_user_cd

    # testing joining a private channel
    try:
        channel_join(general_user['token'], channel_id['channel_id'])
        assert False
    except AccessError:
        userpermission_change(
            owner_info['token'], general_user['u_id'], SLACKR_OWNER)
        try:
            channel_join(general_user['token'], channel_id['channel_id'])
        except AccessError:
            assert False