def testCorrectLogin(self): self.assertDictEqual( {"username": TEST_USER, "password": TEST_PASSWORD}, LHServer.loginUserFromDatabase(TEST_USER, TEST_PASSWORD) )
def testWrongLogin(self): self.assertFalse(LHServer.loginUserFromDatabase(TEST_USER, TEST_PASSWORD + "abc"))
# Logout self.telnetConnection.write(json.dumps({"command": "logout", "data": TEST_USER})) line = self.telnetConnection.read_until("\n") self.assertDictEqual({"data": True, "command": "logoutResponse"}, json.loads(line)) def testLoginFailed(self): self.telnetConnection.write( json.dumps({"command": "login", "data": {"username": TEST_USER, "password": TEST_PASSWORD + "abc"}}) ) line = self.telnetConnection.read_until("\n") self.assertDictEqual({"data": False, "command": "loginResponse"}, json.loads(line)) def testIllegalCommand(self): self.telnetConnection.write("Just illegal data") line = self.telnetConnection.read_until("\n") self.assertDictContainsSubset({"command": "error"}, json.loads(line)) if __name__ == "__main__": # Setup the LHServer LHServer.setup(username=USERNAME, password=PASSWORD, database=DATABASE, port=PORT) # Start the server reactor_process = Process(target=LHServer.reactor.run, kwargs={"installSignalHandlers": 0}) reactor_process.daemon = True reactor_process.start() # Run tests unittest.main() # Stop the server LHServer.stopServer() reactor_process.join()