Example #1
0
def test_not_in_channel():
    '''
    Test a user unreacting to a message in a channel they
    are not a part of
    '''
    reset_workspace()

    user1 = reg_user1()
    user2 = reg_user2()
    channel1 = create_ch1(user1)
    msg1 = send_msg1(user1, channel1)
    react_to_msg(user1, msg1, 1)

    data = json.dumps({
        'token': user2['token'],
        'message_id': msg1['message_id'],
        'react_id': 1
    }).encode('utf-8')

    with pytest.raises(HTTPError):
        urllib.request.urlopen(
            urllib.request.Request(
                f"{BASE_URL}/message/unreact",
                data=data,
                headers={'Content-Type': 'application/json'}))
Example #2
0
def test_unreact1():
    '''
    Test a valid case of message_unreact to a message they had sent
    '''
    reset_workspace()

    user1 = reg_user1()
    channel1 = create_ch1(user1)
    msg1 = send_msg1(user1, channel1)
    react_to_msg(user1, msg1, 1)

    data = json.dumps({
        'token': user1['token'],
        'message_id': msg1['message_id'],
        'react_id': 1
    }).encode('utf-8')

    req = urllib.request.urlopen(
        urllib.request.Request(f"{BASE_URL}/message/unreact",
                               data=data,
                               headers={'Content-Type': 'application/json'}))

    payload = json.load(req)

    assert payload == {}
Example #3
0
def test_login():
    '''
    Test valid case of test_login
    '''
    reset_workspace()

    # Register a user
    response = reg_user1()

    # Logout that user
    logout_user1(response['token'])

    # Attempt to login that user
    data = json.dumps({
        'email': '*****@*****.**',
        'password': '******'
    }).encode('utf-8')
    req = urllib.request.urlopen(
        urllib.request.Request(f"{BASE_URL}/auth/login",
                               data=data,
                               headers={'Content-Type': 'application/json'}))
    payload = json.load(req)

    assert response['u_id'] == payload['u_id']
    assert response['token'] == payload['token']
def test_already_active():
    'error case'
    reset_workspace()


    user1 = reg_user1()
    channel1 = create_ch1(user1)

    data = json.dumps({
        'token': user1['token'],
        'channel_id': channel1['channel_id'],
        'length': 30
    }).encode('utf-8')

    urllib.request.urlopen(urllib.request.Request(
            f"{BASE_URL}/standup/start",                    # pylint: disable=C0330
            data=data,                                      # pylint: disable=C0330
            headers={'Content-Type':'application/json'}     # pylint: disable=C0330
        ))

    with pytest.raises(HTTPError):
        urllib.request.urlopen(urllib.request.Request(
            f"{BASE_URL}/standup/start",
            data=data,
            headers={'Content-Type':'application/json'}
        ))                                                   # pylint: disable=C0304
def test_channel_invite_invalid_userid():
    'Invalid user case'
    reset_workspace()

    # Register users
    user1 = reg_user1()
    token1 = user1['token']
    # Create channel
    channel_info = create_ch1(user1)
    channel_id = channel_info['channel_id']

    # Attempt to invite a user with an invalid userID to a channel
    # Invalid u_id = 100
    data = json.dumps({
        'token': token1,
        'channel_id': channel_id,
        'u_id': 100
    }).encode('utf-8')

    with pytest.raises(HTTPError):
        urllib.request.urlopen(
            urllib.request.Request(
                f"{BASE_URL}/channel/invite",
                data=data,
                headers={'Content-Type': 'application/json'}))
Example #6
0
def test_user_uploadphoto_valurl():
    '''
    This tests the funciton under correct inputs
    '''

    reset_workspace()

    details = reg_user1()

    data = json.dumps({
        'token': details['token'],
        'img_url':
        "https://upload.wikimedia.org/wikipedia/commons/thumb/6/66/An_up-close_picture_of_a_curious_male_domestic_shorthair_tabby_cat.jpg",
        'x_start': 1,
        'y_start': 1,
        'x_end': 1,
        'y_end': 1
    }).encode('utf-8')

    req = urllib.request.Request(f"{BASE_URL}/user/profile/uploadphoto",
                                 data=data,
                                 headers={'Content-Type': 'application/json'})

    payload = json.load(req)

    assert details['img_url'] == payload['img_url']
