Esempio n. 1
0
 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)
Esempio n. 2
0
 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)
Esempio n. 3
0
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")
Esempio n. 4
0
 def test_get_user_id(self):
     user_id = smartcar.get_user_id(self.access_token)
     self.assertIsNotNone(user_id)
Esempio n. 5
0
def user():
    return jsonify(smartcar.get_user_id())