Beispiel #1
0
def test_server_channel_details():
    """ Http testing for channel/details. """
    user_dict = server_create_user("*****@*****.**", "password1", "Bob",
                                   "Ross")

    test_channel = server_create_channel(user_dict['token'], "Test Rum Ham",
                                         True)

    response = urllib.request.urlopen(
        f"{get_url()}/channel/details?token={user_dict['token']}" +
        f"&channel_id={test_channel['channel_id']}")

    payload = json.load(response)

    assert payload["name"] == "Test Rum Ham"
    assert payload["all_members"] == [{
        "u_id":
        user_dict["u_id"],
        "name_first":
        "Bob",
        "name_last":
        "Ross",
        "profile_img_url":
        "http://127.0.0.1:8080/static/bean.jpg"
    }]
    assert payload["owner_members"] == [{
        "u_id":
        user_dict["u_id"],
        "name_first":
        "Bob",
        "name_last":
        "Ross",
        "profile_img_url":
        "http://127.0.0.1:8080/static/bean.jpg"
    }]
Beispiel #2
0
def test_server_channel_messages():
    """ Http testing for channel/messages. """
    user_dict = server_create_user("*****@*****.**", "password1", "Bob",
                                   "Ross")

    test_channel = server_create_channel(user_dict['token'], "Test Rum Ham",
                                         True)

    payload = json.dumps({
        "token": user_dict['token'],
        "channel_id": test_channel['channel_id'],
        "message": "This is a test message"
    }).encode('utf-8')

    server_message_send = urllib.request.Request(
        f"{get_url()}/message/send",
        data=payload,
        headers={"Content-Type": "application/json"},
        method="POST")

    send_response = urllib.request.urlopen(server_message_send)
    decoded_send_response = json.load(send_response)

    response = urllib.request.urlopen(
        f"{get_url()}/channel/messages?token={user_dict['token']}" +
        f"&channel_id={test_channel['channel_id']}&start={0}")

    payload = json.load(response)

    assert payload['messages'][0]['message'] == "This is a test message"
    assert payload['messages'][0]['message_id'] == decoded_send_response[
        'message_id']
    assert payload['start'] == 0
    assert payload['end'] == -1
Beispiel #3
0
def test_server_channel_invite():
    """ Http testing for channel/invite. """
    user_dict = server_create_user("*****@*****.**", "password7", "Will",
                                   "Williamson")
    user_dict_2 = server_create_user("*****@*****.**", "password7", "Bill",
                                     "William")
    c_id_dict = server_create_channel(user_dict['token'], "test_channel", True)

    server_channel_invite(user_dict_2, user_dict, c_id_dict)

    response = urllib.request.urlopen(
        f"{get_url()}/channel/details?token={user_dict['token']}" +
        f"&channel_id={c_id_dict['channel_id']}")
    details_decoded = json.load(response)

    assert details_decoded['all_members'] == [{
        "u_id":
        1,
        "name_first":
        "Will",
        "name_last":
        "Williamson",
        "profile_img_url":
        "http://127.0.0.1:8080/static/bean.jpg"
    }, {
        "u_id":
        2,
        "name_first":
        "Bill",
        "name_last":
        "William",
        "profile_img_url":
        "http://127.0.0.1:8080/static/bean.jpg"
    }]
Beispiel #4
0
def test_message_unpin():
    """
    Testing message unpin route
    """
    user_data = server_create_user("*****@*****.**", "password", "Billy",
                                   "Batson")
    channel_data = server_create_channel(user_data['token'], 'test_channel',
                                         True)
    message_str = "This is a test message!"

    message_payload = json.dumps({
        'token': user_data['token'],
        'channel_id': channel_data['channel_id'],
        'message': message_str
    }).encode('utf-8')
    #send a message by route
    send_msg_req = urllib.request.Request(
        f"{get_url()}/message/send",
        data=message_payload,
        headers={"Content-Type": "application/json"},
        method='POST')
    response = urllib.request.urlopen(send_msg_req)
    decoded_send_response = json.load(response)
    #pin the message above
    pin_payload = json.dumps({
        'token': user_data['token'],
        'message_id': decoded_send_response['message_id']
    }).encode('utf-8')
    pin_msg_req = urllib.request.Request(
        f"{get_url()}/message/pin",
        data=pin_payload,
        headers={"Content-Type": "application/json"},
        method='POST')
    urllib.request.urlopen(pin_msg_req)

    response_details = urllib.request.urlopen(
        f"{get_url()}/channel/messages?token={user_data['token']}" +
        f"&channel_id={channel_data['channel_id']}&start={0}")
    details_decoded = json.load(response_details)

    assert details_decoded['messages'][0].get('is_pinned') is True

    unpin_msg_req = urllib.request.Request(
        f"{get_url()}/message/unpin",
        data=pin_payload,
        headers={"Content-Type": "application/json"},
        method='POST')
    urllib.request.urlopen(unpin_msg_req)

    response_details = urllib.request.urlopen(
        f"{get_url()}/channel/messages?token={user_data['token']}" +
        f"&channel_id={channel_data['channel_id']}&start={0}")
    details_decoded = json.load(response_details)

    assert details_decoded['messages'][0].get('is_pinned') is False
