コード例 #1
0
def test_channels_create():
    reset_data()
    # SETUP BEGIN
    # Assume all users have registered in function: test_channel_invite()
    auth_dic1 = auth_register("*****@*****.**", "123456", "firstone",
                              "lastone")
    auth_dic1 = auth_login("*****@*****.**", "123456")
    token1 = auth_dic1['token']

    auth_dic2 = auth_register("*****@*****.**", "123456", "firstone",
                              "lastone")
    auth_dic2 = auth_login("*****@*****.**", "123456")
    token2 = auth_dic2['token']
    # SETUP END

    # successful test
    # assume the channelid is 1
    assert channels_create(token1, "channel 1", True) == {'channel_id': 0}

    with pytest.raises(ValueError):
        # Name is more than 20 characters long
        channels_create(token1, "qwertyuiopasdfghjklzxcvbnmqwertyuiop", True)

    # logout
    auth_logout(token1)
    auth_logout(token2)

    reset_data()
コード例 #2
0
def test_message_send():
    reset_data()
    # SETUP BEGIN
    authRegisterDict1 = auth_register('*****@*****.**', '123456', 'hayden',
                                      'Diego')
    auth_login('*****@*****.**', '123456')
    token1 = authRegisterDict1['token']
    authRegisterDict2 = auth_register('*****@*****.**', '123456', 'sally',
                                      'Juan')
    auth_login('*****@*****.**', '123456')
    token2 = authRegisterDict2['token']

    channelidDict1 = channels_create(token1, 'channel_1', True)
    channel_id1 = channelidDict1['channel_id']
    channelidDict2 = channels_create(token2, 'channel_8', True)
    channel_id2 = channelidDict2['channel_id']
    # SETUP END

    # The right example
    message_send(token1, channel_id1, 'hello')

    # error test
    with pytest.raises(ValueError):
        # Message is more than 1000 characters
        message_send(token1, channel_id1, 'a' * 1001)

    with pytest.raises(AccessError):
        # token1 has not joined Channel channel_id2
        message_send(token1, channel_id2, 'hello')

    # logout
    auth_logout(token1)
    auth_logout(token2)
    reset_data()
コード例 #3
0
def test_channels_listall():
    reset_data()
    # SETUP BEGIN
    # Assume all users have registered in function: test_channel_invite()
    auth_dic1 = auth_register("*****@*****.**", "123456", "firstone", "lastone")
    auth_dic1 = auth_login("*****@*****.**", "123456")
    token1 = auth_dic1['token']

    auth_dic2 = auth_register("*****@*****.**", "123456", "firstone", "lastone")
    auth_dic2 = auth_login("*****@*****.**", "123456")
    token2 = auth_dic2['token']

    channels_create(token1, "channel 1", True)

    # SETUP END

    # successful test
    # because it output all channel, whatever the user is, the output should be same

    assert channels_listall(token1) == channels_listall(token2)  # just for check

    # logout
    auth_logout(token1)
    auth_logout(token2)

    reset_data()
コード例 #4
0
def test_channels_list():
    reset_data()
    # SETUP BEGIN
    # Assume all users have registered in function: test_channel_invite()
    auth_dic1 = auth_register("*****@*****.**", "123456", "firstone",
                              "lastone")
    auth_dic1 = auth_login("*****@*****.**", "123456")
    token1 = auth_dic1['token']

    auth_dic2 = auth_register("*****@*****.**", "123456", "firstone",
                              "lastone")
    auth_dic2 = auth_login("*****@*****.**", "123456")
    token2 = auth_dic2['token']

    channels_create(token1, "channel 1", True)

    # SETUP END

    # successful test
    channels_list(token1)
    assert channels_list(token2) == {'channels': []}

    # logout
    auth_logout(token1)
    auth_logout(token2)

    reset_data()
