def test_admin_but_non_members(): channel_id2 = channel_create(token2, "Example channel 2", True)["channel_id"] m_id = message_send(token2, channel_id2, "test_message")["message_id"] message_pin(token2, m_id) with pytest.raises(AccessError): message_unpin(token1, m_id)
def test_message_pin(): ## set up AuthRegDict = auth_register("*****@*****.**", "123456", "Hayden", "Smith") token = AuthRegDict['token'] AuthRegDict2 = auth_register("*****@*****.**", "1123456", "Hayen", "Sith") token2 = AuthRegDict['token'] publicChan = channels_create(token, "public", True) publicId = publicChan['channel_id'] message_send(token, publicId, "message one") messageDic = channel_messages(token, publicChan, 0) ###messageDic{ message_id, u_id, message, time_created, is_unread } firstId = messageDic[message_id][0] firstMessage = messageDic[message][0] ## set up done message_pin(token, firstId) message_unpin(token,firstId)
def test_message_unpinFAILinvalidMessage(): ## set up AuthRegDict = auth_register("*****@*****.**", "123456", "Hayden", "Smith") token = AuthRegDict['token'] AuthRegDict2 = auth_register("*****@*****.**", "1123456", "Hayen", "Sith") token2 = AuthRegDict['token'] publicChan = channels_create(token, "public", True) publicId = publicChan['channel_id'] message_send(token, publicId, "message one") messageDic = channel_messages(token, publicChan, 0) ###messageDic{ message_id, u_id, message, time_created, is_unread } firstId = messageDic[message_id][0] fakeId = "asdfg123#" firstMessage = messageDic[message][0] ## set up done with pytest.raises(AccessError, match=r"*"): message_unpin(token, fakeId)
def test_message_unpin_non_admin(): # test an invalid message Id case with pytest.raises(ValueError): message_unpin(token2, 1)
def test_message_unpin_invalid_msg_id(): with pytest.raises(ValueError): message_unpin(token1, -1)
def test_message_already_unpinned(): with pytest.raises(ValueError): message_unpin(token1, 0)
def test_message_unpin(): message_send(token1, 0, "test_message") message_send(token1, 0, "test_message2") # assume message id 2 message_send(token1, 0, "test_message3") # assume message id 2 message_pin(token1, 0) assert message_unpin(token1, 0) == {}