示例#1
0
def test_channel_join_successful():
    'Successful case'
    workspace_reset()

    ret = register_and_create()
    user1 = ret['user']
    token1 = user1['token']
    u_id1 = user1['u_id']
    channel_info = ret['channel']
    channel_id = channel_info['channel_id']

    channel.leave(token1, channel_id)
    channel.join(token1, channel_id)

    assert channel.details(token1, channel_id)['name'] == 'firstChannel'
    assert channel.details(token1, channel_id)['owner_members'] == [{
        'u_id':
        u_id1,
        'name_first':
        'Kennan',
        'name_last':
        'Wong'
    }]
    assert channel.details(token1, channel_id)['all_members'] == [{
        'u_id':
        u_id1,
        'name_first':
        'Kennan',
        'name_last':
        'Wong'
    }]
def test_listall():
    'testing functionability of channels listall'

    workspace_reset()

    ret = register_and_create()
    user1 = ret['user']
    token = user1['token']

    user2 = reg_user2()

    #user2 creating a channel
    payload1 = {
        'token': user2['token'],
        'name': 'Slackrs',
        'is_public': True
    }
    result1 = channels.create(payload1) # pylint: disable=W0612

    result2 = channels.Listall(token) # pylint: disable=C0304

    expected1 = {
        'channel_id' : 1,
        'name': 'firstChannel'
    }

    expected2 = {
        'channel_id': 2,
        'name': 'Slackrs'
    }

    assert expected1 in result2
    assert expected2 in result2
示例#3
0
def test_users_all_invalid_token_error():
    workspace_reset()
    user_ef = auth_register(
        "*****@*****.**", "12345687", "Edward", "Frankenstein")

    with pytest.raises(AccessError):
        users_all(user_ef["token"] + "invalid")
示例#4
0
def test_users_all_access_three_users_at_once_in_order():
    workspace_reset()
    user_gh = auth_register("*****@*****.**",
                            "ihaveadream", "Gregory", "Heidelberg")
    user_ef = auth_register(
        "*****@*****.**", "12345687", "Edward", "Frankenstein")
    user_ij = auth_register(
        "*****@*****.**", "stretchy0urh4mstrinG5thr1c3", "Ian", "Jacobs")

    assert users_all(user_ij["token"])["users"] == [
        {
            'u_id': user_gh["u_id"],
            'email': '*****@*****.**',
            'name_first': 'Gregory',
            'name_last': 'Heidelberg',
            'handle_str': 'gregoryheidelberg',
            "profile_img_url": ""
        },
        {
            'u_id': user_ef["u_id"],
            'email': '*****@*****.**',
            'name_first': 'Edward',
            'name_last': 'Frankenstein',
            'handle_str': 'edwardfrankenstein',
            "profile_img_url": ""
        },
        {
            'u_id': user_ij["u_id"],
            'email': '*****@*****.**',
            'name_first': 'Ian',
            'name_last': 'Jacobs',
            'handle_str': 'ianjacobs',
            "profile_img_url": ""
        }
    ]
示例#5
0
def test_unreact():
    '''
    Test a valid case of message_unreact to a message someone
    else had sent
    '''
    workspace_reset()
    user1 = reg_user1()
    user2 = reg_user2()
    channel1 = create_ch1(user1)
    invite_to_ch1(user1, user2, channel1)
    msg1 = send_msg1(user1, channel1)

    # react to the message
    react_to_msg(1, msg1, user2)

    payload = {
        'token': user2['token'],
        'message_id': msg1['message_id'],
        'react_id': 1
    }
    message.unreact(payload)

    message1_reacts = find_message(msg1['message_id'])['reacts']
    for i in message1_reacts:
        if i['react_id'] == 1:
            assert user2['u_id'] not in i['u_ids']
def test_reset():
    'testing functionability of passwordreset request'

    workspace_reset()
    reset_store = get_reset_code_store()

    reg_user1()

    auth.request({'email': '*****@*****.**'})

    for i in reset_store:
        if i['email'] == '*****@*****.**':
            code = i['reset_code']

    auth.reset({'reset_code': code, 'new_password': '******'})

    auth_store = get_auth_data_store()

    password_check = 0  #if new password is in auth store let = 1

    for i in auth_store:
        if i['password'] == 'thisiscool':
            password_check = 1

    assert password_check == 1