コード例 #5
0
def test_channel_invite():
    reset_data()
    # SETUP BEGIN
    auth_dic1 = auth_register("*****@*****.**", "123456", "firstone",
                              "lastone")
    auth_dic1 = auth_login("*****@*****.**", "123456")
    token1 = auth_dic1['token']
    uid1 = auth_dic1['u_id']

    auth_dic2 = auth_register("*****@*****.**", "123456", "firstone",
                              "lastone")
    auth_dic2 = auth_login("*****@*****.**", "123456")
    token2 = auth_dic2['token']
    uid2 = auth_dic2['u_id']

    auth_dic3 = auth_register("*****@*****.**", "123456", "firstone",
                              "lastone")
    auth_dic3 = auth_login("*****@*****.**", "123456")
    token3 = auth_dic3['token']

    channelid_dic1 = channels_create(token1, "channel 1", True)
    channel_id1 = channelid_dic1['channel_id']

    channelid_dic2 = channels_create(token1, "channel 2", True)
    channel_id2 = channelid_dic2['channel_id']
    # SETUP END

    # successful test
    assert channel_invite(token1, channel_id1, uid2) == {}

    # error test
    with pytest.raises(ValueError):
        # the channel if does not exist
        channel_invite(token1, 10, uid2)

    with pytest.raises(AccessError):
        # channel_id does not refer to a valid channel that the authorised user is part of.
        channel_invite(token3, channel_id2, uid2)

    with pytest.raises(ValueError):
        # u_id does not refer to a valid user
        # assume u_id 5 does not refer to a valid user
        channel_invite(token1, channel_id1, 10)

    with pytest.raises(ValueError):
        # u_id does not refer to a valid user
        # invite the user that is in channel (by calling function above, uid2 is in channel)
        channel_invite(token2, channel_id1, uid1)

    # logout
    auth_logout(token1)
    auth_logout(token2)
    auth_logout(token3)

    reset_data()
コード例 #6
0
def test_message_sendlater():
    reset_data()
    # SETUP BEGIN
    authRegisterDict1 = auth_register('*****@*****.**', '123456', 'hayden',
                                      'Diego')
    auth_login('*****@*****.**', '123456')
    token1 = authRegisterDict1['token']
    authRegisterDict2 = auth_register('*****@*****.**', '123456', 'sally',
                                      'Juan')
    auth_login('*****@*****.**', '123456')
    token2 = authRegisterDict2['token']

    channelidDict1 = channels_create(token1, 'channel_1', True)
    channel_id1 = channelidDict1['channel_id']
    channelidDict2 = channels_create(token2, 'channel_8', True)
    channel_id2 = channelidDict2['channel_id']
    # SETUP END

    # The right example
    '''
    later_time = datetime.datetime.utcnow() + datetime.timedelta(seconds=50)
    str_later_time = later_time.strftime("%Y-%m-%d %H:%M:%S")
    timeArray = time.strptime(str_later_time, "%Y-%m-%d %H:%M:%S")
    timestamp = time.mktime(timeArray)
    print(timestamp)
    '''
    timestamp = int(datetime.datetime.now().strftime("%s")) + 3
    mid = message_sendlater(token1, channel_id1, 'hello', timestamp)
    assert mid['message_id'] == 1

    # error example
    with pytest.raises(ValueError):
        # Message is more than 1000 characters
        message_sendlater(token1, channel_id1, 'a' * 1001, 1603066156)

    with pytest.raises(ValueError):
        # Assume Channel channel_id 3 does not exist (not valid channel)
        message_sendlater(token1, 3, 'hello', 1603066156)

    with pytest.raises(ValueError):
        # Assume Time 2018-10-01 00:09:06 is a time in the past (1538352546 in Timestamp)
        message_sendlater(token1, channel_id1, 'hello', 1538352546)

    with pytest.raises(AccessError):
        # token1 has not joined Channel channel_id2
        message_sendlater(token1, channel_id2, 'hello', 1603066156)

    # logout
    auth_logout(token1)
    auth_logout(token2)
    reset_data()
コード例 #7
0
def test_standup_active():
    reset_data()
    #SETUP Begin
    authRegDict1 = auth_register("*****@*****.**", "qwerty", "John", "Smith")
    token1 = authRegDict1['token']
    channelCreateDict1 = channels_create(token1, 'New Channel', True)
    channel_id1 = channelCreateDict1['channel_id']

    authRegDict2 = auth_register("*****@*****.**", "asdfgh", "Jim", "Smith")
    token2 = authRegDict2['token']


    assert standup_active(token1, channel_id1) == {'is_active' : False, 'time_finish' : None}
    standup_start(token1, channel_id1, 5)
    standup_dic = standup_active(token1, channel_id1)
    assert standup_dic['is_active']

    with pytest.raises(ValueError):
        standup_active(token1, 10)

    with pytest.raises(AccessError):
        standup_active(token2, channel_id1)

    auth_logout(token1)
    auth_logout(token2)
