def test_route_name(): ''' This tests for inclusivity of '/' in the route url. ''' # reset workspace requests.post(URL_RESET) # register 3 people, fetch tokens and u_id of the users. users_data = common_set.register_3_users() # create a channel ch_id = common_set.create_channel_99(users_data[0]["token"]) # send an invite request response = requests.post(URL_INVITE + '/', data={ "token": users_data[0]["token"], "channel_id": ch_id, "u_id": users_data[1]["u_id"] }) # confirm 404 assert response.status_code == 404
def test_user_not_authorised(): ''' Tests that edit is denied when user is not the author. ''' # reset workspace requests.post(URL_RESET) # register 3 people, fetch tokens and u_id of the users. users_data = common_set.register_3_users() # create channel ch_id = common_set.create_channel_99(users_data[0]["token"]) token_0 = users_data[0]["token"] token_1 = users_data[1]["token"] # send message to channel msg1_1 = requests.post(URL_MSG_SEND, json={"token": token_0, "channel_id": ch_id, "message": \ "a"}).json()['message_id'] response = requests.put(URL_MSG_EDIT, json={"token": token_1, "message_id": msg1_1, "message": \ "new_msg_1(1)"}) assert response.status_code == 400
def test_invalid_message_id(): ''' Tests where the provided message id is an invalid string ''' # reset workspace requests.post(URL_RESET) # register 3 people, fetch tokens and u_id of the users. users_data = common_set.register_3_users() # create channel ch_id = common_set.create_channel_99(users_data[0]["token"]) token_0 = users_data[0]["token"] # send message to channel msg1_1 = requests.post(URL_MSG_SEND, json={"token": token_0, "channel_id": ch_id, "message": \ "a"}).json()['message_id'] response = requests.put(URL_MSG_EDIT, json={"token": token_0, "message_id": "NOT_VALID_ID", \ "message": "new_msg_1(1)"}) assert response.status_code == 400 or response.status_code == 500
def test_already_reacted(): '''Test error occurs where user already reacted''' # reset workspace requests.post(URL_RESET) # register 3 people, fetch tokens and u_id of the users. users_data = common_set.register_3_users() # create channel ch_id = common_set.create_channel_99(users_data[0]["token"]) token_0 = users_data[0]["token"] # send message to channel msg1_1 = requests.post(URL_MSG_SEND, json={"token": token_0, "channel_id": ch_id, "message": \ "a"}).json()['message_id'] requests.post(URL_MSG_REACT, json={"token": token_0, "message_id": msg1_1, \ "react_id": 1}).json() response = requests.post(URL_MSG_REACT, json={"token": token_0, "message_id": msg1_1, \ "react_id": 1}) assert response.status_code == 400
def test_bad_data_leave(): ''' 1. Sends token of a non-member. 2. Sends an invalid channel id. ''' # reset workspace requests.post(URL_RESET) # register 3 people, fetch tokens and u_id of the users. users_data = common_set.register_3_users() # create a channel ch_id = common_set.create_channel_99(users_data[0]["token"]) # invite 2 people invite_user_channel( users_data[0]["token"], ch_id, users_data[2]["u_id"], URL_INVITE) # send invalid token response = requests.post( URL_LEAVE, json={"token": users_data[1]["token"], "channel_id": ch_id}) assert response.status_code == 400 # send invalid ch_id with ownr, which should result in bad request response = requests.post(URL_LEAVE, json={"token": users_data[0]["token"], "channel_id": 124124}) assert response.status_code == 400 # send invalid ch_id with user[1], which should result in bad request response = requests.post(URL_LEAVE, json={"token": users_data[1]["token"], "channel_id": 124124}) assert response.status_code == 400
def test_invalid_token(): # reset workspace requests.post(URL_RESET) # register 3 people, fetch tokens and u_id of the users. users_data = common_set.register_3_users() # create 2 channels ch_id = common_set.create_channel_99(users_data[0]["token"]) data_in = { "token": users_data[1]["token"], "name": "FOX_NEWS", "is_public": True } ch_id2 = requests.post(URL_CREATE, json=data_in).json()['channel_id'] # send 3 messages to each channel + 1 extra into channel2 response = requests.post(URL_MSG_SEND, json={ "token": "NOT_VALID_TOKEN", "channel_id": ch_id2, "message": "another message" }) assert response.status_code == 400
def test_user_not_in_channel(): # reset workspace requests.post(URL_RESET) # register 3 people, fetch tokens and u_id of the users. users_data = common_set.register_3_users() token_0 = users_data[0]["token"] token_1 = users_data[1]["token"] token_2 = users_data[2]["token"] # ch_id: owner = token_0; member = token_0, token_2 # ch_id2: owner = token1; member = token_1 ch_id = common_set.create_channel_99(users_data[0]["token"]) data_in = {"token": users_data[1]["token"], "name": "FOX_NEWS", "is_public": True} ch_id2 = requests.post(URL_CREATE, json=data_in).json()['channel_id'] invite_user_channel(token_0, ch_id, users_data[2]['u_id'], URL_INVITE) # send 3 messages to each channel + 1 extra into channel2 msg1_1 = requests.post(URL_MSG_SEND, json={"token": token_0, "channel_id": ch_id, "message": "a"}).json()['message_id'] msg2_1 = requests.post(URL_MSG_SEND, json={"token": token_0, "channel_id": ch_id, "message": "b"}).json()['message_id'] msg3_1 = requests.post(URL_MSG_SEND, json={"token": token_0, "channel_id": ch_id, "message": "c"}).json()['message_id'] msg1_2 = requests.post(URL_MSG_SEND, json={"token": token_1, "channel_id": ch_id2, "message": "d"}).json()['message_id'] msg2_2 = requests.post(URL_MSG_SEND, json={"token": token_1, "channel_id": ch_id2, "message": "e"}).json()['message_id'] msg3_2 = requests.post(URL_MSG_SEND, json={"token": token_1, "channel_id": ch_id2, "message": "f"}).json()['message_id'] # pin some messages requests.post(URL_MSG_PIN, json={"token": token_0, "message_id": msg1_1}) requests.post(URL_MSG_PIN, json={"token": token_1, "message_id": msg1_2}) requests.post(URL_MSG_PIN, json={"token": token_0, "message_id": msg3_2}) # unpin some messages where you arent in the channel response = requests.post(URL_MSG_UNPIN, json={"token": token_1, "message_id": msg1_1}) response = requests.post(URL_MSG_UNPIN, json={"token": token_2, "message_id": msg1_2}) assert response.status_code == 400
def test_bad_data_rem_owner(): ''' 1. Sends a token of a non owner. 2. Sends an invalid channel id. 3. Sends an invalid u_id. ''' # reset workspace requests.post(URL_RESET) # register 3 people, fetch tokens and u_id of the users. users_data = common_set.register_3_users() # create a channel ch_id = common_set.create_channel_99(users_data[0]["token"]) # non-owner trying to remove himself as owner response = requests.post(URL_REMOWNER, json={"token": users_data[2]["token"], "channel_id": ch_id, "u_id": users_data[2]["u_id"]}) assert response.status_code == 400 # send invalid ch_id, which will result in an internal error response = requests.post(URL_REMOWNER, json={"token": users_data[0]["token"], "channel_id": 124124, "u_id": users_data[2]["u_id"]}) assert response.status_code == 400 # send invalid u_id response = requests.post(URL_REMOWNER, json={"token": users_data[0]["token"], "channel_id": ch_id, "u_id": "wow"}) assert response.status_code == 400
def test_basic(): ''' This is a sanity test for correct output based on all-correct input. Input = Correct token, u_id and permission_id Expected Output = {} with no errors. ''' # debug mode # pdb.set_trace() # reset workspace requests.post(URL_RESET) # register 3 people, fetch tokens and u_id of the users. users_data = common_set.register_3_users() # ch_id: owner = token_0; member = token_0, token_2 # ch_id2: owner = token1; member = token_1 ch_id = common_set.create_channel_99(users_data[0]["token"]) data_in = {"token": users_data[1]["token"], "name": "FOX_NEWS", "is_public": True} ch_id2 = requests.post(URL_CREATE, json=data_in).json()['channel_id'] token_0 = users_data[0]["token"] token_1 = users_data[1]["token"] token_2 = users_data[2]["token"] invite_user_channel(token_0, ch_id, users_data[2]['u_id'], URL_INVITE) # send 3 messages to each channel + 1 extra into channel2 msg1_1 = requests.post(URL_MSG_SEND, json={"token": token_0, "channel_id": ch_id, "message": \ "a"}).json()['message_id'] msg2_1 = requests.post(URL_MSG_SEND, json={"token": token_0, "channel_id": ch_id, "message": \ "b"}).json()['message_id'] msg3_1 = requests.post(URL_MSG_SEND, json={"token": token_0, "channel_id": ch_id, "message": \ "c"}).json()['message_id'] msg1_2 = requests.post(URL_MSG_SEND, json={"token": token_1, "channel_id": ch_id2, "message": \ "d"}).json()['message_id'] msg2_2 = requests.post(URL_MSG_SEND, json={"token": token_1, "channel_id": ch_id2, "message": \ "e"}).json()['message_id'] msg3_2 = requests.post(URL_MSG_SEND, json={"token": token_1, "channel_id": ch_id2, "message": \ "f"}).json()['message_id'] # react to some messages requests.post(URL_MSG_REACT, json={"token": token_0, "message_id": msg1_1, "react_id": 1}) requests.post(URL_MSG_REACT, json={"token": token_2, "message_id": msg2_1, "react_id": 1}) requests.post(URL_MSG_REACT, json={"token": token_1, "message_id": msg1_2, "react_id": 1}) requests.post(URL_MSG_REACT, json={"token": token_2, "message_id": msg1_1, "react_id": 1}) # unreact to some messages requests.post(URL_MSG_UNREACT, json={"token": token_0, "message_id": msg1_1, "react_id": 1}) requests.post(URL_MSG_UNREACT, json={"token": token_1, "message_id": msg1_2, "react_id": 1}) # retrieve messages payload = requests.get( URL_MESSAGES + f"?token={token_0}&channel_id={ch_id}&start=0").json() payload2 = requests.get( URL_MESSAGES + f"?token={token_1}&channel_id={ch_id2}&start=0").json() # confirm output. assert payload["messages"][2]["reacts"][0]['u_ids'] == [users_data[2]['u_id']] assert payload["messages"][1]["reacts"][0]['u_ids'] == [users_data[2]['u_id']] assert payload2["messages"][2]["reacts"][0]['u_ids'] == []
def test_basic(): ''' This is a sanity test for correct output based on all-correct input. Input = Correct token, u_id and permission_id Expected Output = {} with no errors. ''' # debug mode # pdb.set_trace() # reset workspace requests.post(URL_RESET) # register 3 people, fetch tokens and u_id of the users. users_data = common_set.register_3_users() # create 2 channels ch_id = common_set.create_channel_99(users_data[0]["token"]) data_in = { "token": users_data[1]["token"], "name": "FOX_NEWS", "is_public": True } ch_id2 = requests.post(URL_CREATE, json=data_in).json()['channel_id'] token_0 = users_data[0]["token"] token_1 = users_data[1]["token"] # send 3 messages to each channel + 1 extra into channel2 msg1_1 = requests.post(URL_MSG_SEND, json={"token": token_0, "channel_id": ch_id, \ "message": "a"}).json()['message_id'] msg2_1 = requests.post(URL_MSG_SEND, json={"token": token_0, "channel_id": ch_id, \ "message": "b"}).json()['message_id'] msg3_1 = requests.post(URL_MSG_SEND, json={"token": token_0, "channel_id": ch_id, \ "message": "c"}).json()['message_id'] msg1_2 = requests.post(URL_MSG_SEND, json={"token": token_1, "channel_id": ch_id2, \ "message": "d"}).json()['message_id'] msg2_2 = requests.post(URL_MSG_SEND, json={"token": token_1, "channel_id": ch_id2, \ "message": "e"}).json()['message_id'] msg3_2 = requests.post(URL_MSG_SEND, json={"token": token_1, "channel_id": ch_id2, \ "message": "f"}).json()['message_id'] msg4_2 = requests.post(URL_MSG_SEND, json={"token": token_1, "channel_id": ch_id2, \ "message": "g"}).json()['message_id'] # edit some messages requests.delete(URL_MSG_REMOVE, json={ "token": token_0, "message_id": msg1_1 }) requests.delete(URL_MSG_REMOVE, json={ "token": token_0, "message_id": msg2_1 }) requests.delete(URL_MSG_REMOVE, json={ "token": token_1, "message_id": msg2_2 }) # retrieve messages payload = requests.get( URL_MESSAGES + f"?token={token_0}&channel_id={ch_id}&start=0").json() payload2 = requests.get( URL_MESSAGES + f"?token={token_1}&channel_id={ch_id2}&start=0").json() # confirm output. assert payload["start"] == 0 and payload["end"] == -1 assert payload["messages"][0]["message"] == "c" assert payload2["start"] == 0 and payload2["end"] == -1 assert payload2["messages"][2]["message"] == "d" assert payload2["messages"][1]["message"] == "f" assert payload2["messages"][0]["message"] == "g"
def test_basic(): ''' This is a sanity test for correct output based on all-correct input. Input = Correct token, u_id and permission_id Expected Output = {} with no errors. ''' # debug mode # pdb.set_trace() # reset workspace requests.post(URL_RESET) # register 3 people, fetch tokens and u_id of the users. users_data = common_set.register_3_users() # create 2 channels ch_id = common_set.create_channel_99(users_data[0]["token"]) data_in = { "token": users_data[1]["token"], "name": "FOX_NEWS", "is_public": True } ch_id2 = requests.post(URL_CREATE, json=data_in).json()['channel_id'] # send 3 messages to each channel + 1 extra into channel2 send_3_messages(users_data[0]["token"], ch_id) send_3_messages(users_data[1]["token"], ch_id2) token_0 = users_data[0]["token"] token_1 = users_data[1]["token"] requests.post(URL_MSG_SEND, json={ "token": token_1, "channel_id": ch_id2, "message": "another message" }) # retrieve messages payload = requests.get( URL_MESSAGES + f"?token={token_0}&channel_id={ch_id}&start=0").json() payload2 = requests.get( URL_MESSAGES + f"?token={token_1}&channel_id={ch_id2}&start=0").json() # confirm output. assert payload["start"] == 0 and payload["end"] == -1 assert payload["messages"][2]["message"] == messages_3[0] assert payload["messages"][1]["message"] == messages_3[1] assert payload["messages"][0]["message"] == messages_3[2] assert payload2["start"] == 0 and payload2["end"] == -1 assert payload2["messages"][3]["message"] == messages_3[0] assert payload2["messages"][2]["message"] == messages_3[1] assert payload2["messages"][1]["message"] == messages_3[2] assert payload2["messages"][0]["message"] == "another message" assert isinstance(payload["messages"][0]["u_id"], int) assert isinstance(payload2["messages"][0]["u_id"], int) assert payload["messages"][0]["u_id"] != payload2["messages"][0]["u_id"] # assert timestamp is within 60 seconds of the time now. assert abs(payload["messages"][0]['time_created'] - (datetime.utcnow().replace( tzinfo=timezone.utc).timestamp())) < 60 assert abs(payload2["messages"][0]['time_created'] - (datetime.utcnow().replace( tzinfo=timezone.utc).timestamp())) < 60 assert abs(payload['messages'][0]['is_pinned']) == False
def test_errors_active(): ''' Confirm http error upon appendation of backslash. ''' # reset workspace requests.post(URL_RESET) # register 3 people, fetch tokens and u_id of the users. users_data = common_set.register_3_users() # create a channel with user[0] as the owner ch_id = common_set.create_channel_99(users_data[0]["token"]) # request a standup for 30 seconds requests.post(URL_STNDUP_START, json={ "token": users_data[0]["token"], "channel_id": ch_id, "length": 30 }).json() token_ = users_data[0]["token"] # req if standup is active response = requests.get(BASE_STANDUP + f'?token={token_}&channel_id={ch_id}') assert response.status_code == 404 # reset workspace requests.post(URL_RESET) # register 3 people, fetch tokens and u_id of the users. users_data = common_set.register_3_users() # create a channel with user[0] as the owner ch_id = common_set.create_channel_99(users_data[0]["token"]) # request a standup for 30 seconds requests.post(URL_STNDUP_START, json={ "token": users_data[0]["token"], "channel_id": ch_id, "length": 30 }) token_ = users_data[0]["token"] # req if standup is active at 'actives' response = requests.get(BASE_STANDUP + '/actives' + f'?token={token_}&channel_id={ch_id}') assert response.status_code == 404 # reset workspace requests.post(URL_RESET) # register 3 people, fetch tokens and u_id of the users. users_data = common_set.register_3_users() # create a channel with user[0] as the owner ch_id = common_set.create_channel_99(users_data[0]["token"]) # request a standup for 30 seconds requests.post(URL_STNDUP_START, json={ "token": users_data[0]["token"], "channel_id": ch_id, "length": 30 }) token_ = users_data[0]["token"] # req if standup is active with invalid POST method response = requests.post(URL_STNDUP_ACTIVE + f'?token={token_}&channel_id={ch_id}') assert response.status_code == 405