def test_join(self): test = ServerWrapper('localhost') user_id1 = test.signup('l', 'k') test2 = ServerWrapper('localhost') user_id2 = test2.signup('12', '15') test3 = ServerWrapper('localhost') test3.create(user_id1, 'k', 'roomj') test4 = ServerWrapper('localhost') self.assertEqual(test4.join(user_id2, '15', 'roomj'), True)
def test_block(self): test = ServerWrapper('localhost') test.signup('lily', 'lon') test1 = ServerWrapper('localhost') user_id_block = test1.signup('windy', 'bon') test2 = ServerWrapper('localhost') test2.create(user_id_block, 'bon', 'roomb') test3 = ServerWrapper('localhost') self.assertEqual(test3.block(user_id_block, 'bon', 'lily', 'roomb'), True)
def test_unblock(self): test = ServerWrapper('localhost') user_id = test.signup('vi', 'kon') test1 = ServerWrapper('localhost') test1.signup('wow', 'pon') test2 = ServerWrapper('localhost') test2.create(user_id, 'kon', 'roomu') test3 = ServerWrapper('localhost') test3.block(user_id, 'kon', 'wow', 'roomu') test4 = ServerWrapper('localhost') self.assertEqual(test4.unblock(user_id, 'kon', 'wow', 'roomu'), True)
def test_delete(self): test = ServerWrapper('localhost') user_id = test.signup('willow', 'butter') test2 = ServerWrapper('localhost') test2.create(user_id, 'butter', 'roomd') test3 = ServerWrapper('localhost') self.assertEqual(test3.delete(user_id, 'butter', 'roomd'), True)
def test_get(self): test = ServerWrapper('localhost') user_id = test.signup('e', 'f') test2 = ServerWrapper('localhost') test2.send(user_id, 'f', 'general', 'hello') test3 = ServerWrapper('localhost') self.assertIsInstance(test3.get(user_id, 'f', 'general'), list) test4 = ServerWrapper('localhost') test4.send(user_id, 'f', 'general', 'bye') test5 = ServerWrapper('localhost') self.assertIsInstance(test5.get(user_id, 'f', 'general', 0), list)
def test_signup_login(self): test = ServerWrapper('localhost') self.assertIsInstance(test.signup('98', '6789'), int) test2 = ServerWrapper('localhost') self.assertIsInstance(test2.login('98', '6789'), int)
def test_create(self): test = ServerWrapper('localhost') user_id_create = test.signup('a', 'b') test2 = ServerWrapper('localhost') self.assertEqual(test2.create(user_id_create, 'b', 'roomc'), True)
def test_set_alias(self): test = ServerWrapper('localhost') user_id = test.signup('h', 'i') test2 = ServerWrapper('localhost') self.assertEqual(test2.set_alias(user_id, 'i', 'hh'), True)
def test_send(self): test = ServerWrapper('localhost') user_id = test.signup('c', 'd') test2 = ServerWrapper('localhost') self.assertEqual(test2.send(user_id, 'd', 'general', 'hello'), True)
class Start(): ## Constructor initiates variables and starts program def __init__(self): #Help text __location__ = os.path.realpath( os.path.join(os.getcwd(), os.path.dirname(__file__))) with open(os.path.join(__location__, "helpMsg.txt")) as myfile: self.helpText = myfile.read() self.credential_errors = { "Ok": "Success", "InvalidUsername": "******", "InvalidPassword": "******", "Invalid_pairing": "Either the password or username entered is incorrect", "DuplicateUsername": "******", "ParametersMissing": "Blank entries are not allowed" } self.wrapper = ServerWrapper(sys.argv) self.run() ## Starts login and sign up process and afterwards begins program def run(self): self.done = False print "Welcome! Type '/quit' to exit or '/help' for assistance." print "Login/sign-up below:\n" while True: tempUser = raw_input("Please enter a username: "******"InvalidUsername"] + "\n").strip() if tempUser == "/quit": self.quit() elif tempUser == "/help": print self.helpText continue tempPass = raw_input( "Please enter your password, if your account does not exist, you will be prompted to sign up: " + self.credential_errors["InvalidPassword"] + "\n").strip() if tempPass == "/quit": self.quit() elif tempPass == "/help": print self.helpText continue try: self.userId = self.wrapper.login(tempUser, tempPass) print "Login complete!" break except (invalidCredentialsException, parametersMissingException, ServerWrapperException) as ex: if type(ex) == invalidCredentialsException: print self.credential_errors["Invalid_pairing"] elif type(ex) == parametersMissingException: print self.credential_errors["ParametersMissing"] else: print "Error occured while trying to perform operation" while True: response = raw_input( "Press 's' to sign up as a new user with the credentials you enetered or press any key to retry login\n" ).strip() if response == 's': print "Beginnng sign up process..." try: self.userId = self.wrapper.signup( tempUser, tempPass) print "Sign up complete, you are now logged in" self.done = True break except (duplicateUsernameException, invalidUsernameException, invalidPasswordException, parametersMissingException, ServerWrapperException) as exx: if type(ex) == duplicateUsernameException: print self.credential_errors[ "DuplicateUsername"] elif type(ex) == invalidUsernameException: print self.credential_errors["InvalidUsername"] elif type(ex) == invalidPasswordException: print self.credential_errors["InvalidPassword"] elif type(ex) == ServerWrapperException: print "Error occured while trying to perform operation" else: print self.credential_errors[ "ParametersMissing"] elif response == "/quit": self.quit() elif response == "/help": print self.helpText continue else: break if self.done: break print self.helpText print "This guide can be accessed again with the /help command\n" self.cred = Credentials(self.userId, tempPass) self.chat = Chat(self.cred, self.wrapper) self.chat.run() ## Quits program def quit(self): sys.exit()