def get_users():
    # Get the user info
    phone = test_data.user_1.get('phone')
    print "get user with phone number: "
    print phone
    print UserHelper.get_user_by_phone(phone)

    phone = test_data.user_4.get('phone')
    print "get user with phone number: "
    print phone
    print UserHelper.get_user_by_phone(phone)
def add_users():
    # Create a new user

    first_name = test_data.user_1.get('first_name')
    last_name = test_data.user_1.get('last_name')
    phone = test_data.user_1.get('phone')
    image_url = test_data.user_1.get('img_url')

    # Store the user
    user_id = UserHelper.add_user(first_name=first_name,
                                  last_name=last_name,
                                  phone=phone,
                                  image_url=image_url)
    print user_id

    # Create a new user
    first_name = test_data.user_2.get('first_name')
    last_name = test_data.user_2.get('last_name')
    phone = test_data.user_2.get('phone')
    image_url = test_data.user_2.get('img_url')

    # Store the user
    user_id = UserHelper.add_user(first_name=first_name,
                                  last_name=last_name,
                                  phone=phone,
                                  image_url=image_url)
    print user_id

    # Create a new user
    first_name = test_data.user_3.get('first_name')
    last_name = test_data.user_3.get('last_name')
    phone = test_data.user_3.get('phone')
    image_url = test_data.user_3.get('img_url')

    # Store the user
    user_id = UserHelper.add_user(first_name=first_name,
                                  last_name=last_name,
                                  phone=phone,
                                  image_url=image_url)
    print user_id

    # Create a new user
    first_name = test_data.user_4.get('first_name')
    last_name = test_data.user_4.get('last_name')
    phone = test_data.user_4.get('phone')
    image_url = test_data.user_4.get('img_url')

    # Store the user to match
    user_id = UserHelper.add_user(first_name=first_name,
                                  last_name=last_name,
                                  phone=phone,
                                  image_url=image_url)
    print user_id
 def get(self):
     user = {}
     m = re.match('^/user/([\d].*)$', self.request.uri)
     if m:
         phone = m.group(1)
         user = UserHelper.get_user_by_phone(phone)
     self.write(user)
Exemple #4
0
 def get(self):
     user = {}
     m = re.match('^/user/([\d].*)$', self.request.uri)
     if m:
         phone = m.group(1)
         user = UserHelper.get_user_by_phone(phone)
     self.write(user)
 def post(self):
     required_params = {
         'first_name':'str',
         'last_name':'str',
         'image_url':'str',
         'phone':'str'
     }
     # returning becuase calling write() a few lines below will throw an error
     # since check_params already called write() or finish()
     if not self.check_params(required_params): return
     first_name = self.get_argument('first_name') 
     last_name = self.get_argument('last_name')
     image_url = self.get_argument('image_url') 
     phone = self.get_argument('phone')
     resp = UserHelper.add_user(first_name=first_name, last_name=last_name, image_url=image_url, phone=phone)
     self.write(resp)
Exemple #6
0
 def format_ride(klass, ride_doc_or_ride_id):
     if type(ride_doc_or_ride_id) != dict:
         ride_doc = klass.get_ride(ride_doc_or_ride_id)
         if not ride_doc: 
             return ApiResponse.RIDE_NOT_FOUND
     else:
         ride_doc = ride_doc_or_ride_id
     
     user_id = ride_doc.get(Ride.A_USER_ID)
     if not user_id: return ApiResponse.RIDE_USER_ID_NOT_FOUND
     
     user_doc = UserHelper.get_user_by_id(user_id)        
     if not user_doc: return ApiResponse.RIDE_USER_NOT_FOUND
     
     ride_doc['user']=user_doc
     return ride_doc
Exemple #7
0
 def get_matches_for_status_prepending(klass, ride_doc):
     # Get all rides that match ride_doc specs
     rides = Ride.get_matches(ride_doc)
     if not rides:
         return ApiResponse.RIDE_NO_MATCHES_FOUND
     
     # Get list of user_ids in rides  
     user_ids = [r.get(Ride.A_USER_ID) for r in rides]
     
     # Make batch call to get all user info
     users = UserHelper.get_users_by_id(user_ids)
     
     # Append each ride with user info
     for ride in rides:
         user_id = ride.get(Ride.A_USER_ID)
         ride['user'] = users.get(user_id)
     return rides