コード例 #8
0
def test_message_unpin():
    reset_data()
    # SETUP BEGIN
    authRegisterDict1 = auth_register('*****@*****.**', '123456', 'hayden',
                                      'Diego')
    auth_login('*****@*****.**', '123456')
    token1 = authRegisterDict1['token']
    authRegisterDict2 = auth_register('*****@*****.**', '123456', 'sally',
                                      'Juan')
    auth_login('*****@*****.**', '123456')
    token2 = authRegisterDict2['token']
    authRegisterDict3 = auth_register('*****@*****.**', '123456', 'Nena',
                                      'Smith')
    auth_login('*****@*****.**', '123456')
    token3 = authRegisterDict3['token']
    authRegisterDict4 = auth_register('*****@*****.**', '123456', 'Carmen',
                                      'Davis')
    auth_login('*****@*****.**', '123456')
    token4 = authRegisterDict4['token']

    channelidDict1 = channels_create(token1, 'channel_1', True)
    channel_id1 = channelidDict1['channel_id']

    channel_join(token2, channel_id1)

    messages_dic1 = message_send(token1, channel_id1, "hello")
    message_id1 = messages_dic1['message_id']

    messagedic2 = message_send(token1, channel_id1, "helloooo")
    message_id2 = messagedic2['message_id']

    message_pin(token1, message_id1)
    message_pin(token1, message_id2)
    # SETUP END

    # The right example
    assert message_unpin(token1, message_id1) == {}

    with pytest.raises(ValueError):
        # message_id 8 is not a valid message
        message_unpin(token1, 8)

    with pytest.raises(ValueError):
        # The authorised user token2 is not an admin
        message_unpin(token2, message_id2)

    with pytest.raises(ValueError):
        # Message message_1 is already unpinned
        message_unpin(token1, message_id1)

    with pytest.raises(AccessError):
        # The authorised user is not a member of the channel that the message is within
        message_unpin(token3, message_id2)

    # logout
    auth_logout(token1)
    auth_logout(token2)
    auth_logout(token3)
    auth_logout(token4)
    reset_data()
コード例 #9
0
def test_search():
    '''
    assumption:
        [email protected] is the only registered email for now.
        2.all the value errors have been modified into specfic words.
        3.the channel called "channelname" hasn't been created
    '''

    #successful test:
    #login
    reset_data()
    auth_register('*****@*****.**', 'q1w2e3r4', 'BEAR', 'XI')
    login1_dic = auth_login('*****@*****.**', 'q1w2e3r4')
    token = login1_dic['token']
    #create a channel
    channelValue = channels_create(token, "channelname", True)
    channel_id = channelValue['channel_id']
    #sending a message
    message_send(token, channel_id, "1q2w3e4r")
    #search
    messages_dic = search(token, "1q")
    assert messages_dic['messages'][0]['message'] == "1q2w3e4r"
    #logout
    auth_logout(token)
    reset_data()
コード例 #10
0
def test1():
    restart()
    authRegisterDict1 = auth_register("*****@*****.**", "123456",
                                      "Tim", "Hu")
    token1 = authRegisterDict1["token"]
    UID1 = authRegisterDict1['u_id']
    authRegisterDict2 = auth_register("*****@*****.**", "1we33456",
                                      "Hayden", "Smith")
    token2 = authRegisterDict2["token"]
    UID2 = authRegisterDict2['u_id']
    authRegisterDict3 = auth_register("*****@*****.**", "1we33ee456",
                                      "Jeff", "Lu")
    token3 = authRegisterDict3["token"]

    UID3 = authRegisterDict3['u_id']

    authRegisterDict4 = auth_register("*****@*****.**", "jijijij37236",
                                      'daniel', 'quin')
    token4 = authRegisterDict4["token"]

    UID4 = authRegisterDict4['u_id']
    channel_id = channels_create(token1, 'test1', True)
    channel_invite(token1, channel_id, UID2)
    channel_invite(token1, channel_id, UID3)
    message_send(token1, channel_id, 'hello')
    message_send(token2, channel_id, 'hi')
    message_send(token3, channel_id, 'numb')
    result = search(token1, 'hello')
    assert result['messages'][0]['message'] == 'hello'
    assert result['messages'][0]['message_id'] == 1