Example #7
0
def test_unpin():
    '''
    Test a valid use of pin on your own message
    '''
    reset_workspace()

    user1 = reg_user1()
    channel1 = create_ch1(user1)

    msg1 = send_msg1(user1, channel1)

    data = json.dumps({
        'token': user1['token'],
        'message_id': msg1['message_id'],
    }).encode('utf-8')

    req = urllib.request.urlopen(
        urllib.request.Request(  # pylint: disable=W0611, W0612
            f"{BASE_URL}/message/pin",
            data=data,
            headers={'Content-Type': 'application/json'}))

    data1 = json.dumps({
        'token': user1['token'],
        'message_id': msg1['message_id'],
    }).encode('utf-8')

    req1 = urllib.request.urlopen(
        urllib.request.Request(f"{BASE_URL}/message/unpin",
                               data=data1,
                               headers={'Content-Type': 'application/json'}))
    payload = json.load(req1)
    assert payload == {}
def test_reset():
    '''
    Test valid case of test_password_request
    '''
    reset_workspace()

    reg_sid()

    data = json.dumps({'email': '*****@*****.**'}).encode('utf-8')

    req = urllib.request.urlopen(
        urllib.request.Request(  # pylint: disable=W0612
            f"{BASE_URL}/auth/passwordreset/request",
            data=data,
            headers={'Content-Type': 'application/json'}))

    reset_store = get_reset_code_store()
    code = ''
    print(reset_store)
    for i in reset_store:
        if i['email'] == '*****@*****.**':
            code = i['reset_code']
            #pylint disable = C0303
    data1 = json.dumps({
        'reset_code': code,
        'new_password': '******'
    }).encode('utf-8')

    req1 = urllib.request.urlopen(
        urllib.request.Request(f"{BASE_URL}/auth/passwordreset/reset",
                               data=data1,
                               headers={'Content-Type': 'application/json'}))

    payload = json.load(req1)
    assert payload == {}
Example #9
0
def test_channel_addowner():
    'Normal case'
    reset_workspace()

    user1 = reg_user1()
    token1 = user1['token']
    user2 = reg_user2()
    token2 = user2['token']
    u_id2 = user2['u_id']

    channel_info = create_ch1(user1)
    channel_id = channel_info['channel_id']

    # Join
    data = json.dumps({
        'token': token2,
        'channel_id': channel_id
    }).encode('utf-8')
    urllib.request.urlopen(
        urllib.request.Request(f"{BASE_URL}/channel/join",
                               data=data,
                               headers={'Content-Type': 'application/json'}))
    data2 = json.dumps({
        'token': token1,
        'channel_id': channel_id,
        'u_id': u_id2
    }).encode('utf-8')
    req = urllib.request.urlopen(
        urllib.request.Request(f"{BASE_URL}/channel/addowner",
                               data=data2,
                               headers={'Content-Type': 'application/json'}))
    payload = json.load(req)

    assert payload == {}
def test_channel_invite_successful():
    'Successful case'
    reset_workspace()

    # Register users
    user1 = reg_user1()
    token1 = user1['token']
    user2 = reg_user2()
    u_id2 = user2['u_id']
    # Create channel
    channel_info = create_ch1(user1)
    channel_id = channel_info['channel_id']

    # Attempt to invite user2
    data = json.dumps({
        'token': token1,
        'channel_id': channel_id,
        'u_id': u_id2
    }).encode('utf-8')
    req = urllib.request.urlopen(
        urllib.request.Request(f"{BASE_URL}/channel/invite",
                               data=data,
                               headers={'Content-Type': 'application/json'}))
    payload = json.load(req)

    assert payload == {}
Example #11
0
def test_active():
    'successful case'
    reset_workspace()

    user1 = reg_user1()
    channel1 = create_ch1(user1)

    data1 = json.dumps({
        'token': user1['token'],
        'channel_id': channel1['channel_id'],
        'length': 30
    }).encode('utf-8')

    req = urllib.request.urlopen(urllib.request.Request(
        f"{BASE_URL}/standup/start",
        data=data1,
        headers={'Content-Type':'application/json'}
    ))

    req = urllib.request.Request(
        f"{BASE_URL}/standup/active?token="+str(user1['token'])+"&channel_id="+str(channel1['channel_id']) # pylint: disable=C0301
    )

    req.get_method = lambda: 'GET'
    response = json.load(urllib.request.urlopen(req))

    assert response['is_active'] is True

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

    assert response['time_finish'] == time_finish
def test_email_used():
    '''
    Test regiseting a user with an email that is already in use
    '''
    reset_workspace()

    # Register user first
    data = json.dumps({
        'email': '*****@*****.**',
        'password': '******',
        'name_first': 'Kennan',
        'name_last': 'Wong'
    }).encode('utf-8')
    urllib.request.urlopen(
        urllib.request.Request(f"{BASE_URL}/auth/register",
                               data=data,
                               headers={'Content-Type': 'application/json'}))

    # Attempt to register new user with the same email
    data2 = json.dumps({
        'email': '*****@*****.**',
        'password': '******',
        'name_first': 'Ken',
        'name_last': 'Wong'
    }).encode('utf-8')

    with pytest.raises(HTTPError):
        urllib.request.urlopen(
            urllib.request.Request(
                f"{BASE_URL}/auth/register",
                data=data2,
                headers={'Content-Type': 'application/json'}))