Beispiel #5
0
def test_channels_listall():
    """ Http testing for channels_listall. """

    user = server_create_user("*****@*****.**", "password", "Toby", "Lerone")
    response = urllib.request.urlopen(
        f"{get_url()}/channels/listall?token={user['token']}")
    payload = json.load(response)

    assert payload['channels'] == []

    channel1 = server_create_channel(user['token'], "test_channel1", True)
    channel2 = server_create_channel(user['token'], "test_channel2", False)

    response = urllib.request.urlopen(
        f"{get_url()}/channels/listall?token={user['token']}")
    payload = json.load(response)

    assert len(payload['channels']) == 2
    assert payload['channels'][0]['channel_id'] == channel1['channel_id']
    assert payload['channels'][0]['name'] == 'test_channel1'
    assert payload['channels'][1]['channel_id'] == channel2['channel_id']
    assert payload['channels'][1]['name'] == 'test_channel2'
Beispiel #6
0
def test_channels_list():
    """ HTTP testing for channels_list """

    # Register users
    user1 = server_create_user("*****@*****.**", "password", "Donald", "Duck")
    user2 = server_create_user("*****@*****.**", "password", "Mickey",
                               "Mouse")

    # Create channels
    channel1 = server_create_channel(user1['token'], "test_channel1", True)
    server_create_channel(user1['token'], "test_channel2", False)

    # user2 joins channel1
    server_channel_join(user2, channel1)

    # user2 calls channels_list
    response = urllib.request.urlopen(
        f"{get_url()}/channels/list?token={user2['token']}")
    payload = json.load(response)

    assert len(payload['channels']) == 1
    assert payload['channels'][0]['channel_id'] == channel1['channel_id']
    assert payload['channels'][0]['name'] == "test_channel1"
Beispiel #7
0
def test_send_messsage():
    """
    Tesing the send message by route
    """
    user_infor = server_create_user("*****@*****.**", "password", "li",
                                    "minxin")
    channel_infor = server_create_channel(user_infor['token'], 'test_channel',
                                          True)
    token = user_infor['token']
    channel_id = channel_infor['channel_id']

    message = "Testing Testing"
    data_add = json.dumps({
        'token': token,
        'channel_id': channel_id,
        'message': message
    }).encode("utf-8")

    req = urllib.request.Request(f'{get_url()}/message/send',
                                 data=data_add,
                                 headers={"Content-Type": "application/json"},
                                 method='POST')
    response = urllib.request.urlopen(req)
    time_create_date = datetime.now().replace(microsecond=0)
    time_create = time_create_date.timestamp()
    payload = json.loads(response.read().decode('utf8'))

    response_details = urllib.request.urlopen(
        f"{get_url()}/channel/messages?token={token}" +
        f"&channel_id={channel_id}&start={0}")
    details_decoded = json.load(response_details)

    assert details_decoded['messages'] == [{
        'message_id':
        payload['message_id'],
        'u_id':
        user_infor['u_id'],
        'message':
        message,
        'time_created':
        time_create,
        'reacts': [{
            'react_id': 1,
            'u_ids': [],
            'is_this_user_reacted': False
        }],
        'is_pinned':
        False
    }]
