def test_admin_permission_change(url): """ Tests whether an owner of Flockr is an owner of all channels they've joined """ # Jack and Jill register Jack = sf.register_user("Jack", "Smith", "*****@*****.**", "jackjack123", url) Jill = sf.register_user("Jill", "Smith", "*****@*****.**", "jilljill123", url) sf.assert_different_people(Jack, Jill) # Jack makes Jill an owner/admin of Flockr change_perm1 = sf.change_permission(Jack['token'], Jill['u_id'], 1, url) assert change_perm1 == {} # Jack creates and joins a channel "Jack"s channel" chan1 = sf.create_channel(Jack['token'], "Jack's Channel", True, url) assert chan1 == 1 # Jill joins the channel join1 = sf.join_channel(Jill['token'], chan1, url) assert join1 == {} # Jack checks for the owners of "Jack's Channel" channel_details = sf.channel_info(Jack['token'], chan1, url) assert channel_details["name"] == "Jack's Channel" assert channel_details["owner_members"][0]["u_id"] == Jack["u_id"] assert channel_details["all_members"][0]["u_id"] == Jack["u_id"] assert channel_details["all_members"][1]["u_id"] == Jill["u_id"]
def test_http_hangman(url): creator = sf.register_user("The", "Creator", "*****@*****.**", "gamers", url) guesser = sf.register_user("The", "Guesser", "*****@*****.**", "Kahoot", url) sf.assert_different_people(creator, guesser) chan1 = sf.create_channel(creator['token'], "channel name", True, url) assert chan1 == 1 join1 = sf.join_channel(guesser['token'], chan1, url) assert join1 == {} msg1 = "/hangman start fut" hang_mess = sf.send_message(creator['token'], chan1, msg1, url) assert hang_mess == 1 msg2 = "/guess a" mess2 = sf.send_message(guesser['token'], chan1, msg2, url) assert mess2 == 2 msg3 = "/guess u" mess3 = sf.send_message(guesser['token'], chan1, msg3, url) assert mess3 == 3 msg4 = "/guess u" mess4 = sf.send_message(guesser['token'], chan1, msg4, url) assert mess4['message'] == "<p>Cannot guess already revealed letters</p>" assert mess4['code'] == 400 msg5 = "/guess F" mess5 = sf.send_message(guesser['token'], chan1, msg5, url) assert mess5 == 5 # Hangman already started in this channel msg6 = "/hangman start dontworkpls" mess6 = sf.send_message(guesser['token'], chan1, msg6, url) assert mess6['message'] == "<p>A hangman session is already active</p>" assert mess6['code'] == 400 # Create new channel and start hangman there chan2 = sf.create_channel(guesser['token'], "hangman time", False, url) assert chan2 == 2 inv1 = sf.invite_channel(guesser['token'], chan2, creator['u_id'], url) assert inv1 == {} msg7 = msg6 mess7 = sf.send_message(guesser['token'], chan2, msg7, url) assert mess7 == 7 msg8 = "/guess t" mess8 = sf.send_message(guesser['token'], chan1, msg8, url) assert mess8 == 8 msg9 = msg6 mess9 = sf.send_message(guesser['token'], chan1, msg9, url) assert mess9 == 9
def test_list_users_and_channels(url): """ Tests listing of all channels, channels of the user and all users on Flockr """ # Jack and Jill register Jack = sf.register_user("Jack", "Smith", "*****@*****.**", "jackjack123", url) Jill = sf.register_user("Jill", "Smith", "*****@*****.**", "jilljill123", url) sf.assert_different_people(Jack, Jill) # Jack gets a list of all users users = sf.user_list(Jack['token'], url) assert users[0]["u_id"] == Jack["u_id"] assert users[1]["u_id"] == Jill["u_id"] # Jack creates and joins the channels "First" and "Second" chan1 = sf.create_channel(Jack['token'], "First", True, url) chan2 = sf.create_channel(Jack['token'], "Second", True, url) assert chan1 == 1 assert chan2 == 2 # Jack calls for a list of all channels in Flockr listall1 = sf.channel_listall(Jack['token'], url) channels_listall_result = [ { "channel_id" : 1, "name" : "First", }, { "channel_id": 2, "name" : "Second" } ] assert listall1 == channels_listall_result # Jill joins "Second Channel" join1 = sf.join_channel(Jill['token'], chan2, url) assert join1 == {} # Jill calls for a list of all channels she has joined listin1 = sf.channel_list(Jill['token'], url) channels_list_result = [ { "channel_id": 2, "name" : "Second" } ] # assert listin1 == {"channels" : channels_list_result} assert listin1 == channels_list_result
def test_admin_permission_change_invalid(url): """ Tests invalid inputs of changing owner/admin permissions """ # Jack and Jill register Jack = sf.register_user("Jack", "Smith", "*****@*****.**", "jackjack123", url) Jill = sf.register_user("Jill", "Smith", "*****@*****.**", "jilljill123", url) sf.assert_different_people(Jack, Jill) # Jack attempts change Jill's permissions with nvalid permission_id value change_perm1 = sf.change_permission(Jack['token'], Jill['u_id'], 3, url) assert change_perm1["message"] == "<p>Permission id is not a valid value</p>" assert change_perm1["code"] == 400 # Jack attempts to make a non-existent member an owner/admin change_perm2 = sf.change_permission(Jack['token'], "invalid_uid", 1, url) assert change_perm2["message"] == "<p>Target user does not exist</p>" assert change_perm2["code"] == 400 # Jill attempts to change Jack"s permissions change_perm3 = sf.change_permission(Jill['token'], Jack['u_id'], 2, url) assert change_perm3["message"] == "<p>User is not owner of Flockr</p>" assert change_perm3["code"] == 400
def test_message_interactions(url): """ Tests every different thing you can do to a message """ # Testing with owner permissinos user1 = sf.register_user("Jeffrey", "Hoits", "*****@*****.**", "gambling", url) assert user1['u_id'] == 1 chan1 = sf.create_channel(user1['token'], "Testing testing 123", False, url) assert chan1 == 1 mess1 = sf.send_message(user1['token'], chan1, "RADIOACTIVE -- DO NOT TOUCh", url) assert mess1 == 1 pin1 = sf.pin_message(user1['token'], mess1, url) assert pin1 == {} react1 = sf.react_message(user1['token'], mess1, 1, url) assert react1 == {} edit1 = sf.edit_message(user1['token'], mess1, 'pls stay pinned', url) assert edit1 == {} messages = sf.check_messages(user1['token'], chan1, 0, url) assert messages['messages'][0]['is_pinned'] unpin1 = sf.unpin_message(user1['token'], mess1, url) assert unpin1 == {} unreact1 = sf.unreact_message(user1['token'], mess1, 1, url) assert unreact1 == {} # Testing with member permissions user2 = sf.register_user("Member", "ofGroup", "*****@*****.**", "member", url) sf.assert_different_people(user1, user2) pin2 = sf.pin_message(user2['token'], mess1, url) assert pin2['message'] == "<p>User is not owner of channel</p>" assert pin2['code'] == 400 react2 = sf.react_message(user1['token'], mess1, 1, url) assert react2 == {} edit2 = sf.edit_message(user1['token'], mess1, 'pls stay pinned', url) assert edit2 == {} messages = sf.check_messages(user1['token'], chan1, 0, url) assert not messages['messages'][0]['is_pinned'] unpin2 = sf.unpin_message(user2['token'], mess1, url) assert unpin2['message'] == "<p>Message is not currently pinned</p>" assert unpin2['code'] == 400 unreact1 = sf.unreact_message(user1['token'], mess1, 1, url) assert unreact1 == {} rem1 = sf.remove_message(user2['token'], mess1, url) assert rem1['message'] == "<p>User is not creator or owner</p>" assert rem1['code'] == 400 rem2 = sf.remove_message(user1['token'], mess1, url) assert rem2 == {}
def test_edit_profile_and_messages(url): """ Tests editing everything that can be edited """ # Fred and Alan register Fred = sf.register_user("Fred","Smith", "*****@*****.**", "Freddo", url) Alan = sf.register_user("Alan","Borm", "*****@*****.**", "Boromir", url) sf.assert_different_people(Fred, Alan) # Fred creates channel 'welcome' chan1 = sf.create_channel(Fred['token'], "Welcome", True, url) assert chan1 == 1 # Fred sends message to empty channel mess1 = sf.send_message(Fred["token"], chan1, "Hello nobody :(", url) assert mess1 == 1 # Alan join channel join1 = sf.join_channel(Alan['token'], chan1, url) assert join1 == {} # Fred deletes message rem1 = sf.remove_message(Fred['token'], mess1, url) assert rem1 == {} # Alan sends a message mess2 = sf.send_message(Alan['token'], chan1, "Good morning Fred!", url) assert mess2 == 2 # Fred changes his name unsuccessfully name_change1 = sf.change_name(Fred['token'], "I wonder how long my name should be. Is there a limit or nah", "Wazco", url) assert name_change1['message'] == "<p>First name is invalid</p>" assert name_change1['code'] == 400 # Fred changes his last name successfully name_change2 = sf.change_name(Fred['token'], "Howard", "Wazco", url) assert name_change2 == {} # Fred changes his handle unsuccessfully handle_change1 = sf.change_handle(Fred['token'], "AlanBorm", url) assert handle_change1['message'] == "<p>Handle already in use</p>" assert handle_change1['code'] == 400 # Fred tries again handle_change2 = sf.change_handle(Fred['token'], "HW", url) assert handle_change2['message'] == "<p>Handle is invalid</p>" assert handle_change2['code'] == 400 # Fred successfully changes his handle handle_change3 = sf.change_handle(Fred['token'], "WazcoWizard", url) assert handle_change3 == {} # Alan edits his original message edit1 = sf.edit_message(Alan['token'], mess2, "Good morning Howard!", url) assert edit1 == {} # Ex-Fred (now Howard) gets annoyed (sends attempted message) msg = "A" * 1001 mess3 = sf.send_message(Fred['token'], chan1, msg, url) assert mess3["message"] == "<p>Invalid message</p>" assert mess3['code'] == 400 # Howard is now angry (sends messages) msg2 = ">:( " * 200 mess4 = sf.send_message(Fred['token'], chan1, msg2, url) assert mess4 == 3 # Alan checks the message history using channel_messages history1 = sf.check_messages(Alan['token'], chan1, 0, url) assert history1["messages"][0]["message"] == ">:( " * 200 assert history1["messages"][1]["message"] == "Good morning Howard!" assert history1["start"] == 0 assert history1["end"] == -1
def test_editing_removing_messages(url): """ Tests a user going on a message editing and removing spree: * auth_register * channels_create (public) * channel_join * channe_messages * message_send * message_remove * message_edit * channel_addowner """ # Paul and Seal register Paul = sf.register_user("Paul", "Schlamp", "*****@*****.**", "m23rdewf2DE", url) Seal = sf.register_user("Seal", "Sire", "*****@*****.**", "phlem$#PHLEM", url) sf.assert_different_people(Paul, Seal) # Paul creates a channel "General" chan1 = sf.create_channel(Paul['token'], "Misc", True, url) assert chan1 == 1 # Seal joins the channel "Misc" join1 = sf.join_channel(Seal['token'], chan1, url) assert join1 == {} # Paul and Seal send messages to each other in "Misc" msg1 = "First rule in general channel do not talkaboutgeneralchannel" mess1 = sf.send_message(Seal['token'], chan1, msg1, url) assert mess1 == 1 msg2 = "Second Rule ... First rule again" mess2 = sf.send_message(Paul['token'], chan1, msg2, url) assert mess2 == 2 msg3 = "You seem bad at this" mess3 = sf.send_message(Seal['token'], chan1, msg3, url) assert mess3 == 3 # Paul addes Seal as an owner of "Misc" addowner1 = sf.add_owner(Paul['token'], chan1, Seal['u_id'], url) assert addowner1 == {} # Seal calls for a list of all messages in "Misc" messages1 = sf.check_messages(Seal['token'], chan1, 0, url) assert len(messages1['messages']) == 3 assert messages1["end"] == -1 # Seal edits a message msg4 = "New message YaYaYaYa" for sent_message in messages1['messages']: edit = sf.edit_message(Seal['token'], sent_message['message_id'], msg4, url) assert edit == {} messages2 = sf.check_messages(Seal['token'], chan1, 0, url) assert len(messages2['messages']) == 3 assert messages2["end"] == -1 # Check message_edit worked for sent_message in messages2["messages"]: assert sent_message["message"] == msg4 # Slam registers and joins the channel "Misc" Slam = sf.register_user("Slam","Bam","*****@*****.**", "rightEOUS!ath", url) join2 = sf.join_channel(Slam['token'], chan1, url) assert join2 == {} # Slam sends a message to "Misc" msg5 = "I love your channel" mess4 = sf.send_message(Slam['token'], chan1, msg5, url) assert mess4 == 4 # Slam deletes their message """Mimics how a person would find and delete a message""" search1 = sf.search_message(Slam['token'], "love", url) assert len(search1) == 1 for message in search1: found_message = message['message_id'] rem1 = sf.remove_message(Slam['token'], found_message, url) assert rem1 == {} # Slam sends a new message to "Misc" msg6 = "I REALLY love your channel" mess5 = sf.send_message(Slam['token'], chan1, msg6, url) assert mess5 == 5 # Seal removes the message rem2 = sf.remove_message(Seal['token'], mess5, url) assert rem2 == {} messages3 = sf.check_messages(Seal['token'], chan1, 0, url) assert len(messages3['messages']) == 3
def test_hostile_takeover(url): """ Tests using commands with different channel permissions and changing profile attributes """ # Joe and Henry register accounts Joe = sf.register_user("Joe", "Gostt", "*****@*****.**", "sdrawkcab", url) Henry = sf.register_user("Henry", "Prill", "*****@*****.**", "word pass", url) sf.assert_different_people(Joe, Henry) # Henry makes a new channel (General) chan1 = sf.create_channel(Henry['token'], "General", False, url) assert chan1 == 1 # Henry invites Joe invite1 = sf.invite_channel(Henry['token'], chan1, Joe['u_id'], url) assert invite1 == {} # Joe says "goodbye" mess1 = sf.send_message(Joe['token'], chan1, "Goodbye >:)", url) assert mess1 == 1 # Joe (owner of Flockr) removes Henry's owner privileges remowner1 = sf.remove_owner(Joe['token'], chan1, Henry['u_id'], url) assert remowner1 == {} # Henry tries to get owner privileges back addowner1 = sf.add_owner(Henry['token'], chan1, Henry['u_id'], url) assert addowner1['message'] == "<p>User is not owner of channel</p>" assert addowner1['code'] == 400 # Henry leaves channel leave1 = sf.leave_channel(Henry['token'], chan1, url) assert leave1 == {} # Henry logs out logout1 = sf.logout_user(Henry['token'], url) assert logout1 == { "is_success" : True } # Joe edits message edit1 = sf.edit_message(Joe['token'], mess1, "I win.", url) assert edit1 == {} # Joe leaves channel leave2 = sf.leave_channel(Joe['token'], chan1, url) assert leave2 == {} # Joe creates new channel (General) chan2 = sf.create_channel(Joe['token'], "General", False, url) assert chan2 == 2 # Joe changes his name name1 = sf.change_name(Joe['token'], "The", "KING", url) assert name1 == {} # Joe changes his email email1 = sf.change_email(Joe['token'], '*****@*****.**', url) assert email1 == {} # Joe changes his handle handle1 = sf.change_handle(Joe['token'], "WeAreNumberOne", url) assert handle1 == {} # Joe logs off logout2 = sf.logout_user(Joe['token'], url) assert logout2 == { "is_success" : True } # Joe logs in successfully new_Joe = sf.login_user("*****@*****.**", "sdrawkcab", url) assert len(new_Joe) == 2 assert new_Joe["token"] is not None assert new_Joe["token"] != Joe["token"] # Could potentially fail 1 in 100,000 times assert new_Joe["u_id"] == Joe["u_id"] # Joe admired his new profile profile1 = sf.check_profile(new_Joe['token'], new_Joe['u_id'], url) expected_user = { "name_first" : "The", "name_last" : "KING", "u_id" : 1, "email" : "*****@*****.**", "handle_str" : "WeAreNumberOne", "profile_img_url" : '' } #expected_profile ={ "user" : expected_user } assert profile1 == expected_user#expected_profile # Joe logs out logout3 = sf.logout_user(new_Joe['token'], url) assert logout3 == { "is_success" : True }