def toAddClient(self): try: return Client(int(self.getArg(1)), self.getArg(2)) except ValueError as ve: raise LibraryException("Client CNP should be an integer.")
aux_i = i time.sleep(0.02) sock.sendto(('confirmado').encode(), addr) # print(">>> janela de 10 pacotes recebidos com sucesso!") # Tratar protocolo UDP aqui i = i + 1 j = j + 1 print("Fim teste Download") # Teste latencia print("Teste Latencia iniciado...") while sock.recv(config.bufferUdp) != finalData: pass sock.send(data) print("Fim teste latencia") sock.close() param = sys.argv[1:] ip, port = parameters(param) cli = Client(ip, port) print("IP: " + ip + " Port: " + str(port)) print("\nIniciando testador de velocidade de conexao\n\n\n") testTcp(cli) time.sleep(1) testUdp(cli) print("Encerrando Internet-tester")
def testCommand(self): ''' Method to test the getter and the setter of the Command class ''' try: Command("addBook|||") assert False except LibraryException: pass try: Command("addBook|Title||") assert False except LibraryException: pass try: Command("addBook||Description|") assert False except LibraryException: pass try: Command("addBook|||Author") assert False except LibraryException: pass try: Command("addBook|Title|Description|") assert False except LibraryException: pass try: Command("addBook|Title||Author") assert False except LibraryException: pass try: Command("addBook||Description|Author") assert False except LibraryException: pass command = Command("addBook|Title|Description|Author") assert command.toAddBook(1) == Book(1, "Title", "Description", "Author") try: Command("Cosmin") assert False except LibraryException: pass try: Command("addClient|1960715060015") assert False except LibraryException: pass try: command = Command("addClient|numarul25|Rusu Cosmin") command.toAddClient() assert False except LibraryException: pass try: command = Command("removeBook|numarul25") command.toRemoveBook() assert False except LibraryException: pass try: command = Command("removeBook|1|Title") command.toRemoveBook() assert False except LibraryException: pass try: command = Command("removeClient|numarul25") command.toRemoveClient() assert False except LibraryException: pass try: command = Command("removeClient") command.toRemoveClient() assert False except LibraryException: pass try: command = Command("removeClient|1960715060|Rusu Cosmin") command.toRemoveClient() assert False except LibraryException: pass try: command = Command("updateCnp|numarul25|newValue") command.toUpdateCnp() assert False except LibraryException: pass try: command = Command("updateCnp|1960715060015|newValue") command.toUpdateCnp() assert False except LibraryException: pass try: command = Command("updateCnp|numarul25|1960715060015") command.toUpdateCnp() assert False except LibraryException: pass try: command = Command("updateCnp||") command.toUpdateCnp() assert False except LibraryException: pass try: command = Command("updateCnp||1960715060015") command.toUpdateCnp() assert False except LibraryException: pass try: command = Command("updateCnp|1960715060015|") command.toUpdateCnp() assert False except LibraryException: pass Command("updateCnp|2960715060015|1960715060015") try: command = Command("updateName|numarul25|newValue") command.toUpdateName() assert False except LibraryException: pass try: command = Command("updateName||") command.toUpdateName() assert False except LibraryException: pass try: command = Command("updateName||1960715060015") command.toUpdateName() assert False except LibraryException: pass try: command = Command("updateName|1960715060015|") command.toUpdateName() assert False except LibraryException: pass try: command = Command("updateTitle|numarul25|NewValue") command.toUpdateTitle() assert False except LibraryException: pass try: command = Command("updateTitle||") command.toUpdateTitle() assert False except LibraryException: pass try: command = Command("updateTitle||1960715060015") command.toUpdateTitle() assert False except LibraryException: pass try: command = Command("updateTitle|1960715060015|") command.toUpdateTitle() assert False except LibraryException: pass try: command = Command("updateTitle|numarul25|NewValue") command.toUpdateTitle() assert False except LibraryException: pass try: command = Command("updateAuthor|numarul25|NewValue") command.toUpdateAuthor() assert False except LibraryException: pass try: command = Command("updateAuthor||") command.toUpdateAuthor() assert False except LibraryException: pass try: command = Command("updateAuthor||1960715060015") command.toUpdateAuthor() assert False except LibraryException: pass try: command = Command("updateAuthor|1960715060015|") command.toUpdateAuthor() assert False except LibraryException: pass try: command = Command("updateAuthor|numarul25|NewValue") command.toUpdateAuthor() assert False except LibraryException: pass command = Command("addClient|1960715060015|Rusu Cosmin") assert command.toAddClient() == Client(1960715060015, "Rusu Cosmin")
def setUp(self): self.test_client = Client(1, "Ivo", 200000.00, "Bitcoin mining makes me rich")
def testController(self): books = [] clients = [] testrepo = LibraryRepository(False) controller = LibraryController(testrepo) cmd = Command( "addBook|Introduction to Algorithms|The Bible for every computer scientist|Thomas H Cormen" ) controller.addBook(cmd.toAddBook(0)) books.append(cmd.toAddBook(0)) cmd = Command( "addBook|Learning Python - 3rd Edition|A very nice book for learning Python from scratch|Mark Lutz" ) controller.addBook(cmd.toAddBook(1)) books.append(cmd.toAddBook(1)) cmd = Command("addClient|1960715060015|Rusu Cosmin") controller.addClient(cmd.toAddClient()) clients.append(cmd.toAddClient()) cmd = Command("addClient|2960715060015|Rusu Raluca") controller.addClient(cmd.toAddClient()) clients.append(cmd.toAddClient()) assert controller.getBooks() == books assert controller.getClients() == clients cmd = Command("updateName|1960715060015|Rusu Cosmin-Ionut") controller.updateClientName(int(cmd.getArg(1)), cmd.getArg(2)) clients[0].setName("Rusu Cosmin-Ionut") assert controller.getClients() == clients cmd = Command("updateCnp|2960715060015|2020715060015") controller.updateClientCnp(int(cmd.getArg(1)), int(cmd.getArg(2))) clients[1].setCnp(2020715060015) assert controller.getClients() == clients cmd = Command("removeClient|2020715060015") controller.removeClient(int(cmd.getArg(1))) clients = clients[:-1] assert controller.getClients() == clients cmd = Command("removeBook|1") controller.removeBook(int(cmd.getArg(1))) books = books[:-1] cmd = Command( "updateDescription|0|The best book on algorithms and data structures" ) controller.updateDescription(int(cmd.getArg(1)), cmd.getArg(2)) books[0].setDescription( "The best book on algorithms and data structures") assert controller.getBooks() == books controller.undo() controller.undo() assert controller.getBooks() == [ Book(0, "Introduction to Algorithms", "The Bible for every computer scientist", "Thomas H Cormen"), Book(1, "Learning Python - 3rd Edition", "A very nice book for learning Python from scratch", "Mark Lutz") ] assert controller.getClients() == [ Client(1960715060015, "Rusu Cosmin-Ionut") ] controller.redo() assert controller.getBooks() == [ Book(0, "Introduction to Algorithms", "The Bible for every computer scientist", "Thomas H Cormen") ] assert controller.getClients() == [ Client(1960715060015, "Rusu Cosmin-Ionut") ]