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_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_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 == {}
Beispiel #4
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'}))
Beispiel #5
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 == {}
Beispiel #6
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_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'}))
Beispiel #8
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
Beispiel #9
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'}))
Beispiel #10
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 == {}
Beispiel #11
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_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_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'}))
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 == {}
Beispiel #15
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 == {}
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_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_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 == {}
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'}))
def test_list():
    '''
    Test for successful case of channels list
    '''
    reset_workspace()

    user1 = reg_user1()
    reg_user2()

    create_ch1(user1)

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

    req.get_method = lambda: 'GET'

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

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

    assert expected in response
Beispiel #21
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
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'}))
def test_others2():
    'Other errors, when start is negative'
    reset_workspace()

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

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

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

    with pytest.raises(HTTPError):
        json.load(urllib.request.urlopen(req))
Beispiel #24
0
def test_invalid_channel():
    'Invalid channel 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'}))
    # Addowner
    data2 = json.dumps({
        'token': token1,
        'channel_id': channel_id,
        'u_id': u_id2
    }).encode('utf-8')
    urllib.request.urlopen(
        urllib.request.Request(f"{BASE_URL}/channel/addowner",
                               data=data2,
                               headers={'Content-Type': 'application/json'}))

    # Invalid channel_id = 100
    data3 = 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/addowner",
                data=data3,
                headers={'Content-Type': 'application/json'}))
Beispiel #25
0
def test_invalid_message_id():
    'test error case'
    reset_workspace()

    user1 = reg_user1()
    channel1 = create_ch1(user1)  #pylint: disable = W0612

    data1 = json.dumps({
        'token': user1['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_channel_messages():
    'Getting messages'
    reset_workspace()

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

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

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

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

    assert payload['messages'] == []
    assert payload['start'] == 0
    assert payload['end'] == -1
def test_no_active():
    'error case'

    reset_workspace()

    user1 = reg_user1()
    channel1 = create_ch1(user1)

    data2 = json.dumps({
        'token': user1['token'],
        'channel_id': channel1['channel_id'],
        '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_admin_user_remove_successful3():
    'Successful case with messages'
    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'}
    ))

    # Send a message
    send_msg1(user2, channel_info)

    data2 = json.dumps({
        'token': token1,
        'u_id': u_id2
    }).encode('utf-8')

    req = urllib.request.Request(
        f"{BASE_URL}/admin/user/remove",
        data=data2,
        headers={'Content-Type': 'application/json'}
    )
    req.get_method = lambda: 'DELETE'
    payload = json.load(urllib.request.urlopen(req))

    assert payload == {}
def test_send1():
    '''
    Test valid use of message_send
    '''
    reset_workspace()

    user1 = reg_user1()
    ch1 = create_ch1(user1)

    data = json.dumps({
        'token': user1['token'],
        'channel_id': ch1['channel_id'],
        'message': 'testing'
    }).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)

    assert payload['message_id'] == 1
Beispiel #30
0
def test_channel_details_unauthorised():
    'User is not a member case'
    reset_workspace()

    # Register users
    user1 = reg_user1()
    user2 = reg_user2()
    token2 = user2['token']

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

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

    # AccessError when we try to get details of channel where the user isn't a member
    # user2 isn't a member
    with pytest.raises(HTTPError):
        json.load(urllib.request.urlopen(req))