Exemple #8
0
 def post(self):
     required_params = {
         'first_name': 'str',
         'last_name': 'str',
         'image_url': 'str',
         'phone': 'str'
     }
     # returning becuase calling write() a few lines below will throw an error
     # since check_params already called write() or finish()
     if not self.check_params(required_params): return
     first_name = self.get_argument('first_name')
     last_name = self.get_argument('last_name')
     image_url = self.get_argument('image_url')
     phone = self.get_argument('phone')
     resp = UserHelper.add_user(first_name=first_name,
                                last_name=last_name,
                                image_url=image_url,
                                phone=phone)
     self.write(resp)
def add_rides():
    # Using user_1 add a ride that will be used to search for matches
    phone = test_data.user_1.get('phone')
    user = UserHelper.get_user_by_phone(phone)
    user_id = user.get(User.A_USER_ID)
    dt = datetime.datetime.now()
    departure_timestamp = time.mktime(dt.timetuple())
    dest_lat = 40.65
    dest_lon = 73.78
    origin_place = 'jfk'
    origin_pick_up = 'Terminal A'
    ride_id_doc = RideHelper.create_or_update_ride(user_id, origin_place,
                                                   origin_pick_up, dest_lon,
                                                   dest_lat,
                                                   departure_timestamp)
    ride_id = ride_id_doc.get('ride_id')

    # Check to see that the ride info was stored
    ride = RideHelper.get_ride(ride_id)
    print "ride to match"
    print ride
    print "ride to match id"
    print ride_id
    ride_to_match_id = ride_id

    # Check for a ride that does not exist
    ride_id = "10291032491203"
    ride = RideHelper.get_ride(ride_id)
    print "should return an error, no ride exists"
    print ride

    # Switch users to user_4
    phone = test_data.user_4.get('phone')
    user = UserHelper.get_user_by_phone(phone)
    user_id = user.get("user_id")
    print "current user:"******"Ride that will leave 2 hrs later"
    print ride

    # Create another ride that will go to a far away destination for user_4

    ride_id = RideHelper.create_or_update_ride(user_id, origin_place,
                                               origin_pick_up, dest_lon + 10,
                                               dest_lat + 10,
                                               departure_timestamp)
    ride_id = ride_id_doc.get('ride_id')
    # Check to see that the ride info was stored
    ride = RideHelper.get_ride(ride_id)
    print "Ride with far away destination"
    print ride

    # Create another ride that will be an ideal match, only .5 degrees further for user_4
    ride_id = RideHelper.create_or_update_ride(user_id, origin_place,
                                               origin_pick_up,
                                               dest_lon + 0.005,
                                               dest_lat + 0.005,
                                               departure_timestamp)
    ride_id = ride_id_doc.get('ride_id')
    # Check to see that the ride info was stored
    ride = RideHelper.get_ride(ride_id)
    print "Ride with only .5 degrees distance from ride to match"
    print ride

    # Switch to user 3
    phone = test_data.user_3.get('phone')
    user = UserHelper.get_user_by_phone(phone)
    user_id = user.get(User.A_USER_ID)

    # Create another ride that will be an ideal match with only .5 degrees further for user_3
    ride_id = RideHelper.create_or_update_ride(user_id, origin_place,
                                               origin_pick_up,
                                               dest_lon + 0.003,
                                               dest_lat + 0.003,
                                               departure_timestamp + 10 * 60)
    ride_id = ride_id_doc.get('ride_id')
    # Check to see that the ride info was stored
    ride = RideHelper.get_ride(ride_id)
    print "Ride with only .3 degrees distance from ride to match"
    print ride

    # Create another ride that leaves from a different origin for user_3
    origin_place = "jfk"
    origin_pick_up = "Terminal B"
    ride_id = RideHelper.create_or_update_ride(user_id, origin_place,
                                               origin_pick_up, dest_lon,
                                               dest_lat, departure_timestamp)
    # Check to see that the ride info was stored
    ride = RideHelper.get_ride(ride_id)
    print "Ride with different origin, same max distance"
    print ride
    return ride_to_match_id