Esempio n. 1
0
    def test_save_github_user_data(self):
        User.drop_collection()
        github_user = '******'
        chat_id = 'id'
        github_user_id = 'git_id'
        user = User()
        user.github_user = github_user
        user.save()
        user.save_github_user_data(github_user, chat_id, github_user_id)

        user_db = User.objects(github_user=github_user).first()
        self.assertEqual(user, user_db)
Esempio n. 2
0
def get_access_token(chat_id):
    code = request.args.get('code')
    existing_user = User.objects(chat_id=chat_id).first()
    send_message(ACCESS_TOKEN, chat_id)
    if not existing_user:
        GITHUB_TOKEN = authenticate_access_token(code)
        db_user = User()
        db_user.access_token = GITHUB_TOKEN
        db_user.chat_id = str(chat_id)
        db_user.save()
        user = UserInfo(chat_id)
        user_infos = user.get_own_user_data()
        db_user.github_user = user_infos["github_username"]
        db_user.github_user_id = str(user_infos["github_user_id"])
        db_user.save()
        user.send_button_message(user_infos, chat_id)
    redirect_uri = "https://t.me/{bot_name}".format(bot_name=BOT_NAME)
    return redirect(redirect_uri, code=302)