def identificar(bot, update, user_data): info = update.message.text bot.sendChatAction(chat_id=update.message.chat_id, action=ChatAction.TYPING) if not user_data.get('host', None) or not user_data['host'].get( 'host', None): logger.info("Host received {}".format(info)) try: info = checkAndFixUrl(info) user_data['host'] = {} user_data['host']['host'] = info keyboard = [[ InlineKeyboardButton(text="Correcto", callback_data='host_ok'), InlineKeyboardButton(text="Corregir", callback_data='host_ko') ]] reply_markup = InlineKeyboardMarkup(keyboard, resize_keyboard=False, one_time_keyboard=True) update.message.reply_text("Es correcto el host? {}:".format( user_data['host']['host']), reply_markup=reply_markup) return CONFIRMAR except Exception as e: logger.error(e) update.message.reply_text( "{} no parece ser un host correcto, intentá de nuevo".format( info)) return IDENTIFICAR elif not user_data['host'].get('username', None): logger.info("Username received {}".format(info)) user_data['host']['username'] = info keyboard = [[ InlineKeyboardButton(text="Correcto", callback_data='username_ok'), InlineKeyboardButton(text="Corregir", callback_data='username_ko') ]] reply_markup = InlineKeyboardMarkup(keyboard, resize_keyboard=False, one_time_keyboard=True) update.message.reply_text("Es correcto el usuario? {}:".format( user_data['host']['username']), reply_markup=reply_markup) return CONFIRMAR else: logger.info("Password received") # Try to login user_data['host']['pass'] = info try: connection = Connection(user_data['host']['host'], user_data['host']['username'], user_data['host']['pass']) logger.info("good login") usuario = usuarios.getCollection().find_one( {'chat_id': update.message.chat_id}) if not usuario: usuarios.getCollection().insert_one({ 'chat_id': update.message.chat_id, 'hosts': [user_data['host']] }) else: usuarios.getCollection().update_one( {'chat_id': update.message.chat_id}, {'$push': { 'hosts': user_data['host'] }}) logger.info(user_data['host']) proyectos = connection.getProjects() keyboard = [] for proyecto in proyectos.keys(): keyboard.append([ InlineKeyboardButton(proyectos[proyecto], callback_data=proyecto) ]) reply_markup = InlineKeyboardMarkup(keyboard, resize_keyboard=True, one_time_keyboard=True) update.message.reply_text("Bien! Elegí un proyecto", reply_markup=reply_markup) return PROYECTO except Exception as e: logger.error(e) update.message.reply_text("Clave incorrecta") return IDENTIFICAR return CONFIRMAR
def test_ip_puerto_path(self): """Ip, path y puerto""" self.assertEqual('http://127.0.0.1:8989/youtrack', checkAndFixUrl('127.0.0.1:8989/youtrack'))
def test_solo_hostname(self): """Solo hostname""" self.assertEqual('http://prueba.com', checkAndFixUrl('prueba.com'))
def test_ip(self): """Ip""" self.assertEqual('http://127.0.0.1', checkAndFixUrl('127.0.0.1'))
def test_ip_puerto(self): """Ip y puerto""" self.assertEqual('http://127.0.0.1:8989', checkAndFixUrl('127.0.0.1:8989'))
def test_hostname_path(self): """Hostname y path""" self.assertEqual('http://prueba.com/youtrack', checkAndFixUrl('prueba.com/youtrack'))
def test_hostname_puerto_www_path(self): """Hostname, www, puerto y path""" self.assertEqual('http://www.prueba.com:8181/youtrack', checkAndFixUrl('www.prueba.com:8181/youtrack'))
def test_solo_hostname_www(self): """Hostname y www""" self.assertEqual('http://www.prueba.com', checkAndFixUrl('www.prueba.com'))
def test_hostname_puerto_www(self): """Hostname, www y puerto""" self.assertEqual('http://www.prueba.com:8181', checkAndFixUrl('www.prueba.com:8181'))
def test_hostname_puerto(self): """Hostname y puerto""" self.assertEqual('http://prueba.com:8181', checkAndFixUrl('prueba.com:8181'))