示例#7
0
def test_user_profile_sethandle_already_used():
    workspace_reset()

    details1 = reg_user1()
    token1 = details1['token']
    uid1 = details1['u_id']

    details2 = reg_user2()
    token2 = details2['token']
    uid2 = details2['u_id']

    valid_handle = "ValidHandle"

    #test handle already used

    payload1 = {'token': token1, 'handle_str': valid_handle}

    payload2 = {'token': token1, 'u_id': uid1}

    payload3 = {'token': token2, 'handle_str': valid_handle}

    user_profile_sethandle(payload1)

    assert (user_profile(payload2) == {})

    with pytest.raises(InputError):
        user_profile_sethandle(payload3)
示例#8
0
def test_message_send_channel_not_found():
    workspace_reset()
    user_ab = auth_register("*****@*****.**", "stronkpassword123", "Alice",
                            "Bee")

    with pytest.raises(Exception):
        message_send(user_ab['token'], 22222, "Hello world!")
示例#9
0
def test_active():
    'testing functionability for standup active'

    workspace_reset()

    ret = register_and_create()
    user = ret['user']
    channel = ret['channel']

    payload = {
        'token': user['token'],
        'channel_id': channel['channel_id'],
        'length': 30
    }

    result = standup.start(payload)

    payload2 = {'token': user['token'], 'channel_id': channel['channel_id']}

    result2 = standup.active(payload2)

    length = 30
    time_finish = (datetime.now() +
                   timedelta(seconds=length)).strftime("%H:%M:%S")

    assert result == time_finish
    assert result2['is_active'] is True
示例#10
0
def test_user_profile_setname_working():
    workspace_reset()

    details = reg_user1()

    token = details['token']
    uid = details['u_id']

    #do some tests to test that everying is running fine

    #initially the user's name is varun kashyap, and is changed to jeff jefferson
    name_first2 = "Jeff"
    name_last2 = "Jefferson"

    payload5 = {
        'token': details['token'],
        'name_first': name_first2,
        'name_last': name_last2
    }

    assert (user_profile_setname(payload5) == {})

    payload3 = {'token': details['token'], 'u_id': details['u_id']}

    profile2 = user_profile(payload3)
    assert (profile2['name_first']) == name_first2
    assert (profile2['name_last']) == name_last2
示例#11
0
def test_invalid_id():
    'testing error case'

    workspace_reset()

    ret = register_and_create()
    user = ret['user']
    channel = ret['channel']

    payload = {
        'token': user['token'],
        'channel_id': channel['channel_id'],
        'length': 30
    }

    result = standup.start(payload)  # pylint: disable=W0612

    payload2 = {'token': user['token'], 'channel_id': channel['channel_id']}

    result2 = standup.active(payload2)  # pylint: disable=W0612

    with pytest.raises(InputError):
        standup.start({
            'token': user['token'],
            'channel_id': 100,
            'message': 'test'
        })
示例#12
0
def test_unauthor_member():
    'testing error case'

    workspace_reset()

    ret = register_and_create()
    user = ret['user']
    channel = ret['channel']

    user2 = reg_user2()

    payload = {
        'token': user['token'],
        'channel_id': channel['channel_id'],
        'length': 30
    }

    result = standup.start(payload)  # pylint: disable=W0612

    payload2 = {'token': user['token'], 'channel_id': channel['channel_id']}

    result2 = standup.active(payload2)  # pylint: disable=W0612

    with pytest.raises(AccessError):
        standup.send({
            'token': user2['token'],
            'channel_id': channel['channel_id'],
            'message': 'test'
        })  # pylint: disable=C0304
示例#13
0
def make_users():
    workspace_reset()
    user_ab = auth_register("*****@*****.**", "stronkpassword123", "Alice",
                            "Bee")
    user_cd = auth_register("*****@*****.**", "comp1531pass", "Charlie",
                            "Dee")
    return (user_ab, user_cd)
def test_channel_remove_owner():
    'Normal case'
    workspace_reset()

    ret = register_and_create()
    user1 = ret['user']
    token1 = user1['token']
    u_id1 = user1['u_id']
    channel_info = ret['channel']
    user2 = reg_user2()
    token2 = user2['token']
    u_id2 = user2['u_id']

    channel_id = channel_info['channel_id']

    channel.join(token2, channel_id)
    channel.addowner(token1, channel_id, u_id2)

    # User2 removes user1 as owner
    channel.removeowner(token2, channel_id, u_id1)

    assert channel.details(token1, channel_id)['owner_members'] == [{
        "u_id":
        u_id2,
        "name_first":
        'Cindy',
        "name_last":
        'Tran'
    }]