コード例 #11
0
def test_message_edit():
    reset_data()
    # SETUP BEGIN
    authRegisterDict1 = auth_register('*****@*****.**', '123456', 'hayden',
                                      'Diego')
    auth_login('*****@*****.**', '123456')
    token1 = authRegisterDict1['token']
    authRegisterDict2 = auth_register('*****@*****.**', '123456', 'sally',
                                      'Juan')
    auth_login('*****@*****.**', '123456')
    token2 = authRegisterDict2['token']
    authRegisterDict3 = auth_register('*****@*****.**', '123456', 'Nena',
                                      'Smith')
    auth_login('*****@*****.**', '123456')
    token3 = authRegisterDict3['token']
    authRegisterDict4 = auth_register('*****@*****.**', '123456', 'Carmen',
                                      'Davis')
    auth_login('*****@*****.**', '123456')
    token4 = authRegisterDict4['token']

    channelidDict1 = channels_create(token1, 'channel_1', True)
    channel_id1 = channelidDict1['channel_id']

    channel_join(token2, channel_id1)

    messages_dic1 = message_send(token1, channel_id1, "hello")
    message_id1 = messages_dic1['message_id']
    # SETUP END

    # The right example
    # Assume the message id 1 is a valid id for user1
    assert message_edit(token1, message_id1, 'hello') == {}

    with pytest.raises(ValueError):
        # Assume Message id 2 does not exist
        message_edit(token1, 10, 'hello')

    with pytest.raises(ValueError):
        # Message is more than 1000 characters
        message_edit(token1, message_id1, 'a' * 1001)

    with pytest.raises(AccessError):
        # message_id1 was not sent by the authorised user token2 making this request
        message_edit(token2, message_id1, 'hello')

    with pytest.raises(AccessError):
        # token3 is not an owner of this channel
        message_edit(token3, message_id1, 'hello')

    with pytest.raises(AccessError):
        # token4 is not an admin or owner of the slack
        message_edit(token4, message_id1, 'hello')

    # logout
    auth_logout(token1)
    auth_logout(token2)
    auth_logout(token3)
    auth_logout(token4)
    reset_data()
コード例 #12
0
def test_channel_join():
    reset_data()
    # SETUP BEGIN
    # Assume all users have registered in function: test_channel_invite()
    auth_dic1 = auth_register("*****@*****.**", "123456", "firstone",
                              "lastone")
    auth_dic1 = auth_login("*****@*****.**", "123456")
    token1 = auth_dic1['token']

    auth_dic2 = auth_register("*****@*****.**", "123456", "firstone",
                              "lastone")
    auth_dic2 = auth_login("*****@*****.**", "123456")
    token2 = auth_dic2['token']

    channelid_dic1 = channels_create(token1, "channel 1", True)
    channel_id1 = channelid_dic1['channel_id']

    # create a private channel
    channelid_dic2 = channels_create(token1, "channel 2", False)
    channel_id2 = channelid_dic2['channel_id']

    # SETUP END

    # successful test
    assert channel_join(token2, channel_id1) == {}

    # error test
    with pytest.raises(ValueError):
        # Channel (based on ID) does not exist
        # assume channel id 3 does not exist
        channel_join(token1, 10)

    with pytest.raises(ValueError):
        # if token is already a member in this channel
        channel_join(token2, channel_id1)

    with pytest.raises(AccessError):
        # channel_id refers to a channel that is private (when the authorised user is not an admin)
        channel_join(token2, channel_id2)

    # logout
    auth_logout(token1)
    auth_logout(token2)

    reset_data()
コード例 #13
0
def test_active():
    restart()
    authRegisterDict1 = auth_register("*****@*****.**","123456","Tim","Hu")
    token1 = authRegisterDict1["token"]
    channel_id = channels_create(token1,'test1',True)
    standup_start(token1,channel_id, 20)
    standup_active(token1, 1)
    with pytest.raises(ValueError, match=r'.*'):
        standup_active(token1, -5)
