Example #1
0
def test_channel_addowner_success(setup1, setup2, setup3):
    data = getData()
    reset_channels()
    ''' Creates a public channel (Admin: user1) '''
    channelsCreate1 = channels_create(setup1['token'], "Public Channel", True)
    channelId1 = channelsCreate1['channel_id']
    ''' User2 joins the channel '''
    channel_join(setup2['token'], channelId1)
    ''' Adds user2 as owner of "Public Channel" '''
    channel_addowner(setup1['token'], channelId1, setup2['u_id'])
    ''' If above line was succesful, will display user2 as an owner when calling channel_details '''
    details = channel_details(setup1['token'], channelId1)
    assert details['owner_members'] == [{
        'u_id':
        setup1['u_id'],
        'name_first':
        "Sojin",
        'name_last':
        "Nam",
        'profile_img_url':
        "https://upload.wikimedia.org/wikipedia/commons/thumb/6/66/An_up-close_picture_of_a_curious_male_domestic_shorthair_tabby_cat.jpg/440px-An_up-close_picture_of_a_curious_male_domestic_shorthair_tabby_cat.jpg"
    }, {
        'u_id':
        setup2['u_id'],
        'name_first':
        "Fairuz",
        'name_last':
        "Alam",
        'profile_img_url':
        "https://upload.wikimedia.org/wikipedia/commons/thumb/6/66/An_up-close_picture_of_a_curious_male_domestic_shorthair_tabby_cat.jpg/440px-An_up-close_picture_of_a_curious_male_domestic_shorthair_tabby_cat.jpg"
    }]
Example #2
0
def test_channel_join_no_channel(setup1, setup2, setup3):
    data = getData()
    reset_channels()
    ''' Creates a public channel (Admin: user1) '''
    channelsCreate1 = channels_create(setup1['token'], "Public Channel", True)
    channelId1 = channelsCreate1['channel_id']
    ''' Error when Channel ID does not exist '''
    with pytest.raises(ValueError_http, match=r".*"):
        channel_join(setup1['token'], -1)
Example #3
0
def channel_id1(request, reg1, reg2, reg3, reg4):
    data = getData()
    #user1 create a public channel
    channel_id_1 = channels_create(reg1['token'], 'channel1',
                                   True)['channel_id']
    #user2 joins the public channel
    channel_join(reg2['token'], channel_id_1)
    #user4 joins channel 1
    channel_join(reg4['token'], channel_id_1)
    return channel_id_1
Example #4
0
def test_channel_join_unauthorized(setup1, setup2, setup3):
    global data
    reset_channels()
    ''' Creates a private channel (Admin: user1) '''
    channelsCreate2 = channels_create(setup1['token'], "Private Channel",
                                      False)
    channelId2 = channelsCreate2['channel_id']
    ''' Error when unauthorized user joins private channel '''
    with pytest.raises(AccessError, match=r".*"):
        channel_join(setup2['token'], channelId2)
Example #5
0
def test_channel_removeowner_no_channel(setup1, setup2, setup3):
    data = getData()
    reset_channels()
    ''' Creates a public channel (Admin: user1) '''
    channelsCreate1 = channels_create(setup1['token'], "Public Channel", True)
    channelId1 = channelsCreate1['channel_id']
    ''' User2 joins the channel '''
    channel_join(setup2['token'], channelId1)
    ''' Adds user2 as owner of "Public Channel" '''
    channel_addowner(setup1['token'], channelId1, setup2['u_id'])
    ''' Error when channel does not exist '''
    with pytest.raises(ValueError_http, match=r".*"):
        channel_removeowner(setup1['token'], -1, setup2['u_id'])
Example #6
0
def test_channel_addowner_already_owner(setup1, setup2, setup3):
    data = getData()
    reset_channels()
    ''' Creates a public channel (Admin: user1) '''
    channelsCreate1 = channels_create(setup1['token'], "Public Channel", True)
    channelId1 = channelsCreate1['channel_id']
    ''' User2 joins the channel '''
    channel_join(setup2['token'], channelId1)
    ''' Adds user2 as owner of "Public Channel" '''
    channel_addowner(setup1['token'], channelId1, setup2['u_id'])
    ''' Error when trying to add owner that is already an owner '''
    with pytest.raises(ValueError_http, match=r".*"):
        channel_addowner(setup1['token'], channelId1, setup2['u_id'])
Example #7
0
def reset_data_standup():
    data = getData()
    data['users'] = []
    user1 = auth_register('*****@*****.**', 'password', 'Sally', 'name')
    user2 = auth_register('*****@*****.**', 'password', 'Bob', 'name')
    user3 = auth_register('*****@*****.**', 'password', 'Bob2', 'name')
    global channel_id
    data['channel'] = []
    for user in data['users']:
        user['joined_channels'] = []
    channel_id = 0
    ch_id = channels_create(user1['token'], 'ch1', True)['channel_id']
    channel_join(user2['token'], ch_id)
    return user1, user2, user3, ch_id
Example #8
0
def test_channel_join_success_admin(setup1, setup2, setup3):
    data = getData()
    reset_channels()
    ''' Creates a public channel (Admin: user1) '''
    channelsCreate1 = channels_create(setup1['token'], "Public Channel", True)
    channelId1 = channelsCreate1['channel_id']
    ''' Join public channel '''
    channel_join(tokenize('*****@*****.**'), channelId1)

    assert channels_list(setup1['token']) == {
        'channels': [{
            'channel_id': channelId1,
            'name': "Public Channel",
        }]
    }
Example #9
0
def test_channels_create_success_public(setup1, setup2, setup3):
    data = getData()
    reset_channels()
    ''' valid name '''
    validName1 = "validname"
    ''' Creating a public channel '''
    channelsCreate1 = channels_create(setup1['token'], validName1, True)
    channelId1 = channelsCreate1['channel_id']
    ''' Confirm that created channel is public by attempting to add unauthorized user '''
    channel_join(setup2['token'], channelId1)
    ''' If the above was successful, it will display the channel when calling channels_listall '''
    assert channels_listall(setup1['token']) == {
        'channels': [{
            'channel_id': channelId1,
            'name': validName1,
        }]
    }
Example #10
0
def test_channels_list_user2_joins(setup1, setup2, setup3):
    data = getData()
    reset_channels()
    ''' Creates a public channel (channel1) (Admin: user1) '''
    channelsCreate1 = channels_create(setup1['token'], "Public Channel", True)
    channelId1 = channelsCreate1['channel_id']

    assert channels_list(setup1['token']) == {
        'channels': [{
            'channel_id': channelId1,
            'name': 'Public Channel',
        }]
    }
    ''' User2 joins channel1 '''
    channel_join(setup2['token'], channelId1)

    assert channels_list(setup2['token']) == {
        'channels': [{
            'channel_id': channelId1,
            'name': 'Public Channel',
        }]
    }