def inicio(self): personService = PersonService() print( "\n Bienvenido, a continuacion seleccione una de las siguientes opciones: " ) while True: print("\n1. Agregar personas") print("\n2. Modificar datos de la persona") print("\n3. Eliminar persona") print("\n4. Listar personas") print("\n5. Salir") x = int(input("\nElija una opción: ")) if x == 1: # Agregar personas p1 = Person() p1.name = str(input("Ingrese un nombre: ")) p1.surname = str(input("Ingrese un Apellido: ")) p1.age = int(input("Ingrese una edad: ")) personService.add_person(p1) elif x == 2: key = int(input("Ingrese clave que desea modificar: ")) personService.update_person(key) elif x == 3: key = int(input("Ingrese clave que desea eliminar: ")) personService.delete_person(key) elif x == 4: personService.get_personList() elif x == 5: print("...Saliendo...") break else: print(ValueError("Opcion no contemplada"))
if __name__ == '__main__': personService = PersonService() menu = Menu() opcion = Menu.menu_inicio({}) while True: if opcion == 1: numero = Menu.menu_person({}) "#Agregar personas" if numero == 1: p1 = Person() p1 = personService.crearPersona() personService.add_person(p1) "#Modificar alguna persona" if numero == 2: clave = int( input( 'Elija la clave de la persona que desea modificar: ')) personService.update_person(clave) "#Eliminar alguna persona" if numero == 3: clave = int( input('Elija la clave de la persona que desea eliminar: ')) personService.delete_person(clave) "#Listar personas" if numero == 4: personService.get_personList() if numero == 5: break if opcion == 2: break
def test_del_person(self, key): personService = PersonService() personService.delete_person(key) self.assertNotIn(key, personService.lista.keys())
#Agregamos al hermano ********************** p3 = Person() p3.name = 'niclas' p3.surname = 'pico' p3.age = 40 personService.add_person(p3) print( personService.get_personList() ) # {0: {'_name': 'FEDERICO', '_surname': 'GONZALEZ', '_age': '20'}, 1: {'_name': 'NICOLAS', '_surname': 'PICO', '_age': 33}, 2: {'_name': 'NICOLAS', '_surname': 'PICO', '_age': 40}} #Update fEDERICO p4 = Person() p4.name = 'federico' p4.surname = 'gonzalez' p4.age = '30' personService.update_person(0, p4) print( personService.get_personList() ) #{0: {'_name': 'FEDERICO', '_surname': 'GONZALEZ', '_age': '30'}, 1: {'_name': 'NICOLAS', '_surname': 'PICO', '_age': 33}, 2: {'_name': 'NICOLAS', '_surname': 'PICO', '_age': 40}} #delte person #Elimina persona segun key del dic person personService.delete_person(2) print( personService.get_personList() ) #{0: {'_name': 'FEDERICO', '_surname': 'GONZALEZ', '_age': '20'}, 1: {'_name': 'NICOLAS', '_surname': 'NICOLAS', '_age': 41}}
print("--> 2 - Agregar persona") print("--> 3 - Modificar persona") print("--> 4 - Eliminar persona") print("--> 5 - Finalizar") return int(input("\n Ingrese un numero para seleccionar una opcion: ")) if __name__ == '__main__': menu = Menu() bucle = True while bucle == True: opcion = menu.menuPersona() if opcion == 1: servicePersona = PersonService() servicePersona.get_personList() servicePersona = None if opcion == 2: servicePersona = PersonService() servicePersona.agregarPersona() servicePersona = None if opcion == 3: servicePersona = PersonService() servicePersona.update_person() servicePersona = None if opcion == 4: servicePersona = PersonService() servicePersona.delete_person() servicePersona = None if opcion == 5: bucle = False
def testC_DeletePerson(self, key): service = PersonService() service.delete_person(key, False) listKeys = Repository.person.keys() self.assertNotIn(key, listKeys)
print("3: para modificar datos de una persona") print("4: para eliminar datos de una persona\n") if entrada == 1: print("\nBase de datos\n") print(personService.get_personList()) print("") if entrada == 2: nPersons = int(input("\nCuantas personas desea agregar: ")) for i in range(nPersons): pi = Person() pi.name = input("Ingrese nombre: ") pi.surname = input("Ingrese apellido: ") pi.age = input("Ingrese edad: ") personService.add_person(pi) print("\nPersona agregada correctamente!!\n") if entrada == 3: nPersons = int(input("Cuantas personas desea modificar: ")) for i in range(nPersons): key = int(input("Inserte clave de datos de persona: \n")) pi = Person() pi.name = input("Ingrese nombre: ") pi.surname = input("Ingrese apellido: ") pi.age = input("Ingrese edad: ") personService.update_person(key, pi) print("\nPersona modificada correctamente!!\n") if entrada == 4: print("Eliminar datos de persona\n") key = int(input("Ingrese la clave de la persona a eliminar: ")) print(personService.delete_person(key)) print("\nDatos eliminados correctamente\n")
app = App() personService = PersonService() while True: opcion_person = app.menu_person() if opcion_person == 1: listPerson = personService.get_personList() for key in listPerson: print("legajo: %s -> %s" % (key, listPerson[key])) if opcion_person == 2: p = Person() p.name = input("Ingrese Nombre: ") p.surname = input("Ingrese apellido: ") p.age = int(input("Ingrese edad: ")) personService.add_person(p) if opcion_person == 3: key = int(input("Ingrese legajo de la persona: ")) p = Person() p.name = input("Ingrese Nombre: ") p.surname = input("Ingrese apellido: ") p.age = int(input("Ingrese edad: ")) personService.update_person(key, p) if opcion_person == 4: p = Person() key = int(input("Ingrese legajo de la persona: ")) personService.delete_person(key) if opcion_person < 1 or opcion_person > 4: break
# actualizamos datos de una persona if opcion == 2: print('\n1. Modificar nombre') print('2. Modificar apellido') print('3. Modificar edad') key = int(input('\nElija la key de la persona que desea modificar: ')) opcionUpdate = int(input('Elija lo que desea modificar: ')) if opcionUpdate == 1: new_name = str(input('\nNuevo nombre: ')) personService.update_person_name(key, new_name) elif opcionUpdate == 2: new_surname = str(input('Nuevo apellido: ')) personService.update_person_surname(key, new_surname) elif opcionUpdate == 3: new_age = str(input('Nueva edad: ')) personService.update_person_age(key, new_age) # eliminamos una persona del diccionario if opcion == 3: key_delete = int(input('Ingrese la key de la persona que desea borrar: ')) personService.delete_person(key_delete) print(personService.lista) # mostramos la lista if opcion == 4: print(personService.get_personList()) if opcion == 5: break
def test_delete(self): perserv = PersonService() perserv.delete_person(0) self.assertEqual(perserv.get_personList(), second={})
def test_delete(self, key): delete = PersonService() delete.delete_person(key) lista = Repository.person self.assertNotIn(key, lista.keys())