コード例 #14
0
def test_standup_send():
    reset_data()
    #SETUP Begin
    authRegDict1 = auth_register("*****@*****.**", "qwerty", "John", "Smith")
    token1 = authRegDict1['token']
    channelCreateDict1 = channels_create(token1, 'New Channel', True)
    channel_id1 = channelCreateDict1['channel_id']

    authRegDict2 = auth_register("*****@*****.**", "asdfgh", "Jim", "Smith")
    token2 = authRegDict2['token']

    channelCreateDict2 = channels_create(token2, 'New Channel2', True)
    channel_id2 = channelCreateDict2['channel_id']

    standup_start(token1, channel_id1, 7)
    #User 2 has not joined the 'New Channel' created by user 1
    #SETUP End

    #Test Case 1: Successful message sent to get bufferred in the standup queue
    assert standup_send(token1, channel_id1, 'Hello') == {}

    #Test Case 2: Unsuccessful message due to channel not existing
    with pytest.raises(ValueError):
        standup_send(
            token1, 10,
            'Hello')  #Invalid channel ID hence the unsuccessful message

    #Test Case 3: Unsuccessful message due to message being more than 1000 characters
    with pytest.raises(ValueError):
        standup_send(token1, channel_id1, 'a' * 1001)

    #Test Case 4: Unsuccessful message due to user not being a member of the channel
    with pytest.raises(AccessError):
        #user 2 has not joined the channel created by user 1 so the message is Unsuccessful
        standup_send(token2, channel_id1, 'Hello')

    #Test Case 5: Unsuccessful standup message due to standup not being active
    with pytest.raises(ValueError):
        standup_send(token2, channel_id2, 'Hello')

    auth_logout(token1)
    auth_logout(token2)

    reset_data()
コード例 #15
0
def test_standup_all():
    restart()
    authRegisterDict1 = auth_register("*****@*****.**","123456","Tim","Hu")
    token1 = authRegisterDict1["token"]
    authRegisterDict2 = auth_register("*****@*****.**","1we33456","Hayden","Smith")
    token2 = authRegisterDict2["token"]
    UID2 = authRegisterDict2['u_id']
    authRegisterDict3 = auth_register(
        "*****@*****.**", "1we33ee456", "Jeff", "Lu")
    token3 = authRegisterDict3["token"]
    
    UID3 = authRegisterDict3['u_id']

    authRegisterDict4 = auth_register(
        "*****@*****.**", "jijijij37236", 'daniel', 'quin')
    token4 = authRegisterDict4["token"]
    
    channel_id = channels_create(token1,'test1',True)
    channel_invite(token1,channel_id,UID2)
    channel_invite(token1,channel_id,UID3)

    showtime(20)

    with pytest.raises(ValueError, match=r".*"):
        standup_send(token2, channel_id, 'hello')

    standup_start(token1,channel_id, 20)
    
    with pytest.raises(ValueError, match = r".*"):
        standup_start(token2, channel_id, 20)

    with pytest.raises(AccessError, match=r".*"):
        standup_start(token4,channel_id, 20)
        
    with pytest.raises(ValueError,match = r".*"):
        standup_start(token1,-1, 20)

    with pytest.raises(AccessError, match=r".*"):
        standup_send(token4, channel_id , 'hello')

    with pytest.raises(ValueError, match=r".*"):
        standup_send(token1, -1 , 'hello')

    with pytest.raises(ValueError, match=r".*"):
        standup_send(token3, channel_id, "dhbfuyawgefdahdhbfuyawgefdahsgfhiashfuihasfnrweiauehcyaacweynugirnnnnnnnnnnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnfnnnnnnnnnnnnnnnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfaecntyvufyyyyyyyyyyyyyyyfyfyfygyyywyyyyyyyyyyyyyyywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywydhbfuyawgefdahsgfhiashfuihasfnrweiauehcyaacweynugirnnnnnnnnnnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnfnnnnnnnnnnnnnnnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfaecntyvufyyyyyyyyyyyyyyyfyfyfygyyywyyyyyyyyyyyyyyywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywydhbfuyawgefdahsgfhiashfuihasfnrweiauehcyaacweynugirnnnnnnnnnnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnfnnnnnnnnnnnnnnnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfaecntyvufyyyyyyyyyyyyyyyfyfyfygyyywyyyyyyyyyyyyyyywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywyywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywyywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywyysgfhiashfuihasfnrweiauehcyaacweynugirnnnnnnnnnnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnrnfnnnnnnnnnnnnnnnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfnfaecntyvufyyyyyyyyyyyyyyyfyfyfygyyywyyyyyyyyyyyyyyywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywywyy")

    standup_send(token2,channel_id, 'hello')
    standup_send(token3,channel_id,'daniel')
    standup_send(token2,channel_id, 'quin' )
    channelDict = load()['channelDict']
    for ch in channelDict:
        if int(channel_id) == ch['channel_id']:
            assert 'hayden: hello' + '\r\n' + 'jeff: daniel' + '\r\n' + 'hayden: quin' == ch['standlist']
    pass
