def test_search_user(db): assert users.add_user( ("test1", "*****@*****.**", "tester", "one"), db) is True assert users.search_user("test1", db) == { 'id': 1, 'NAME': 'tester', 'EMAIL': '*****@*****.**', 'USER_ID': 'test1', 'LASTNAME': 'one' } assert users.search_user("test2", db) is None
def test_search_user(user): ''' Test each aspect of search_user ''' # Return empty dictionary for non existant users data = users.search_user(user[0]) assert data['user_id'] is None users.add_user(*user) # Sucessfully find a user data = users.search_user(user[0]) assert data['user_id'] == user[0] assert data['user_email'] == user[1] assert data['user_name'] == user[2] assert data['user_last_name'] == user[3]
def search_user(user_id, db): ''' Requirements: - If the user is found, returns the corresponding user's info - Otherwise, it returns None. ''' return users.search_user(user_id, db)
def add_status(status_info, db=None): status_id = status_info[0] user_id = status_info[1] status_text = status_info[2] if status_data_valid(status_id, user_id, status_text) is False: return False if users.search_user( user_id, db) is None: # Can't add a status to a non-existant user_id return False # db['statuses'].create_index(['STATUS_ID'], unique=True) if db['statuses'].find_one(STATUS_ID=status_id) is not None: return False try: db['statuses'].insert(STATUS_ID=status_id, USER_ID=user_id, STATUS_TEXT=status_text) except IntegrityError: return False return True
def test_users_interfaces(user): ''' Test functions that interface with users ''' assert main.search_user(user[0]) is None assert main.add_user(*user) assert main.update_user(*user) assert main.search_user(user[0]) == users.search_user(user[0]) assert main.delete_user(user[0])
def search_user(user_id): ''' Searches for a user in the database Requirements: - If the user is found, returns the corresponding User. - Otherwise, it returns None. ''' logger.info('Searching for an User') user = users.search_user(user_id) if user['user_id']: return user return None
def test_modify_user(db): assert users.add_user( ("test1", "*****@*****.**", "tester", "one"), db) is True assert users.modify_user("test1", "*****@*****.**", "tester", "one", db) is True assert users.modify_user("user_id_not_in_db", "*****@*****.**", "tester", "me", db) is False assert users.search_user("test1", db) == { 'id': 1, 'NAME': 'tester', 'EMAIL': '*****@*****.**', 'USER_ID': 'test1', 'LASTNAME': 'one' }
def main(): """ Main que gestiona todo el funcionamiento del sistema. :return: """ # Creamos un parser para los argumentos de entrada del programa parser = argparse.ArgumentParser(description="Cliente SecureBox") # Ayuda # Gestion de usuarios parser.add_argument("--create_id", nargs=2, metavar=('name', 'email')) parser.add_argument("--search_id", nargs=1, metavar=('data')) parser.add_argument("--delete_id", nargs=1, metavar=('user_id')) # Gestion de ficheros parser.add_argument("--upload", nargs=1, metavar=('file')) parser.add_argument("--source_id", nargs=1, metavar=('user_id')) parser.add_argument("--dest_id", nargs=1, metavar=('user_id')) parser.add_argument("--list_files", action='store_true') parser.add_argument("--download", nargs=1, metavar=('file_id')) parser.add_argument("--delete_file", nargs=1, metavar=('file_id')) # Gestion del cifrado y firmado de documentos parser.add_argument("--encrypt", nargs=1, metavar=('file')) parser.add_argument("--sign", nargs=1, metavar=('file')) parser.add_argument("--enc_sign", nargs=1, metavar=('file')) # Se parsean los argumentos args = parser.parse_args() # Si no se encuentan los parametros suficientes if len(sys.argv) < 2: print( "Se necesitan mas argumentos de entrada para ejecutar el programa." ) print("Si necesita ayuda ejecute el programa con la flag --help") return # Gestion de usuarios if args.create_id: users.register_user(name=args.create_id[0], email=args.create_id[1], token=token) elif args.search_id: users.search_user(data_search=args.search_id[0], token=token) elif args.delete_id: users.delete_user(user_id=args.delete_id[0], token=token) # Gestion de cifrado y firmado elif args.encrypt and args.dest_id: key = users.get_public_key(user_id=args.dest_id[0], token=token) crypto.encrypt(file=args.encrypt[0], public_key_receiver=key) elif args.sign: crypto.sign(file=args.sign[0]) elif args.enc_sign and args.dest_id: key = users.get_public_key(user_id=args.dest_id[0], token=token) crypto.encrypt_and_sign(file=args.enc_sign[0], public_key_receiver=key) # Gestion de ficheros elif args.upload and args.dest_id: key = users.get_public_key(user_id=args.dest_id[0], token=token) files.upload_file(file=args.upload[0], public_key_dest=key, token=token) elif args.list_files: files.list_files(token=token) elif args.download and args.source_id: key = users.get_public_key(user_id=args.source_id[0], token=token) files.download_file(file_id=args.download[0], public_key_receiver=key, token=token) elif args.delete_file: files.delete_file(file_id=args.delete_file[0], token=token) else: print("Comando no soportado") print( "Revise con el comando --help los comandos que puede ejecutar el cliente SecureBox." )