예제 #1
0
def test_user_all04():
    user1 = auth.register("*****@*****.**", "test", "John", "Smith")
    user2 = auth.register("*****@*****.**", "Example", "Jhn", "Smith")
    user3 = auth.register("*****@*****.**", "Example", "Jon", "Smith")
    user4 = auth.register("*****@*****.**", "Example", "Bon", "Smoth")
    
    pub_channel = channels.create(user1['token'], 'awesomechannel', True)
    priv_channel = channels.create(user2['token'], 'notcool', False)
    
    channel.joi(user3['token'],pub_channel['channel_id'])
    channel.joi(user2['token'],priv_channel['channel_id'])

    users_dictionary = {
        'users' : [
            profile(user1['token'],user1['u_id']),
            profile(user2['token'],user2['u_id']),
            profile(user3['token'],user3['u_id']),
            profile(user4['token'],user4['u_id'])
        ]
    }
    
    assert all_(user1['token']) == users_dictionary
    assert all_(user2['token']) == users_dictionary
    assert all_(user3['token']) == users_dictionary
    assert all_(user4['token']) == users_dictionary
예제 #2
0
def test_remove_unauthorised_not_admin():
    testData = create_data(1)
    testData2 = create_data(2)

    joi(testData2[0]['token'], testData[1]['channel_id'])
    # testData sent the message and is admin
    testMessage = send(testData2[0]['token'], testData[1]['channel_id'],
                       "Message")
    # testData sent the message and testData is the owner/admin of BOTH the slackr and the channel so testData 2 shouldn't be able to remove
    with pytest.raises(AccessError):
        remove(testData2[0]['token'], testMessage)
예제 #3
0
def test_edit_unauthorised_not_admin():
    testData = create_data(1)
    testData2 = create_data(2)

    joi(testData2[0]['token'], testData[1]['channel_id'])

    # The user of testData sent the message and is admin
    testMessage = send(testData2[0]['token'], testData[1]['channel_id'],
                       "Message")
    # The user of testData sent the message and testData is the owner/admin so testData 2 shouldn't be able to remove
    with pytest.raises(AccessError):
        edit(testData2[0]['token'], testMessage, "newMessage")
예제 #4
0
def bot_join(channel_id):
    '''
    Input - channel_id

    Joins a channel directly as a bot.
    No message is shown upon joining.
    '''
    # join a channel as a bot.
    # NOTE: cannot join private channels.
    for channel in all_channels:
        if channel["channel_id"] == channel_id:
            bot_id = discrete.find_uid("*****@*****.**")
            token_bot = common.encode_token({"u_id": bot_id})
            joi(token_bot, channel_id)
예제 #5
0
def test_edit_authorised_not_admin():
    testData = create_data(1)
    testData2 = create_data(2)

    joi(testData2[0]['token'], testData[1]['channel_id'])

    # The user of testData2 sent the message; but is not an admin
    testMessage = send(testData2[0]['token'], testData[1]['channel_id'],
                       "Message")

    # The user of testData2 should still be able to edit the message
    result = edit(testData2[0]['token'], testMessage, "new msg")
    assert type(result) is dict
    assert result == {}
예제 #6
0
def test_edit_unauthorised_admin():
    #C reate 1 admin of channel and 1 member of channel
    testData = create_data(1)
    testData2 = create_data(2)
    # The user of testData is owner

    joi(testData2[0]['token'], testData[1]['channel_id'])
    testMessage = send(testData2[0]['token'], testData[1]['channel_id'],
                       "Test")

    # The user of testData2 sent the message but testData is the owner/admin so should be able to edit
    result = edit(testData[0]['token'], testMessage, "newmessage")
    assert type(result) is dict
    assert result == {}
예제 #7
0
def test_remove_authorised_not_admin():
    testData = create_data(1)
    testData2 = create_data(2)

    joi(testData2[0]['token'], testData[1]['channel_id'])

    # The user of testData2 sent the message; but is not an admin (did not joi the channel first - see assumptions)
    testMessage = send(testData2[0]['token'], testData[1]['channel_id'],
                       "Message")

    # The user of testData2 should still be able to remove the message
    result = remove(testData2[0]['token'], testMessage)
    assert type(result) is dict
    assert result == {}
예제 #8
0
def test_remove_unauthorised_admin():
    # Create 1 admin of channel and 1 member of channel
    testData = create_data(1)
    testData2 = create_data(2)
    # The user of testData is owner (joied first - see assumptions)

    joi(testData2[0]['token'], testData[1]['channel_id'])
    testMessage = send(testData2[0]['token'], testData[1]['channel_id'],
                       "Test")

    # The user of testData2 sent the message but testData is the owner/admin of †he channel so should be able to remove
    result = remove(testData[0]['token'], testMessage)
    assert type(result) is dict
    assert result == {}
예제 #9
0
def test_chjn02(validUser, owner):

    # Non-member attempting to join a private channel
    with pt.raises(AccessError):
        ch.joi(validUser.details2["token"], owner.priv_channel["channel_id"])
예제 #10
0
def test_chjn01(validUser, owner):
    with pt.raises(InputError):
        ch.joi(owner.details["token"], "INVALID_CHANNEL_ID")
예제 #11
0
def test_chjn00(validUser, owner):
    assert ch.joi(validUser.details["token"],
                  owner.real_channel["channel_id"]) == {}

    ch.lev(validUser.details["token"], owner.real_channel["channel_id"])
예제 #12
0
def ch_joi():
    data = request.get_json()
    return dumps(ch.joi(data["token"], int(data["channel_id"])))