Beispiel #8
0
def test_standup():
    """ Http testing for standup functions.
    coverage ensured by calling each function. """

    user1 = server_create_user("*****@*****.**", "password", "Lich", "King")
    user2 = server_create_user("*****@*****.**", "password", "Gold", "Tooth")
    channel = server_create_channel(user1['token'], "test_channel", True)

    # user2 joins channel
    server_channel_join(user2, channel)

    # call standup_start
    data = json.dumps({
        'token': user1['token'],
        'channel_id': channel['channel_id'],
        'length': 3
    }).encode('utf-8')
    req = urllib.request.Request(f"{get_url()}/standup/start",
                                 data=data,
                                 headers={'Content-Type': 'application/json'},
                                 method='POST')
    response = urllib.request.urlopen(req)
    standup = json.load(response)

    # call standup_active
    url = f"{get_url()}/standup/active?token={user1['token']}&channel_id={channel['channel_id']}"
    response = urllib.request.urlopen(url)
    payload = json.load(response)

    # assert that standup is active
    assert payload['is_active'] is True
    assert payload['time_finish'] == standup['time_finish']

    # call standup_send
    send_standup_message(user1['token'], channel['channel_id'], "hello")
    send_standup_message(user2['token'], channel['channel_id'], "there")

    # wait out the rest of the standup and check messages
    time.sleep(3)
    url = (f"{get_url()}/channel/messages?token={user1['token']}" +
           f"&channel_id={channel['channel_id']}&start=0")
    response = urllib.request.urlopen(url)
    payload = json.load(response)

    assert len(payload['messages']) == 1
    assert payload['messages'][0][
        'message'] == "lichking: hello\ngoldtooth: there"
Beispiel #9
0
def test_message_react():
    """
    Testing message react route
    """
    user_data = server_create_user("*****@*****.**", "password", "Billy",
                                   "Batson")
    channel_data = server_create_channel(user_data['token'], 'test_channel',
                                         True)
    message_str = "This is a test message!"

    message_payload = json.dumps({
        'token': user_data['token'],
        'channel_id': channel_data['channel_id'],
        'message': message_str
    }).encode('utf-8')
    send_msg_req = urllib.request.Request(
        f"{get_url()}/message/send",
        data=message_payload,
        headers={"Content-Type": "application/json"},
        method='POST')
    response = urllib.request.urlopen(send_msg_req)
    decoded_send_response = json.load(response)

    react_payload = json.dumps({
        'token':
        user_data['token'],
        'message_id':
        decoded_send_response['message_id'],
        'react_id':
        1
    }).encode('utf-8')
    react_msg_req = urllib.request.Request(
        f"{get_url()}/message/react",
        data=react_payload,
        headers={"Content-Type": "application/json"},
        method='POST')
    urllib.request.urlopen(react_msg_req)

    response_details = urllib.request.urlopen(
        f"{get_url()}/channel/messages?token={user_data['token']}" +
        f"&channel_id={channel_data['channel_id']}&start={0}")
    details_decoded = json.load(response_details)

    assert details_decoded['messages'][0].get(
        'reacts')[0]['u_ids'][0] == user_data['u_id']
Beispiel #10
0
def test_message_sendlater():
    """ Http testing for message/sendlater. """
    def helper_func(token):
        """ Check that there are no messages in channel """
        url = (f"{get_url()}/channel/messages?token={token}"
               f"&channel_id={channel['channel_id']}&start=0")
        response = urllib.request.urlopen(url)
        payload = json.load(response)

        assert payload['messages'] == []

    user = server_create_user("*****@*****.**", "password", "Prince", "Ali")
    channel = server_create_channel(user['token'], "test_channel", True)

    # Run test check empty a second after message_sendlater has been
    # called (but hasn't finished executing)
    new_thread = threading.Timer(1.5, helper_func, args=(user['token']))
    new_thread.start()

    # Send a message later
    time_sent = datetime.now() + timedelta(seconds=2)
    time_sent = int(time_sent.timestamp())
    data = json.dumps({
        'token': user['token'],
        'channel_id': channel['channel_id'],
        'message': "omegalul",
        'time_sent': time_sent
    }).encode('utf-8')
    req = urllib.request.Request(f"{get_url()}/message/sendlater",
                                 data=data,
                                 headers={'Content-Type': 'application/json'},
                                 method='POST')
    response = urllib.request.urlopen(req)
    json.load(response)

    url = (f"{get_url()}/channel/messages?token={user['token']}"
           f"&channel_id={channel['channel_id']}&start=0")
    response = urllib.request.urlopen(url)
    payload = json.load(response)

    assert len(payload['messages']) == 1
    assert payload['messages'][0]['message'] == "omegalul"
    assert payload['messages'][0]['time_created'] == time_sent