def test_invalid_id():
    'error case'

    reset_workspace()

    user1 = reg_user1()
    channel1 = create_ch1(user1)

    data = json.dumps({
        'token': user1['token'],
        'channel_id': channel1['channel_id'],
        'length': 30
    }).encode('utf-8')

    req = urllib.request.urlopen(
        urllib.request.Request(  # pylint: disable=W0612
            f"{BASE_URL}/standup/start",
            data=data,
            headers={'Content-Type': 'application/json'}))

    data2 = json.dumps({
        'token': user1['token'],
        'channel_id': 100,
        'message': 'testing'
    }).encode('utf-8')

    with pytest.raises(HTTPError):
        urllib.request.urlopen(
            urllib.request.Request(
                f"{BASE_URL}/standup/send",
                data=data2,
                headers={'Content-Type': 'application/json'}))
def test_channel_messages_unauthorised():
    'User is not a member case'
    reset_workspace()

    user1 = reg_user1()
    token1 = user1['token']

    channel1 = create_ch1(user1)
    channel_id = channel1['channel_id']

    # Send a message
    data = json.dumps({
        'token': token1,
        'channel_id': channel_id,
        'message': "hello"
    }).encode('utf-8')
    urllib.request.urlopen(urllib.request.Request(
        f"{BASE_URL}/message/send",
        data=data,
        headers={'Content-Type':'application/json'}
    ))

    req = urllib.request.Request(
        f"{BASE_URL}/channel/messages?token="+str(token1)+"&channel_id="+str(channel_id)+"&start=50"
    )
    req.get_method = lambda: 'GET'

    with pytest.raises(HTTPError):
        json.load(urllib.request.urlopen(req))
def test_listall():
    'successful case for channels listall'
    reset_workspace()

    user1 = reg_user1()
    user2 = reg_user2()

    create_ch1(user1)

    data = json.dumps({
        'token': user2['token'],
        'name': 'new_channel',
        'is_public': True
    }).encode('utf-8')

    req = urllib.request.urlopen(
        urllib.request.Request(f"{BASE_URL}/channels/create",
                               data=data,
                               headers={'Content-Type': 'application/json'}))

    req = urllib.request.Request(f"{BASE_URL}/channels/listall?token=" +
                                 str(user1['token']))

    req.get_method = lambda: 'GET'

    response = json.load(urllib.request.urlopen(req))['channels']

    expected = {'channel_id': 1, 'name': 'new_channel'}

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

    assert expected in response  #pylint disable = C0305
    assert expected2 in response  #pylint disable = C0305
def test_channel_invite_invalid_channel():
    'Invalid channel case'
    reset_workspace()

    # Register users
    user1 = reg_user1()
    token1 = user1['token']
    user2 = reg_user2()
    u_id2 = user2['u_id']
    # Create channel
    create_ch1(user1)

    # Attempt to invite user2 to an invalid channel
    # Invalid channel_id = 100
    data = json.dumps({
        'token': token1,
        'channel_id': 100,
        'u_id': u_id2
    }).encode('utf-8')

    with pytest.raises(HTTPError):
        urllib.request.urlopen(
            urllib.request.Request(
                f"{BASE_URL}/channel/invite",
                data=data,
                headers={'Content-Type': 'application/json'}))
def test_react2():
    '''
    Test another user in a channel attempting to react to another person message
    '''
    reset_workspace()

    user1 = reg_user1()
    user2 = reg_user2()
    channel1 = create_ch1(user1)
    invite_to_channel(user1, user2, channel1)
    msg1 = send_msg1(user1, channel1)

    data = json.dumps({
        'token': user2['token'],
        'message_id': msg1['message_id'],
        'react_id': 1
    }).encode('utf-8')

    req = urllib.request.urlopen(
        urllib.request.Request(f"{BASE_URL}/message/react",
                               data=data,
                               headers={'Content-Type': 'application/json'}))

    payload = json.load(req)

    assert payload == {}