コード例 #16
0
def run_channels_create():
    """
    Run the channels_create function to make a new channel and
    add it to the  server database
    """
    request_data = request.form
    return_value = channel.channels_create(request_data["token"],
                                           request_data["name"],
                                           request_data["is_public"] == 'true')

    return dumps(return_value)
コード例 #17
0
def test_message_react():
    reset_data()

    # SETUP BEGIN
    authRegisterDict1 = auth_register('*****@*****.**', '123456', 'hayden', 'Diego')
    auth_login('*****@*****.**', '123456')
    token1 = authRegisterDict1['token']
    authRegisterDict2 = auth_register('*****@*****.**', '123456', 'sally', 'Juan')
    auth_login('*****@*****.**', '123456')
    token2 = authRegisterDict2['token']
    authRegisterDict3 = auth_register('*****@*****.**', '123456', 'Nena', 'Smith')
    auth_login('*****@*****.**', '123456')
    token3 = authRegisterDict3['token']
    authRegisterDict4 = auth_register('*****@*****.**', '123456', 'Carmen', 'Davis')
    auth_login('*****@*****.**', '123456')
    token4 = authRegisterDict4['token']

    channelidDict1 = channels_create(token1, 'channel_1', True)
    channel_id1 = channelidDict1['channel_id']

    channel_join(token2, channel_id1)

    messages_dic1 = message_send(token1, channel_id1, "hello")
    message_id1 = messages_dic1['message_id']

    # SETUP END

    # The right example
    # message_id1 is a valid message for user1
    # assume the react id 1 is a valid id
    assert message_react(token1, message_id1, 1) == {}

    # error example
    with pytest.raises(ValueError):
        # assume message_id 2 is not a valid message
        message_react(token1, 2, 1)

    with pytest.raises(ValueError):
        # assume react_id id 3 is not a valid React ID
        message_react(token1, message_id1, 3)

    with pytest.raises(ValueError):
        # message_id 1 already contains an active React with react_id 1
        message_react(token1, message_id1, 1)

    with pytest.raises(ValueError):
        # user3 is not a member of channel which contain messageid1
        message_react(token3, message_id1, 1)

    # logout
    auth_logout(token1)
    auth_logout(token2)
    auth_logout(token3)
    auth_logout(token4)
コード例 #18
0
def test_channel_messages():
    reset_data()
    # SETUP BEGIN
    # Assume all users have registered in function: test_channel_invite()
    auth_dic1 = auth_register("*****@*****.**", "123456", "firstone",
                              "lastone")
    auth_dic1 = auth_login("*****@*****.**", "123456")
    token1 = auth_dic1['token']

    auth_dic2 = auth_register("*****@*****.**", "123456", "firstone",
                              "lastone")
    auth_dic2 = auth_login("*****@*****.**", "123456")
    token2 = auth_dic2['token']

    channelid_dic1 = channels_create(token1, "channel 1", True)
    channel_id1 = channelid_dic1['channel_id']

    # SETUP END

    # successful test
    # assume the total number of messages in the channel is 0
    # which means there is no message in the channel
    # assume the start number is 0

    # send a message to channel1
    message_send(token1, channel_id1, "hello")
    channel_messages(token1, channel_id1, 0)

    # error test
    with pytest.raises(ValueError):
        # Channel (based on ID) does not exist
        # assume the channel ID 2 does not exist
        channel_messages(token1, 10, 0)

    with pytest.raises(ValueError):
        # start is greater than the total number of messages in the channel
        # the total number of messages is 1, start is 2
        channel_messages(token1, channel_id1, 2)

    with pytest.raises(AccessError):
        # Authorised user is not a member of channel with channel_id
        channel_messages(token2, channel_id1, 0)

    # logout
    auth_logout(token1)
    auth_logout(token2)
    reset_data()