Beispiel #11
0
def test_workspace_reset():
    """ Test if workspace successfully reset. """
    user_dict = server_create_user("*****@*****.**", "password7", "Will",
                                   "Williamson")
    c_id_dict = server_create_channel(user_dict['token'], "test_channel", True)

    response_details = urllib.request.urlopen(
        f"{get_url()}/users/all?token={user_dict['token']}")
    details_decoded = json.load(response_details)
    assert details_decoded['users'] == [{
        "u_id": 1,
        "email": "*****@*****.**",
        'profile_img_url': 'http://127.0.0.1:8080/static/bean.jpg',
        "name_first": "Will",
        "name_last": "Williamson",
        "handle_str": "willwilliamson"
    }]

    url = (f"{get_url()}/channel/details?token={user_dict['token']}" +
           f"&channel_id={c_id_dict['channel_id']}")
    response_details = urllib.request.urlopen(url)
    details_decoded = json.load(response_details)
    assert details_decoded['all_members'] == [{
        "u_id":
        1,
        "name_first":
        "Will",
        "name_last":
        "Williamson",
        "profile_img_url":
        "http://127.0.0.1:8080/static/bean.jpg"
    }]

    clear_request = urllib.request.Request(f"{get_url()}/workspace/reset",
                                           method="POST")
    urllib.request.urlopen(clear_request)

    # We expect an error, because the user is no longer registered and so their token is invalid
    with pytest.raises(HTTPError):
        urllib.request.urlopen(
            f"{get_url()}/users/all?token={user_dict['token']}")
Beispiel #12
0
def test_search():
    """ Http testing for users/all. """
    # Register user
    user = server_create_user("*****@*****.**", "password", "Donald", "Trump")
    user2 = server_create_user("*****@*****.**", "password", "Donald",
                               "Duck")

    # create channel join and invite second user to join
    c_id_dict = server_create_channel(user['token'], "test_channel", True)

    server_channel_invite(user2, user, c_id_dict)

    # send some messages
    data = json.dumps({
        'token': user['token'],
        'channel_id': c_id_dict['channel_id'],
        'message': "HI IM NGUYEN"
    }).encode('utf-8')
    server_request = urllib.request.Request(
        f"{get_url()}/message/send",
        data=data,
        headers={"Content-Type": "application/json"},
        method="POST")
    urllib.request.urlopen(server_request)
    time_create_date = datetime.now().replace(microsecond=0)
    time_create_1 = time_create_date.timestamp()

    data = json.dumps({
        'token': user2['token'],
        'channel_id': c_id_dict['channel_id'],
        'message': "HI it's nguyen"
    }).encode('utf-8')
    server_request = urllib.request.Request(
        f"{get_url()}/message/send",
        data=data,
        headers={"Content-Type": "application/json"},
        method="POST")
    urllib.request.urlopen(server_request)
    time_create_date = datetime.now().replace(microsecond=0)
    time_create_2 = time_create_date.timestamp()

    data = json.dumps({
        'token': user['token'],
        'channel_id': c_id_dict['channel_id'],
        'message': "hi im nguyen"
    }).encode('utf-8')
    server_request = urllib.request.Request(
        f"{get_url()}/message/send",
        data=data,
        headers={"Content-Type": "application/json"},
        method="POST")
    urllib.request.urlopen(server_request)

    data = json.dumps({
        'token': user2['token'],
        'channel_id': c_id_dict['channel_id'],
        'message': "hi im nguyen"
    }).encode('utf-8')
    server_request = urllib.request.Request(
        f"{get_url()}/message/send",
        data=data,
        headers={"Content-Type": "application/json"},
        method="POST")
    urllib.request.urlopen(server_request)

    data = json.dumps({
        'token': user2['token'],
        'channel_id': c_id_dict['channel_id'],
        'message': "hello"
    }).encode('utf-8')
    server_request = urllib.request.Request(
        f"{get_url()}/message/send",
        data=data,
        headers={"Content-Type": "application/json"},
        method="POST")
    urllib.request.urlopen(server_request)

    # search for message
    payload = json.load(
        urllib.request.urlopen(
            f"{get_url()}/search?token={user['token']}&query_str=HI"))

    assert payload['messages'] == [{
        'message_id':
        1,
        'u_id':
        2,
        'message':
        "HI it's nguyen",
        'time_created':
        time_create_2,
        'reacts': [{
            'react_id': 1,
            'u_ids': [],
            'is_this_user_reacted': False
        }],
        'is_pinned':
        False
    }, {
        'message_id':
        0,
        'u_id':
        1,
        'message':
        "HI IM NGUYEN",
        'time_created':
        time_create_1,
        'reacts': [{
            'react_id': 1,
            'u_ids': [],
            'is_this_user_reacted': False
        }],
        'is_pinned':
        False
    }]