Example #18
0
def test_not_owner():
    'Non-owner case'
    reset_workspace()

    user1 = reg_user1()
    user2 = reg_user2()
    token2 = user2['token']
    user3 = reg_user3()
    token3 = user3['token']
    u_id3 = user3['u_id']

    channel_info = create_ch1(user1)
    channel_id = channel_info['channel_id']

    # Join
    data = json.dumps({
        'token': token3,
        'channel_id': channel_id
    }).encode('utf-8')
    urllib.request.urlopen(
        urllib.request.Request(f"{BASE_URL}/channel/join",
                               data=data,
                               headers={'Content-Type': 'application/json'}))
    data2 = json.dumps({
        'token': token2,
        'channel_id': channel_id,
        'u_id': u_id3
    }).encode('utf-8')

    with pytest.raises(HTTPError):
        urllib.request.urlopen(
            urllib.request.Request(
                f"{BASE_URL}/channel/addowner",
                data=data2,
                headers={'Content-Type': 'application/json'}))
def test_already_pinned():
    'error case test'
    reset_workspace()

    user1 = reg_user1()
    channel1 = create_ch1(user1)
    msg1 = send_msg1(user1, channel1)

    data = json.dumps({
        'token': user1['token'],
        'message_id': msg1['message_id'],
    }).encode('utf-8')

    urllib.request.urlopen(
        urllib.request.Request(
            f"{BASE_URL}/message/pin",  # pylint: disable=C0330
            data=data,  # pylint: disable=C0330
            headers={'Content-Type': 'application/json'}  # pylint: disable=C0330
        ))

    with pytest.raises(HTTPError):
        urllib.request.urlopen(
            urllib.request.Request(
                f"{BASE_URL}/message/pin",
                data=data,
                headers={'Content-Type': 'application/json'}))
Example #20
0
def test_unauth_owner():
    'error case test'
    reset_workspace()

    user1 = reg_user1()
    user2 = reg_user2()

    channel1 = create_ch1(user1)

    invite_to_channel(user1, user2, channel1)
    msg1 = send_msg1(user1, channel1)

    data = json.dumps({
        'token': user1['token'],
        'message_id': msg1['message_id'],
    }).encode('utf-8')

    urllib.request.urlopen(
        urllib.request.Request(f"{BASE_URL}/message/pin",
                               data=data,
                               headers={'Content-Type': 'application/json'}))

    data1 = json.dumps({
        'token': user2['token'],
        'message_id': 1,
    }).encode('utf-8')

    with pytest.raises(HTTPError):
        urllib.request.urlopen(
            urllib.request.Request(
                f"{BASE_URL}/message/unpin",
                data=data1,
                headers={'Content-Type': 'application/json'}))
def test_send():
    'successful case for standup send'

    reset_workspace()

    user1 = reg_user1()
    channel1 = create_ch1(user1)

    data = json.dumps({
        'token': user1['token'],
        'channel_id': channel1['channel_id'],
        'length': 30
    }).encode('utf-8')

    req = urllib.request.urlopen(
        urllib.request.Request(  # pylint: disable=W0612
            f"{BASE_URL}/standup/start",
            data=data,
            headers={'Content-Type': 'application/json'}))

    data2 = json.dumps({
        'token': user1['token'],
        'channel_id': channel1['channel_id'],
        'message': 'testing'
    }).encode('utf-8')

    req2 = urllib.request.urlopen(
        urllib.request.Request(f"{BASE_URL}/standup/send",
                               data=data2,
                               headers={'Content-Type': 'application/json'}))

    payload = json.load(req2)  # pylint: disable=W0612

    assert payload == {}
Example #22
0
def test_channel_details():
    'Getting details'
    reset_workspace()

    user1 = reg_user1()
    token1 = user1['token']
    u_id1 = user1['u_id']

    channel1 = create_ch1(user1)
    channel_id = channel1['channel_id']

    req = urllib.request.Request(f"{BASE_URL}/channel/details?token=" +
                                 str(token1) + "&channel_id=" +
                                 str(channel_id))
    req.get_method = lambda: 'GET'

    payload = json.load(urllib.request.urlopen(req))

    assert payload['name'] == 'new_channel'
    assert payload['owner_members'] == [{
        "u_id": u_id1,
        "name_first": 'Kennan',
        "name_last": 'Wong'
    }]
    assert payload['all_members'] == [{
        "u_id": u_id1,
        "name_first": 'Kennan',
        "name_last": 'Wong'
    }]
def test_channel_invite_unauthorised():
    'User is not a member case'
    reset_workspace()

    # Register users
    user1 = reg_user1()
    user2 = reg_user2()
    token2 = user2['token']
    user3 = reg_user3()
    u_id3 = user3['u_id']

    # Create channel
    channel_info = create_ch1(user1)
    channel_id = channel_info['channel_id']

    data = json.dumps({
        'token': token2,
        'channel_id': channel_id,
        'u_id': u_id3
    }).encode('utf-8')

    with pytest.raises(HTTPError):
        urllib.request.urlopen(
            urllib.request.Request(
                f"{BASE_URL}/channel/invite",
                data=data,
                headers={'Content-Type': 'application/json'}))
