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_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_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 == {}
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 == {}
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_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'}))
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_remove1(): ''' Test a valid use of message.remove ''' 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.Request(f"{BASE_URL}/message/remove", data=data, headers={'Content-Type': 'application/json'}) req.get_method = lambda: 'DELETE' response = json.load(urllib.request.urlopen(req)) assert response == {}
def test_invalid_react_id(): ''' Test a user reacting with an invalid reactId ''' 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'], 'react_id': 2 }).encode('utf-8') with pytest.raises(HTTPError): urllib.request.urlopen( urllib.request.Request( f"{BASE_URL}/message/react", data=data, headers={'Content-Type': 'application/json'}))
def test_not_reacted(): ''' Test unreacting to a message they have already reacted to ''' 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'], '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'}))
def test_unauth_remove1(): ''' Test if a user is attempting to remove a message from a channel that they are not a part of ''' reset_workspace() user1 = reg_user1() user2 = reg_user2() channel1 = create_ch1(user1) msg1 = send_msg1(user1, channel1) data = json.dumps({ 'token': user2['token'], 'message_id': msg1['message_id'] }).encode('utf-8') req = urllib.request.Request(f"{BASE_URL}/message/remove", data=data, headers={'Content-Type': 'application/json'}) req.get_method = lambda: 'DELETE' with pytest.raises(HTTPError): json.load(urllib.request.urlopen(req))
def test_remove2(): ''' The admin of a channel attempting to remove another users message ''' reset_workspace() user1 = reg_user1() user2 = reg_user2() channel1 = create_ch1(user1) invite_to_channel(user1, user2, channel1) msg1 = send_msg1(user2, channel1) data = json.dumps({ 'token': user1['token'], 'message_id': msg1['message_id'] }).encode('utf-8') req = urllib.request.Request(f"{BASE_URL}/message/remove", data=data, headers={'Content-Type': 'application/json'}) req.get_method = lambda: 'DELETE' response = json.load(urllib.request.urlopen(req)) assert response == {}