示例#15
0
def test_user_profile_sethandle_length():
    workspace_reset()

    string_3 = "aaa"
    string_20 = "x" * 20

    string_2 = "aa"
    string_21 = "q" * 21
    string_long = "w" * 50

    details = reg_user1()
    token = details['token']
    uid = details['u_id']

    assert (user_profile_sethandle(token, string_3) == {})
    #check handle has been changed
    assert (user_profile(token, ["handle_str"] == string_3))
    assert (user_profile_sethandle(token, string_20) == {})
    assert (user_profile(token, ["handle_str"] == string_20))

    with pytest.raises(InputError):
        user_profile_sethandle(token, string_2)

    with pytest.raises(InputError):
        user_profile_sethandle(token, string_21)

    with pytest.raises(InputError):
        user_profile_sethandle(token, string_long)
示例#16
0
def test_user_profile_setemail_invalidEmail():

    #create some users
    workspace_reset()

    details = reg_user1()

    token = details['token']
    uid = details['u_id']

    #function will fail if the email provided is invalid
    payload1 = {'token': token, 'email': "@gmail.com"}
    payload2 = {'token': token, 'email': "[email protected]"}
    payload3 = {'token': token, 'email': "new_email@gmail."}
    payload4 = {'token': token, 'email': "new_emailgmail.com"}

    # No prefix
    with pytest.raises(InputError):
        user_profile_setemail(payload1)
    # No suffix
    with pytest.raises(InputError):
        user_profile_setemail(payload2)
    # No .com
    with pytest.raises(InputError):
        user_profile_setemail(payload3)
    # no @
    with pytest.raises(InputError):
        user_profile_setemail(payload4)
示例#17
0
def test_user_profile_setname_length_border():
    workspace_reset()

    details = reg_user1()
    token = details['token']
    string_50 = "a" * 50
    string_1 = "a"

    payload1 = {
        'token': details['token'],
        'name_first': "ValidString",
        'name_last': string_50
    }

    payload2 = {
        'token': details['token'],
        'name_first': "ValidString",
        'name_last': string_1
    }
    payload3 = {
        'token': details['token'],
        'name_first': string_50,
        'name_last': "ValidString"
    }
    payload4 = {
        'token': details['token'],
        'name_first': string_1,
        'name_last': string_50
    }

    assert (user_profile_setname(payload1) == {})
    assert (user_profile_setname(payload2) == {})
    assert (user_profile_setname(payload3) == {})
    assert (user_profile_setname(payload4) == {})
示例#18
0
def test_send():
    'testing functionability for standup send'

    workspace_reset()

    ret = register_and_create()
    user = ret['user']
    channel = ret['channel']

    payload = {
        'token': user['token'],
        'channel_id': channel['channel_id'],
        'length': 30
    }

    result = standup.start(payload)  # pylint: disable=W0612

    payload2 = {'token': user['token'], 'channel_id': channel['channel_id']}

    result2 = standup.active(payload2)  # pylint: disable=W0612

    standup.send({
        'token': user['token'],
        'channel_id': channel['channel_id'],
        'message': 'test'
    })
示例#19
0
def test_message_too_long():
    'testing error case'

    workspace_reset()

    ret = register_and_create()
    user = ret['user']
    channel = ret['channel']

    payload = {
        'token': user['token'],
        'channel_id': channel['channel_id'],
        'length': 30
    }

    result = standup.start(payload)  # pylint: disable=W0612

    payload2 = {'token': user['token'], 'channel_id': channel['channel_id']}

    result2 = standup.active(payload2)  # pylint: disable=W0612

    with pytest.raises(InputError):
        standup.send({
            'token':
            user['token'],
            'channel_id':
            channel['channel_id'],
            'message':
            'To manage the transition from trimesters to hexamesters in 2020,'
            +
            'UNSW has established a new focus on building an in-house digital'
            +
            ' collaboration and communication tool for groups and teams to support'
            +
            ' the high intensity learning environment. Rather than re-invent the '
            +
            'wheel, UNSW decided that it finds the functionality of Slackto be nearly'
            +
            ' exactly what it needs. For this reason, UNSW has contracted out Lit Pty '
            +
            'Ltd (a small software business run by Hayden) to build the new product.'
            +
            ' UNSWs attempt to connect with the younger and more "hip" generation that'
            +
            ' fell in love with flickr, Tumblr, etc, they would like to call the new '
            +
            'UNSW-based product slackr. Lit Pty Ltd has sub-contracted two software '
            +
            'firms: Catdog Pty Ltd (two software developers, Sally and Bob, who will '
            +
            'build the initial web-based GUI). YourTeam Pty Ltd (a team of talented '
            +
            'misfits completing COMP1531 in 20T1), who will build the backend python '
            +
            'server and possibly assist in the GUI later in the project. In summary, '
            +
            'UNSW contracts Lit Pty Ltd, who sub contracts:Catdog (Sally and Bob) '
            + 'for front end work, YourTeam (you and others) for backend work'
        })