コード例 #19
0
def test_channel_leave():
    reset_data()
    # SETUP BEGIN
    # Assume all users have registered in function: test_channel_invite()
    auth_dic1 = auth_register("*****@*****.**", "123456", "firstone",
                              "lastone")
    auth_dic1 = auth_login("*****@*****.**", "123456")
    token1 = auth_dic1['token']

    auth_dic2 = auth_register("*****@*****.**", "123456", "firstone",
                              "lastone")
    auth_dic2 = auth_login("*****@*****.**", "123456")
    token2 = auth_dic2['token']

    channelid_dic1 = channels_create(token1, "channel 1", True)
    channel_id1 = channelid_dic1['channel_id']

    channel_join(token2, channel_id1)
    # SETUP END

    # successful test
    assert channel_leave(token2, channel_id1) == {}

    # error test
    with pytest.raises(AccessError):
        # if the user is not a member of channel with channel id
        channel_leave(token2, channel_id1)

    # assume if no one in the channel, the channel will does not exist
    with pytest.raises(ValueError):
        # Channel (based on ID) does not exist
        channel_leave(token1, 10)

    # if there is only one owner in the channel, cannot remove
    with pytest.raises(ValueError):
        channel_leave(token1, channel_id1)

    # logout
    auth_logout(token1)
    auth_logout(token2)

    reset_data()
コード例 #20
0
def test_channel_details():
    reset_data()
    # SETUP BEGIN
    # Assume all users have registered in function: test_channel_invite()
    auth_dic1 = auth_register("*****@*****.**", "123456", "firstone", "lastone")
    auth_dic1 = auth_login("*****@*****.**", "123456")
    token1 = auth_dic1['token']

    auth_dic2 = auth_register("*****@*****.**", "123456", "firstone", "lastone")
    auth_dic2 = auth_login("*****@*****.**", "123456")
    token2 = auth_dic2['token']

    channelid_dic1 = channels_create(token1, "channel 1", True)
    channel_id1 = channelid_dic1['channel_id']

    # SETUP END

    # successful test
    # assume channel_details function return the channel name
    # and the uid of the owner_members/members
    channel_dic = channel_details(token1, channel_id1)
    assert channel_dic['name'] == "channel 1"

    # error test
    with pytest.raises(ValueError):
        # Channel (based on ID) does not exist
        # assume channel ID 2 does not exist
        channel_details(token1, 10)
    '''
    with pytest.raises(AccessError):
        # Authorised user is not a member of channel with channel_id    
        # user2 is not a member of channel1
        channel_details(token2, channel_id1)
    '''
    # logout
    auth_logout(token1)
    auth_logout(token2)

    reset_data()
コード例 #21
0
def test_standup_start():
    reset_data()
    #SETUP Begin
    authRegDict1 = auth_register("*****@*****.**", "qwerty", "John", "Smith")
    token1 = authRegDict1['token']
    channelCreateDict1 = channels_create(token1, 'New Channel', True)
    channel_id1 = channelCreateDict1['channel_id']

    authRegDict2 = auth_register("*****@*****.**", "asdfgh", "Jim", "Smith")
    token2 = authRegDict2['token']
    #User 2 has not joined the 'New Channel' created by user 1
    #SETUP End
    #Test Case 1: Successful test case
    timestamp = int(datetime.datetime.now().strftime("%s")) + 5
    finish = standup_start(token1, channel_id1, 5)['time_finish']
    assert finish == timestamp
    # Successful test case should return datetime of current time + 5 minutes

    #Test Case 2: Unsuccessful test case where channel does not exist
    with pytest.raises(ValueError):
        standup_start(
            token1, 10,
            5)  #channel ID is invalid hence the unsuccessful function call

    #Test Case 3: Unsuccessful start of standup
    # due to user not being a member of the channel he/she is trying to send the message in
    with pytest.raises(AccessError):
        standup_start(token2, channel_id1, 5)

    #Test Case 3: Unsuccessful start of standup
    # because An active standup is currently running in this channel
    with pytest.raises(ValueError):
        standup_start(token1, channel_id1, 5)

    auth_logout(token1)
    auth_logout(token2)
    reset_data()
コード例 #22
0
def app_channels_create():
    token = get_args('token')
    name = get_args('name')
    is_public = str2bool(get_args('is_public'))

    return dumps(channels_create(token, name, is_public))
