def test_users_all_http(url): resetData() clear() user1data = { 'email': '*****@*****.**', 'password': '******', 'name_first': 'Frank', 'name_last': 'Su' } user1 = requests.post(f"{url}/auth/register", json=user1data) user1_dict = user1.json() user1token = user1_dict['token'] users = getUserData() print("Users:\n", users) usersallparam = {"token": user1token} resp1 = requests.get(f"{url}/users/all", params=usersallparam) resp1_dict = resp1.json() print("\nResp\n", resp1) print("Resp1_dict:", resp1_dict) assert 'users' in resp1_dict
def test_channel_join_http(url): resetData() clear() user1data = { 'email': '*****@*****.**', 'password': '******', 'name_first': 'Frank', 'name_last': 'Su' } user1 = requests.post(f"{url}/auth/register", json=user1data) user1_dict = user1.json() user1token = user1_dict['token'] user2data = { 'email': '*****@*****.**', 'password': '******', 'name_first': 'Howard', 'name_last': 'Fog' } user2 = requests.post(f"{url}/auth/register", json=user2data) user2_dict = user2.json() user2token = user2_dict['token'] channel1 = { 'token': user1token, 'name': "Test_channel", 'is_public': True } new_channel = requests.post(f"{url}/channels/create", json=channel1) assert new_channel.status_code == 200 new_channel_dict = new_channel.json() print("\nnew_channel_dict:" , new_channel_dict) channel_id = new_channel_dict['channel_id'] channeljoindata = { "token": user2token, "channel_id": channel_id } channels = getChannelData() print("Channels_before:\n", channels) resp = requests.post(f"{url}/channel/join", json=channeljoindata) channels = getChannelData() print("Channels_after:\n", channels) resp_dict = resp.json() print("Resp:\n", resp) print("Resp_dict:\n", resp_dict)
def test_channel_addowner_http(url): resetData() user1data = { 'email': '*****@*****.**', 'password': '******', 'name_first': 'Frank', 'name_last': 'Su' } user1 = requests.post(url + 'auth/register', json=user1data) user1_dict = json.loads(user1.text) user1token = user1_dict['token'] #Code block registers a user user2data = { 'email': '*****@*****.**', 'password': '******', 'name_first': 'Howard', 'name_last': 'Fog' } user2 = requests.post(f"{url}/auth/register", json=user2data) assert user2.status_code == 200 #Extracts elements from the response dictionary and stores into varaibles user2_dict = user2.json() user2u_id = user2_dict['u_id'] #creating channel channel1 = {'token': user1token, 'name': "Test_channel", 'is_public': True} new_channel = requests.post(url + 'channels/create', json=channel1) assert new_channel.status_code == 200 new_channel_dict = json.loads(new_channel.text) channel_id = new_channel_dict['channel_id'] #inviting user2 to channel channelinvitedata = { "token": user1token, "channel_id": channel_id, "u_id": user2u_id } resp = requests.post(f"{url}/channel/invite", json=channelinvitedata) #testing addowner channel_add_owner = { 'token': user1token, 'channel_id': channel_id, 'u_id': user2u_id } resp = requests.post(f"{url}/channel/addowner", json=channel_add_owner) assert resp.status_code == 200 resp_dict = resp.json() assert resp_dict == {}
def test_standup_send_http(url): ''' A http test for channels_create ''' resetData() registerdata = { 'email': '*****@*****.**', 'password': '******', 'name_first': 'Frank', 'name_last': 'Su' } regis = requests.post(f"{url}/auth/register", json=registerdata) # regis_dict = json.loads(regis.text) regis_dict = regis.json() data1 = { 'token': regis_dict['token'], 'name': "Test_channel", 'is_public': True } #Channels create always returning none resp = requests.post(f"{url}channels/create", json=data1) resp_dict = resp.json() assert 'channel_id' in resp_dict assert resp.status_code == 200 channel_id = resp_dict['channel_id'] standup_data = { 'token': regis_dict['token'], 'channel_id': channel_id, 'length': 4 } resp = requests.post(f"{url}standup/start", json=standup_data) assert resp.status_code == 200 standup_send_data = { 'token': regis_dict['token'], 'channel_id': channel_id, 'message': "Hello" } resp = requests.post(f"{url}standup/send", json=standup_send_data) print('resp:', resp) resp_dict = resp.json() print('resp_dict:', resp_dict)
def test_channels_invite(): resetData() 'Tests for channel_invite' clear() #Creating users to create channels user1 = auth_register("*****@*****.**", "user1pass", "user1", "last1", None) user2 = auth_register("*****@*****.**", "user2pass", "user2", "last2", None) token1 = user1['token'] token2 = user2['token'] u_id1 = user1['u_id'] u_id2 = user2['u_id'] #creating channels ch_id1 = channels_create(token1, "aGreatChannel", True)['channel_id'] ch_id2 = channels_create(token2, "yetAnotherChannel", False)['channel_id'] with pytest.raises(InputError): #test for invalid channel channel_invite(token1, 50, u_id2) #test for invalid u_id channel_invite(token1, ch_id1, 3) with pytest.raises(AccessError): #test for user not already member of the channel channel_invite(token2, ch_id1, u_id1) channels = getChannelData() print("\nChannels_before:", channels) #test user invite works with public channel channel_invite(token1, ch_id1, u_id2) channels = getChannelData() print("\nChannels_after:", channels) assert user_in_channel_persist(u_id2, ch_id1) #test user invite works with private channel channel_invite(token2, ch_id2, u_id1) assert user_in_channel_persist(u_id1, ch_id2)
def test_auth_passwordreset_reset_http(url): resetData() #creating user data registerdata = { 'email': '*****@*****.**', 'password': '******', 'name_first': 'Frank', 'name_last': 'Su' } #registering user requests.post(f"{url}/auth/register", json=registerdata) #requesting a password reset resp = requests.post(f"{url}/auth/passwordreset/request", json={'email': '*****@*****.**'}) print(json.loads(resp.text)) assert resp.status_code == 200 #finding users status code users = getUserData() for user in users: if user['u_id'] == 1: reset_code = user['reset_code'] break print(users) #testing password reset resp = requests.post(f"{url}/auth/passwordreset/reset", json={ 'reset_code': reset_code, 'new_password': "******" }) print(json.loads(resp.text)) assert resp.status_code == 200 resp_dict = (json.loads(resp.text)) assert resp_dict == {}
def test_admin_userpermssion_change_http(url): ''' Send request to register two users, before requesting a permission change. Asserting returned status code is 200 ''' resetData() clear() user_1_register = { 'email': '*****@*****.**', 'password': '******', 'name_first': 'Sans', 'name_last': 'Undertale' } user_1 = requests.post(f"{url}/auth/register", json=user_1_register) user_1_details = user_1.json() user_1_token = user_1_details['token'] user_2_register = { 'email': '*****@*****.**', 'password': '******', 'name_first': 'Papyrus', 'name_last': 'Dundertale' } user_2 = requests.post(f"{url}/auth/register", json=user_2_register) user_2_details = user_2.json() user_2_id = user_2_details['u_id'] permission_change_data = { 'token': user_1_token, 'u_id': user_2_id, 'permission_id': 1 } resp = requests.post(f"{url}/admin/userpermission/change", json=permission_change_data) assert resp.status_code == 200
def test_channel_details_http(url): ''' Http test for channel_details ''' resetData() user1data = { 'email': '*****@*****.**', 'password': '******', 'name_first': 'Frank', 'name_last': 'Su' } user1 = requests.post(f"{url}/auth/register", json=user1data) user1_dict = user1.json() user1token = user1_dict['token'] channel1 = {'token': user1token, 'name': "Test_channel", 'is_public': True} new_channel = requests.post(f"{url}/channels/create", json=channel1) assert new_channel.status_code == 200 new_channel_dict = new_channel.json() print("\nnew_channel_dict:", new_channel_dict) channel_id = new_channel_dict['channel_id'] channeldetailparam = {'token': user1token, 'channel_id': channel_id} channels = getChannelData() users = getUserData() print("\nChannels:\n", channels) print("\nUsers:\n", users) resp = requests.get(f"{url}channel/details", params=channeldetailparam) print("\nresp:", resp) resp_dict = resp.json() print("\nresp_dict:", resp_dict) assert 'name' in resp_dict assert 'owner_members' in resp_dict assert 'all_members' in resp_dict
def test_channel_invite_http(url): resetData() clear() channels = getChannelData() print("\nChannels_start:\n", channels) users = getUserData() print("\nUsers_start:\n", users) #Code block each registers a user user1data = { 'email': '*****@*****.**', 'password': '******', 'name_first': 'Frank', 'name_last': 'Su' } user1 = requests.post(f"{url}/auth/register", json=user1data) user1_dict = user1.json() user1token = user1_dict['token'] #Code block registers a user user2data = { 'email': '*****@*****.**', 'password': '******', 'name_first': 'Howard', 'name_last': 'Fog' } user2 = requests.post(f"{url}/auth/register", json=user2data) assert user2.status_code == 200 #Extracts elements from the response dictionary and stores into varaibles user2_dict = user2.json() user2u_id = user2_dict['u_id'] channel1 = {'token': user1token, 'name': "Test_channel", 'is_public': True} new_channel = requests.post(f"{url}/channels/create", json=channel1) assert new_channel.status_code == 200 new_channel_dict = new_channel.json() channel_id = new_channel_dict['channel_id'] print("\nUser1token:", user1token) print("Channel_id:", channel_id) print("User2id:", user2u_id) channelinvitedata = { "token": user1token, "channel_id": channel_id, "u_id": user2u_id } resp = requests.post(f"{url}/channel/invite", json=channelinvitedata) print("\nResp:", resp) resp_dict = resp.json() print("Resp_dict:", resp_dict) channels = getChannelData() print("\nChannels_end:\n", channels) users = getUserData() print("\nUsers_end:\n", users) assert resp_dict == {}
def clear(): resetData() del users[:] del channels[:] del messages[:] return {}