def test_get_user_id(self): access_token = 'access_token' data = { 'id': 'user_id', } url = smartcar.const.API_URL + '/user' responses.add('GET', url, json=data) actual = smartcar.get_user_id(access_token) self.assertEqual(actual, data['id']) self.assertEqual(request().headers['Authorization'], 'Bearer ' + access_token)
def test_get_user_id(self): access_token = "access_token" data = { "id": "user_id", } url = smartcar.const.API_URL + "/user" responses.add("GET", url, json=data) actual = smartcar.get_user_id(access_token) self.assertEqual(actual, data["id"]) self.assertEqual(request().headers["Authorization"], "Bearer " + access_token)
def exchange(): email = session.get("email") if not email: return "not logged in" code = request.args.get("code") user_access = smartcar_client.exchange_code(code) user_id = smartcar.get_user_id(user_access["access_token"]) user_access["uid"] = user_id user_access["expires_on"] = datetime.datetime.now() + datetime.timedelta( seconds=user_access["expires_in"]) db.access.insert_one(user_access) user = db.users.find_one({"email": email}) uids = user.get("uids") uids.append(user_id) db.users.update_one({"email": email}, {"$set": {"uids": uids}}) return redirect("/home.html")
def test_get_user_id(self): user_id = smartcar.get_user_id(self.access_token) self.assertIsNotNone(user_id)
def user(): return jsonify(smartcar.get_user_id())