示例#20
0
def test_user_profile_setname_name_both_short():
    workspace_reset()

    details = reg_user1()
    payload = {'token': details['token'], 'name_first': "", 'name_last': ""}

    with pytest.raises(InputError):
        user_profile_setname(payload)
示例#21
0
def test_reseting_password():
    workspace_reset()
    data = get_store()
    reg_dict = auth_register('*****@*****.**', 'password123',
                             'Max', 'Smith')
    auth_logout(reg_dict['token'])
    data.users.set_password(reg_dict['u_id'], 'wubbalubba')
    auth_login('*****@*****.**', 'wubbalubba')
示例#22
0
def test_invalid_id():
    'testing error case'
    workspace_reset()

    ret = register_and_create()
    user = ret['user']
    with pytest.raises(InputError):
        message.unpin({'token': user['token'], 'message_id': 1})
示例#23
0
def test_auth_register_existing_user():
    workspace_reset()

    auth_register('*****@*****.**', 'great_password101', 'Max', 'Smith')

    with pytest.raises(InputError):
        auth_register('*****@*****.**', 'great_password101', 'Max',
                      'Smith')
示例#24
0
def test_login_password():
    workspace_reset()

    user = auth_register('*****@*****.**', 'great_password101', 'Max',
                         'Smith')
    auth_logout(user['token'])
    with pytest.raises(InputError):
        auth_login('*****@*****.**', 'poor_password')
示例#25
0
def test_profile_invalid_uID3():
    workspace_reset()

    details = reg_user1()

    payload = {'token': details['token'], 'u_id': "126261261----22322323"}

    with pytest.raises(InputError):
        user_profile(payload)
示例#26
0
def test_login():
    workspace_reset()

    user = auth_register('*****@*****.**', 'great_password101', 'Max',
                         'Smith')
    auth_logout(user['token'])
    user_logging_in = auth_login('*****@*****.**', 'great_password101')

    assert user['u_id'] == user_logging_in['u_id']
示例#27
0
def test_profile_invalid_uID2():
    workspace_reset()

    details = reg_user1()

    payload = {'token': details['token'], 'u_id': "22tt3t3tt3r4r"}

    with pytest.raises(InputError):
        user_profile(payload)
示例#28
0
def test_profile_invalid_uID1():

    workspace_reset()

    details = reg_user1()

    payload = {'token': details['token'], 'u_id': "NOT_VALID_UID"}

    with pytest.raises(InputError):
        user_profile(payload)
示例#29
0
def test_user_profile_uploadphoto_error1():
    workspace_reset()
    #img_url is return an HTTP status other than 200

    details = reg_user1
    token = details['token']
    url = "https://img.buzzfeed.com/buzzfeed-static/static/2020-04/16/14/asset/46d3bcfa9ed6/sub-buzz-1180-1587047168-1.jpg"

    with pytest.raises(ValueError, match=r"*"):
        user_profile_uploadphoto(token, "notArealUrl.jpg", 300, 100, 100, 100)
示例#30
0
def test_user_profile_uploadphoto_error2():
    workspace_reset()
    #x_start, y_start, x_end, y_end are not within the dimensions of the image

    url = "https://img.buzzfeed.com/buzzfeed-static/static/2020-04/16/14/asset/46d3bcfa9ed6/sub-buzz-1180-1587047168-1.jpg"
    details = reg_user1
    token = details['token']

    with pytest.raises(ValueError, match=r"*"):
        user_profile_uploadphoto(token, url, 99999999999, 999999999999,
                                 999999999999, 999999999999)