def test_join_channel_trying_to_join_channel_that_you_are_already_a_part_of(): server = Camelot_Server() mydb = Camelot_Database() client_request = json.loads( json.dumps({"join_channel": ["Client Team", "Server Team"]}, indent=4)) expected_response = json.dumps({ "error": "The user has already joined one or more of the channels they were trying to join again." }) mydb.create_account("username", "password") server, mydb = login(server, mydb, "username", "password") mydb.create_channel("Client Team", "username") mydb.create_channel("Server Team", "username") server.join_channel(mydb, client_request) result = server.join_channel(mydb, client_request) assert expected_response == result mydb.empty_tables()
def test_join_channel_not_logged_in(): server = Camelot_Server() mydb = Camelot_Database() client_request = json.loads( json.dumps({"join_channel": ["Client Team", "Server Team"]}, indent=4)) expected_response = json.dumps( {"error": "A user must be signed in to access this function."}, indent=4) result = server.join_channel(mydb, client_request) assert expected_response == result mydb.empty_tables()
def test_join_channel_no_channels_available(): server = Camelot_Server() mydb = Camelot_Database() client_request = json.loads( json.dumps({"join_channel": ["Client Team", "Server Team"]}, indent=4)) expected_response = json.dumps( {"error": "No channels exist in the database."}, indent=4) mydb.create_account('username', 'password') server, mydb = login(server, mydb, 'username', 'password') result = server.join_channel(mydb, client_request) assert expected_response == result mydb.empty_tables()
def test_join_channel_user_tries_to_send_json_containing_zero_channels_to_join( ): server = Camelot_Server() mydb = Camelot_Database() client_request = json.loads(json.dumps({"join_channel": []}, indent=4)) expected_response = json.dumps( {"error": "No channels were given for the user to join."}, indent=4) mydb.create_account("username", "password") server, mydb = login(server, mydb, "username", "password") mydb.create_channel("Client Team", "username") mydb.create_channel("Server Team", "username") result = server.join_channel(mydb, client_request) assert expected_response == result mydb.empty_tables()
def test_join_channel_that_doesnt_exist(): server = Camelot_Server() mydb = Camelot_Database() client_request = json.loads( json.dumps({"join_channel": ["Client Team", "Server Team"]}, indent=4)) expected_response = json.dumps( {"error": "The user is trying to join a channel that doesn't exist."}, indent=4) mydb.create_account('username', 'password') server, mydb = login(server, mydb, 'username', 'password') mydb.create_channel("TestChannel", "username") result = server.join_channel(mydb, client_request) assert expected_response == result mydb.empty_tables()
def test_join_channel_success(): server = Camelot_Server() mydb = Camelot_Database() client_request = json.loads( json.dumps({"join_channel": ["Client Team", "Server Team"]}, indent=4)) expected_response = json.dumps( { "channels_joined": ["Client Team", "Server Team"], "user": "******" }, indent=4) mydb.create_account("username", "password") server, mydb = login(server, mydb, "username", "password") mydb.create_channel("Client Team", "username") mydb.create_channel("Server Team", "username") result = server.join_channel(mydb, client_request) assert expected_response == result mydb.empty_tables()