Beispiel #13
0
def test_server_channel_owner():
    """ Http testing for channel/addowner and channel/removeowner. """

    user1 = server_create_user("*****@*****.**", "password", "Robbie",
                               "Rotten")
    user2 = server_create_user("*****@*****.**", "password", "Sport", "Acus")
    channel = server_create_channel(user1['token'], "test_channel", True)

    # user2 joins channel
    server_channel_join(user2, channel)

    # user1 adds user2 as an owner
    data = json.dumps({
        'token': user1['token'],
        'channel_id': channel['channel_id'],
        'u_id': user2['u_id']
    }).encode('utf-8')
    req = urllib.request.Request(f"{get_url()}/channel/addowner",
                                 data=data,
                                 headers={'Content-Type': 'application/json'},
                                 method='POST')
    urllib.request.urlopen(req)

    # Check that user2 is an owner using channel/details
    url = f"{get_url()}/channel/details?token={user1['token']}&channel_id={channel['channel_id']}"
    response = urllib.request.urlopen(url)
    payload = json.load(response)

    assert len(payload['owner_members']) == 2
    assert payload['owner_members'][0]['u_id'] == user1['u_id']
    assert payload['owner_members'][1]['u_id'] == user2['u_id']

    # user1 removes user2 as an owner
    data = json.dumps({
        'token': user1['token'],
        'channel_id': channel['channel_id'],
        'u_id': user2['u_id']
    }).encode('utf-8')
    req = urllib.request.Request(f"{get_url()}/channel/removeowner",
                                 data=data,
                                 headers={'Content-Type': 'application/json'},
                                 method='POST')
    urllib.request.urlopen(req)

    # Check that user2 is no longer an owner using channel/details
    url = f"{get_url()}/channel/details?token={user1['token']}&channel_id={channel['channel_id']}"
    response = urllib.request.urlopen(url)
    payload = json.load(response)

    assert len(payload['owner_members']) == 1
    assert payload['owner_members'][0]['u_id'] == user1['u_id']
    assert payload['all_members'] == [{
        "u_id":
        1,
        "name_first":
        "Robbie",
        "name_last":
        "Rotten",
        "profile_img_url":
        "http://127.0.0.1:8080/static/bean.jpg"
    }, {
        "u_id":
        2,
        "name_first":
        "Sport",
        "name_last":
        "Acus",
        "profile_img_url":
        "http://127.0.0.1:8080/static/bean.jpg"
    }]
Beispiel #14
0
def test_server_channel_join_leave():
    """ Http testing for channel/leave. """
    user_dict = server_create_user("*****@*****.**", "password1", "Bob",
                                   "Ross")
    user_dict_2 = server_create_user("*****@*****.**", "password7", "Bill",
                                     "William")

    test_channel = server_create_channel(user_dict['token'], "Test Rum Ham",
                                         True)

    payload = json.dumps({
        "token": user_dict_2['token'],
        "channel_id": test_channel['channel_id']
    }).encode('utf-8')

    server_channel_join(user_dict_2, test_channel)

    response = urllib.request.urlopen(
        f"{get_url()}/channel/details?token={user_dict['token']}" +
        f"&channel_id={test_channel['channel_id']}")
    details_decoded = json.load(response)

    assert details_decoded['all_members'] == [{
        "u_id":
        1,
        "name_first":
        "Bob",
        "name_last":
        "Ross",
        "profile_img_url":
        "http://127.0.0.1:8080/static/bean.jpg"
    }, {
        "u_id":
        2,
        "name_first":
        "Bill",
        "name_last":
        "William",
        "profile_img_url":
        "http://127.0.0.1:8080/static/bean.jpg"
    }]

    assert details_decoded['owner_members'] == [{
        "u_id":
        1,
        "name_first":
        "Bob",
        "name_last":
        "Ross",
        "profile_img_url":
        "http://127.0.0.1:8080/static/bean.jpg"
    }]

    payload = json.dumps({
        "token": user_dict_2['token'],
        "channel_id": test_channel['channel_id']
    }).encode('utf-8')

    server_channel_leave = urllib.request.Request(
        f"{get_url()}/channel/leave",
        data=payload,
        headers={"Content-Type": "application/json"},
        method="POST")
    urllib.request.urlopen(server_channel_leave)

    response = urllib.request.urlopen(
        f"{get_url()}/channel/details?token={user_dict['token']}" +
        f"&channel_id={test_channel['channel_id']}")
    details_decoded = json.load(response)

    assert details_decoded['all_members'] == [{
        "u_id":
        1,
        "name_first":
        "Bob",
        "name_last":
        "Ross",
        "profile_img_url":
        "http://127.0.0.1:8080/static/bean.jpg"
    }]
    assert len(details_decoded['all_members']) == 1