def test_basic_start(): ''' Start a standup in a channel with valid inputs. ''' # 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 result = requests.post(URL_STNDUP_START, json={ "token": users_data[0]["token"], "channel_id": ch_id, "length": 30 }).json() # Use this to confirm time finish > now # now_time = datetime.now().replace(tzinfo=timezone.utc).timestamp() # confirm return assert isinstance(result["time_finish"], int)
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 a invite request invite_user_channel( users_data[0]["token"], ch_id, users_data[2]["u_id"], URL_INVITE) # add a user[2] as an owner common_set.add_user_owner( users_data[0]["token"], ch_id, users_data[2]["u_id"]) # confirm http error, code = 404 response = requests.post(URL_REMOWNER + '/', json={ "token": users_data[0]["token"], "channel_id": ch_id, "u_id": users_data[2]["u_id"]}) assert response.status_code == 404
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"]) # invite users to channel invite_user_channel(users_data[0]["token"], ch_id, users_data[1]["u_id"], URL_INVITE) invite_user_channel(users_data[0]["token"], ch_id, users_data[2]["u_id"], URL_INVITE) token = users_data[0]["token"] response = requests.get(URL_DETAILS + '/' + f'?token={token}&channel_id={ch_id}') assert response.status_code == 404
def test_route_name_send(): ''' Send message to appended / 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() token_ = users_data[0]["token"] # create a channel with user[0] as the owner ch_id = common_set.create_channel_99(token_) # request a standup for 30 seconds requests.post(URL_STNDUP_START, json={ "token": token_, "channel_id": ch_id, "length": 5 }).json() # send 3 messages response = requests.post(URL_STNDUP_SEND + '/', json={ "token": token_, "channel_id": ch_id, "message": messages_3[0] }) assert response.status_code == 404
def test_active_route_name(): ''' 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(URL_STNDUP_ACTIVE + '/' + f'?token={token_}&channel_id={ch_id}') assert response.status_code == 404
def test_active_basic(): ''' Confirm we get the correct output on valid input and start standup. ''' # 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"]) # start a standup for 30 seconds result = 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(URL_STNDUP_ACTIVE + f'?token={token_}&channel_id={ch_id}').json() assert response["is_active"] assert response["time_finish"] == result["time_finish"]
def test_bad_input_active(): ''' 1. Send invalid token 2. Send 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 with user[0] as the owner ch_id = common_set.create_channel_99(users_data[0]["token"]) # check if a standup is active with non channel member user[1] token_bad = 215125125125 token_ = users_data[0]["token"] response = requests.get(URL_STNDUP_ACTIVE + f'?token={token_bad}&channel_id={ch_id}') assert response.status_code == 400 # check if standup is active in a non-existent channel response = requests.get(URL_STNDUP_ACTIVE + f'?token={token_}&channel_id={52521125}') assert response.status_code == 400
def test_user_not_authorised(): ''' User is not author of message ''' # 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.delete(URL_MSG_REMOVE, json={ "token": token_1, "message_id": msg1_1 }) 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() # create 2 channels ch_id = common_set.create_channel_99(users_data[0]["token"]) data_in = { "token": users_data[1]["token"], "name": "new", "is_public": True } ch_id2 = requests.post(URL_CREATE, json=data_in).json()['channel_id'] # send 3 messages to channels which users are not in. response = requests.post(URL_MSG_SEND, json={ "token": users_data[1]['token'], "channel_id": ch_id, "message": "another message" }) response2 = requests.post(URL_MSG_SEND, json={ "token": users_data[2]["token"], "channel_id": ch_id2, "message": "another message" }) assert response.status_code == 400 assert response2.status_code == 400
def test_user_not_owner_of_slackr_or_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'] requests.post(URL_MSG_PIN, json={"token": token_0, "message_id": msg1_1}) requests.post(URL_MSG_PIN, json={"token": token_2, "message_id": msg1_2}) requests.post(URL_MSG_PIN, json={"token": token_0, "message_id": msg3_2}) # unpin some messages where you arent owner of channel or slackr response = requests.post(URL_MSG_UNPIN, json={"token": token_2, "message_id": msg1_1}) assert response.status_code == 400
def test_bad_data_join(): ''' 1. Sends an invalid token. 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"]) # send invalid token response = requests.post( URL_JOIN, json={"token": 1221451512, "channel_id": ch_id}) assert response.status_code == 400 # send invalid ch_id, which should result in a bad request response = requests.post( URL_JOIN, json={"token": users_data[0]["token"], "channel_id": 124124}) assert response.status_code == 400
def test_errors(): ''' Testing for correct http error returns. Input = invalid route from admin Expected Ouput = corresponding http error codes ''' # 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 a join request to base channel. if this doesnt raise an error, # there are serious problems with the implementation response = requests.post( BASE_CHANNEL+'/', json={"token": users_data[1]["token"], "channel_id": ch_id}) assert response .status_code == 404 # confirm http error, code = 404 response = requests.post( BASE_CHANNEL+'/joining', json={"token": users_data[1]["token"], "channel_id": ch_id}) assert response .status_code == 404 # send with wrong method response = requests.get( URL_JOIN, json={"token": users_data[1]["token"], "channel_id": ch_id}) assert response .status_code == 405
def test_bad_data_details(): ''' 1. Sends a token of a non owner. 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"]) token = users_data[1]["token"] # non-owner trying to get channel details response = requests.get(URL_DETAILS + f'?token={token}&channel_id={ch_id}') assert response.status_code == 400 # send invalid ch_id response = requests.post(URL_ADDOWNER, json={ "token": users_data[0]["token"], "channel_id": 124124, "u_id": users_data[2]["u_id"] }) assert response.status_code == 400
def test_basic(): ''' Test correct input -> output ''' # 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 users to channel invite_user_channel(users_data[0]["token"], ch_id, users_data[1]["u_id"], URL_INVITE) invite_user_channel(users_data[0]["token"], ch_id, users_data[2]["u_id"], URL_INVITE) token = users_data[0]["token"] # send a details request payload = requests.get(URL_DETAILS + f'?token={token}&channel_id={ch_id}').json() # confirm output assert payload["name"] == "FOX_NEWS" assert payload["owner_members"] and payload["all_members"]
def test_basic_send(): ''' Start a standup and send a message to it. ''' # 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_ = users_data[0]["token"] # create a channel with user[0] as the owner ch_id = common_set.create_channel_99(token_) # request a standup for 30 seconds requests.post(URL_STNDUP_START, json={ "token": token_, "channel_id": ch_id, "length": 5 }) # send 3 messages response = requests.post(URL_STNDUP_SEND, json={ "token": token_, "channel_id": ch_id, "message": messages_3[0] }) assert response.json() == {} response = requests.post(URL_STNDUP_SEND, json={ "token": token_, "channel_id": ch_id, "message": messages_3[1] }) assert response.json() == {} response = requests.post(URL_STNDUP_SEND, json={ "token": token_, "channel_id": ch_id, "message": messages_3[2] }) assert response.json() == {} # confirm that these messages will be in the channel after 3 seconds sleep(5) result = requests.get( URL_MESSAGES + f"?token={token_}&channel_id={ch_id}&start={0}").json() # confirm output. assert result["start"] == 0 and result["end"] == -1 assert result["messages"][0][ "message"] == "\nxdlamoDfondofpigsW: I am fond of pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals.\nxdlamoDfondofpigsW: Give a man a fish, feed him for a day. Poison a man's fish, and you'll never have to feed him again.\nxdlamoDfondofpigsW: Maybe the real virus is human beings. We infect every corner of the planet and turn everything into factory, killing off other living things"
def test_basic(): ''' This is a sanity test for correct output based on all-correct input. ''' # 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() token_0 = users_data[0]["token"] token_1 = users_data[1]["token"] token_2 = users_data[2]["token"] # owner of slackr = token_0 # 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 - first is owner of channel and slackr, second is owner of channel, third is owner of slackr 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 the messages - first is owner of channel and slackr, second is owner of channel, third is owner of slackr requests.post(URL_MSG_UNPIN, json={"token": token_0, "message_id": msg1_1}) requests.post(URL_MSG_UNPIN, json={"token": token_1, "message_id": msg1_2}) requests.post(URL_MSG_UNPIN, json={"token": token_0, "message_id": msg3_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["messages"][0]["is_pinned"] == False assert payload["messages"][1]["is_pinned"] == False assert payload2["messages"][0]["is_pinned"] == False assert payload2["messages"][2]["is_pinned"] == False
def test_errors_send(): ''' Send message to appended / 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() token_ = users_data[0]["token"] # create a channel with user[0] as the owner ch_id = common_set.create_channel_99(token_) # request a standup for 30 seconds requests.post(URL_STNDUP_START, json={ "token": token_, "channel_id": ch_id, "length": 10 }).json() # send to base url response = requests.post(BASE_STANDUP, json={ "token": token_, "channel_id": ch_id, "message": messages_3[0] }) assert response.status_code == 404 # send to to sending response = requests.post(BASE_STANDUP + '/sending', json={ "token": token_, "channel_id": ch_id, "message": messages_3[0] }) assert response.status_code == 404 # send to to sent response = requests.post(BASE_STANDUP + '/sent', json={ "token": token_, "channel_id": ch_id, "message": messages_3[0] }) assert response.status_code == 404 # send with wrong method response = requests.get( URL_STNDUP_SEND + f"?token={token_}&channel_id={ch_id}&message={messages_3[0]}") assert response.status_code == 405
def test_errors_start(): ''' Tests possible redirection routes that shouldn't be implemented. ''' # 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 result = requests.post(BASE_STANDUP, json={ "token": users_data[0]["token"], "channel_id": ch_id, "length": 30 }) assert result.status_code == 404 # request a standup for 30 seconds result = requests.post(BASE_STANDUP + '/starting', json={ "token": users_data[0]["token"], "channel_id": ch_id, "length": 30 }) assert result.status_code == 404 # request a standup for 30 seconds result = requests.post(BASE_STANDUP + '/starts', json={ "token": users_data[0]["token"], "channel_id": ch_id, "length": 30 }) assert result.status_code == 404 # confirm invalid method result. result = requests.get(URL_STNDUP_START, json={ "token": users_data[0]["token"], "channel_id": ch_id, "length": 30 }) assert result.status_code == 405
def test_bad_data_invite(): ''' 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"]) # send an invite request to user[1] invite_user_channel(users_data[0]["token"], ch_id, users_data[1]["u_id"], URL_INVITE) # non-owner user[1] trying to invite user[2] response = requests.post(URL_INVITE, json={ "token": users_data[1]["token"], "channel_id": 124124, "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_INVITE, json={ "token": users_data[1]["token"], "channel_id": 124124, "u_id": users_data[2]["u_id"] }) assert response.status_code == 400 # send invalid u_id response = requests.post(URL_INVITE, json={ "token": users_data[1]["token"], "channel_id": ch_id, "u_id": 12551 }) assert response.status_code == 400
def test_errors(): ''' Testing for correct http error returns. Input = invalid route from admin Expected Ouput = corresponding http error codes ''' # 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 to user[2] response = requests.post(BASE_CHANNEL, data={ "token": users_data[0]["token"], "channel_id": ch_id, "u_id": users_data[1]["u_id"] }) # confirm 404 assert response.status_code == 404 # send an invite request to user[2] response = requests.post(BASE_CHANNEL + '/invites', data={ "token": users_data[0]["token"], "channel_id": ch_id, "u_id": users_data[1]["u_id"] }) # confirm 404 assert response.status_code == 404 # confirm http error, code = 405 # send an invite request to user[2] response = requests.get(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 == 405
def test_user_not_in_channel(): '''Test error occurs where user is not in the 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() # 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 where you arent in the channel response = requests.post(URL_MSG_REACT, json={"token": token_1, "message_id": msg1_1, \ "react_id": 1}) response2 = requests.post(URL_MSG_REACT, json={"token": token_0, "message_id": msg1_2, \ "react_id": 1}) response3 = requests.post(URL_MSG_REACT, json={"token": token_2, "message_id": msg1_2, \ "react_id": 1}) assert response.status_code == 400 assert response2.status_code == 400 assert response3.status_code == 400
def test_bad_input_send(): ''' 1. Send invalid token 2. Send invalid channel_id 3. Send a message '**5000, too long. ''' # 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"]) # check if a standup is active with non channel member user[1] token_bad = 215125125125 token_ = users_data[0]["token"] # send message with invalid token response = requests.post(URL_STNDUP_SEND, json={ "token": token_bad, "channel_id": ch_id, "message": messages_3[0] }) assert response.status_code == 400 # send message with invalid channel_id response = requests.post(URL_STNDUP_SEND, json={ "token": token_, "channel_id": 125125132, "message": messages_3[0] }) assert response.status_code == 400 # send a huge message response = requests.post(URL_STNDUP_SEND, json={ "token": token_, "channel_id": ch_id, "message": 'a' * 1001 }) assert response.status_code == 400
def test_already_unpinned(): # 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.post(URL_MSG_UNPIN, json={"token": token_0, "message_id": msg1_1}) assert response.status_code == 400
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 a join request response = requests.post( URL_JOIN+'/', json={"token": users_data[1]["token"], "channel_id": ch_id}) assert response .status_code == 404
def test_errors(): ''' Testing for correct http error returns. Input = invalid route from admin Expected Ouput = corresponding http error codes ''' # 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_user_channel(users_data[0]["token"], ch_id, users_data[2]["u_id"], URL_INVITE) token = users_data[0]["token"] # confirm http error, code = 404 # send base url response = requests.get(BASE_CHANNEL + f'?token={token}&channel_id={ch_id}') assert response.status_code == 404 # confirm http error, code = 404 # send base url with 'detail' response = requests.get(BASE_CHANNEL + '/detail' + f'?token={token}&channel_id={ch_id}') assert response.status_code == 404 # confirm http error, code = 405 # send with post method, i.e. not get. response = requests.post(URL_DETAILS, json={ "token": token, "channel_id": ch_id, "u_id": users_data[2]["u_id"] }) assert response.status_code == 405
def test_bad_input_start(): ''' 1. Send token of non-owner 2. Send invalid channel_id 3. Send invalid length ''' # 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 by user[1] result = requests.post(URL_STNDUP_START, json={ "token": users_data[1]["token"], "channel_id": ch_id, "length": 30 }) assert result.status_code == 400 # request a standup for 30 seconds in an invalid channel result = requests.post(URL_STNDUP_START, json={ "token": users_data[0]["token"], "channel_id": 12251251, "length": 30 }) assert result.status_code == 400 # request a standup for 30 seconds with an invalid length result = requests.post(URL_STNDUP_START, json={ "token": users_data[0]["token"], "channel_id": ch_id, "length": -55 }) assert result.status_code == 400
def test_basic(): ''' Test correct input -> output ''' # 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 payload = invite_user_channel(users_data[0]["token"], ch_id, users_data[1]["u_id"], URL_INVITE) # confirm output assert payload == {}
def test_basic(): ''' Test correct input -> output ''' # 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 a join request payload = requests.post( URL_JOIN, json={"token": users_data[1]["token"], "channel_id": ch_id}) # confirm output assert payload.json() == {}
def test_errors(): ''' Testing for correct http error returns. Input = invalid route Expected Ouput = corresponding http error codes ''' # 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 a invite request invite_user_channel( users_data[0]["token"], ch_id, users_data[2]["u_id"], URL_INVITE) # add a user[2] as an owner common_set.add_user_owner( users_data[0]["token"], ch_id, users_data[2]["u_id"]) # confirm http error, code = 404 # send base url response = requests.post(BASE_CHANNEL, json={ "token": users_data[0]["token"], "channel_id": ch_id, "u_id": users_data[2]["u_id"]}) assert response.status_code == 404 # confirm http error, code = 404 # send base url appended with '/removal', i.e. a possible user mistake. response = requests.post(BASE_CHANNEL + '/removal', json={ "token": users_data[0]["token"], "channel_id": ch_id, "u_id": users_data[2]["u_id"]}) assert response.status_code == 404 # confirm http error, code = 405 # send base url response = requests.get(URL_REMOWNER, json={ "token": users_data[0]["token"], "channel_id": ch_id, "u_id": users_data[2]["u_id"]}) assert response.status_code == 405
def test_not_reacted(): '''Test error occurs where user has not 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'] response = requests.post(URL_MSG_UNREACT, json={"token": token_0, "message_id": msg1_1, \ "react_id": 1}) assert response.status_code == 400