Example #24
0
def test_game_start():
    reset_workspace()

    # Register a user
    user1 = reg_user1()

    channel1 = create_ch1(user1)

    channel1_dets = get_channel(channel1['channel_id'])

    # start a game of hangman
    data = json.dumps({
        'token': user1['token'],
        'channel_id': channel1['channel_id'],
        'message': '/hangman'
    }).encode('utf-8')
    req = urllib.request.urlopen(
        urllib.request.Request(f"{BASE_URL}/message/send",
                               data=data,
                               headers={'Content-Type': 'application/json'}))
    payload = json.load(req)

    channel1_dets = get_channel(channel1['channel_id'])

    print(channel1_dets)
    '''

    assert channel1_dets['hangman_active'] == True
    assert {"u_id": 2, "name_first": "Hangman", "name_last": "Bot"} in channel1_dets['members']
    
    phrase = get_phrase()
    
    guess = phrase[0]

    #make a guess
    data = json.dumps({
        'token': user1['token'],
        'channel_id': channel1['channel_id'],
        'message': '/guess ' + str(guess)
    }).encode('utf-8')
    req = urllib.request.urlopen(urllib.request.Request(
        f"{BASE_URL}/message/send",
        data=data,
        headers={'Content-Type':'application/json'}
    ))
    payload2 = json.load(req)

    empty_guess = get_empty_guess()

    assert guess in empty_guess
    '''
    assert 1 == 1
Example #25
0
def test_invalid_channel_id():
    'error test'
    reset_workspace()

    user1 = reg_user1()
   # channel1 = create_ch1(user1)

    with pytest.raises(HTTPError):
        req = urllib.request.Request(
            f"{BASE_URL}/standup/active?token="+str(user1['token'])+"&channel_id=1"
        )
        req.get_method = lambda: 'GET'
        json.load(urllib.request.urlopen(req))
Example #26
0
def test_profile_invalid_u_id():
    '''
    Test for invalid u_id
    '''

    reset_workspace()

    req = urllib.request.Request(
        f"{BASE_URL}/user/profile?token=6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b&u_id=2"
    )

    with pytest.raises(HTTPError):
        json.load(urllib.request.urlopen(req))
def test_long_msg():
    '''
    Test to send a message more thatn 1000 characters, should raise an Input error
    '''
    reset_workspace()

    user1 = reg_user1()
    ch1 = create_ch1(user1)

    data = json.dumps({
        'token':
        user1['token'],
        'channel_id':
        ch1['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 has decided that it finds the functionality of Slack to 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. In'
        +
        ' 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'
    }).encode('utf-8')

    with pytest.raises(HTTPError):
        urllib.request.urlopen(
            urllib.request.Request(
                f"{BASE_URL}/message/send",
                data=data,
                headers={'Content-Type': 'application/json'}))
Example #28
0
def test_profile_working():
    '''
    This test has all correct variables
    '''
    reset_workspace()

    req = urllib.request.Request(
        f"{BASE_URL}/user/profile?token=6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b&u_id=1"
    )
    req.get_method = lambda: 'GET'
    response = json.load(urllib.request.urlopen(req))['user']

    assert response['email'] == '*****@*****.**'
    assert response['name_first'] == 'Kennan'
    assert response['name_last'] == 'Wong'
Example #29
0
def test_user_profile_setemail_working():
    reset_workspace()

    details = reg_user1()

    data = json.dumps({
        'token': details['token'],
        'email': "*****@*****.**"
    }).encode('utf-8')

    req = urllib.request.Request(f"{BASE_URL}/user/profile/setemail",
                                 data=data,
                                 headers={'Content-Type': 'application/json'})
    req.get_method = lambda: 'PUT'
    response = json.load(urllib.request.urlopen(req))
    assert response == {}
Example #30
0
def test_channel_details_invalid_channel():
    'Invalid channel case'
    reset_workspace()

    # Register users
    user1 = reg_user1()
    token1 = user1['token']

    req = urllib.request.Request(f"{BASE_URL}/channel/details?token=" +
                                 str(token1) + "&channel_id=100")
    req.get_method = lambda: 'GET'

    # Attempt to get details of an invalid channel
    # Invalid channel_id = 100
    with pytest.raises(HTTPError):
        json.load(urllib.request.urlopen(req))