コード例 #23
0
def test_message_remove():
    reset_data()

    # SETUP BEGIN
    authRegisterDict1 = auth_register('*****@*****.**', '123456', 'hayden', 'Diego')
    auth_login('*****@*****.**', '123456')
    token1 = authRegisterDict1['token']
    authRegisterDict2 = auth_register('*****@*****.**', '123456', 'sally', 'Juan')
    auth_login('*****@*****.**', '123456')
    token2 = authRegisterDict2['token']
    uid2 = authRegisterDict2['u_id']
    authRegisterDict3 = auth_register('*****@*****.**', '123456', 'Nena', 'Smith')
    auth_login('*****@*****.**', '123456')
    token3 = authRegisterDict3['token']
    authRegisterDict4 = auth_register('*****@*****.**', '123456', 'Carmen', 'Davis')
    auth_login('*****@*****.**', '123456')
    token4 = authRegisterDict4['token']

    channelidDict1 = channels_create(token1, 'channel_1', True)
    channel_id1 = channelidDict1['channel_id']

    channel_join(token2, channel_id1)
    channel_addowner(token1, channel_id1, uid2)

    channel_join(token3, channel_id1)

    messages_dic1 = message_send(token1, channel_id1, "hello")
    message_id = messages_dic1['message_id']

    # SETUP END

    # The right example
    # the message_id is a valid message for user1
    assert message_remove(token1, message_id) == {}

    # send again
    messages_dic1 = message_send(token1, channel_id1, "hello")
    message_id = messages_dic1['message_id']
    # the right example
    # Message_id was not sent by the authorised user token2,
    # but the token2 is a owner of this channel
    assert message_remove(token2, message_id) == {}

    # send again
    messages_dic1 = message_send(token1, channel_id1, "hello")
    message_id = messages_dic1['message_id']
    with pytest.raises(ValueError):
        # assume Message id 2 no longer exists
        message_remove(token1, 10)

    with pytest.raises(AccessError):
        # assume token3 is not an owner of this channel that contain message_id
        message_remove(token3, message_id)

    with pytest.raises(AccessError):
        # assume token4 is not an admin or owner of the slack
        message_remove(token4, message_id)

    # logout
    auth_logout(token1)
    auth_logout(token2)
    auth_logout(token3)
    auth_logout(token4)
コード例 #24
0
ファイル: route.py プロジェクト: Tim-0731-Hzt/H18A-ROOKIES
def channel_create():
    token = request.form.get("token")
    name = request.form.get("name")
    is_public = request.form.get("is_public")
    return dumps(channels_create(token, name, is_public))
コード例 #25
0
def test_channel_addowner():
    reset_data()
    # SETUP BEGIN
    # Assume all users have registered in function: test_channel_invite()
    auth_dic1 = auth_register("*****@*****.**", "123456", "firstone",
                              "lastone")
    auth_login("*****@*****.**", "123456")
    token1 = auth_dic1['token']

    auth_dic2 = auth_register("*****@*****.**", "123456", "firstone",
                              "lastone")
    auth_dic2 = auth_login("*****@*****.**", "123456")
    token2 = auth_dic2['token']
    uid2 = auth_dic2['u_id']

    auth_dic3 = auth_register("*****@*****.**", "123456", "firstone",
                              "lastone")
    auth_dic3 = auth_login("*****@*****.**", "123456")
    token3 = auth_dic3['token']
    uid3 = auth_dic3['u_id']

    channelid_dic1 = channels_create(token1, "channel 1", True)
    channel_id1 = channelid_dic1['channel_id']

    channel_join(token2, channel_id1)
    channel_join(token3, channel_id1)

    # create a private channel
    channelid_dic2 = channels_create(token2, "channel 2", True)
    channel_id2 = channelid_dic2['channel_id']
    channel_join(token3, channel_id2)

    # SETUP END

    # successful test
    assert channel_addowner(token1, channel_id1, uid2) == {}
    assert channel_addowner(token1, channel_id2,
                            uid3) == {}  # token 1 is the owner of the slackr
    # error test
    with pytest.raises(ValueError):
        # Channel (based on ID) does not exist
        channel_addowner(token1, 10, uid2)

    with pytest.raises(ValueError):
        # When user with user id u_id is already an owner of the channel
        channel_addowner(token1, channel_id1, uid2)

    with pytest.raises(ValueError):
        # When the user with u_id is not a member of the channel
        channel_addowner(token1, channel_id2, uid2)

    with pytest.raises(AccessError):
        # when the authorised user is not an owner of the slackr, or an owner of this channel
        channel_addowner(token3, channel_id1, uid3)

    # logout
    auth_logout(token1)
    auth_logout(token2)
    auth_logout(token3)

    reset_data()