Example #1
0
 def test_trip_is_in_the_past_with_past_trip(self):
     """
     is_in_the_past() returns True for trips whose start_date is in the past
     """
     date = timezone.now().date() - datetime.timedelta(days=1)
     future_trip = Trip(start_date=date)
     self.assertIs(future_trip.is_in_the_past(), True)
Example #2
0
    def get_context_data(self, **kwargs):

        car_owner = get_object_or_404(get_user_model(),
                                      username=kwargs["username"])
        d = datetime.now()
        # GOTO if it's before noon. RETURN otherwise.
        way = d.hour <= 12 and Trip.GOTO or Trip.RETURN

        trip_params = {
            "date": d.date(),
            "car": car_owner.cars.get(),
            "way": way
        }
        try:
            # The Trip already exists
            trip = Trip.objects.get(**trip_params)
        except Trip.DoesNotExist:
            #  A new Trip instance
            trip = Trip(**trip_params)
        self.object = trip

        context = super().get_context_data(**kwargs)
        register_existing = trip.id and reverse("trips:register_existing",
                                                args=[trip.id])
        register_new = reverse("trips:register_new")
        context["processing_url"] = register_existing or register_new
        return context
Example #3
0
 def test_trip_is_in_the_past_with_today_trip(self):
     """
     is_in_the_past() returns False for trips whose start_date is today
     or in the future
     """
     date = timezone.now().date()
     future_trip = Trip(start_date=date)
     self.assertIs(future_trip.is_in_the_past(), False)
Example #4
0
 def test_get_context_data_includes_key_cancel_button_path(self):
     request = self.factory.get('/fake/')
     request.user = self.user
     view = TripCreateView()
     kwargs = {}
     view = setup_view(view, request, **kwargs)
     view.object = Trip()
     context = view.get_context_data()
     self.assertIn('cancel_button_path', context)
Example #5
0
 def test_get_context_data_includes_key_page_title(self):
     '''
     The get_context_data includes key 'page_title'
     '''
     request = self.factory.get('/fake/')
     request.user = self.user
     view = TripCreateView()
     kwargs = {}
     view = setup_view(view, request, **kwargs)
     view.object = Trip()
     context = view.get_context_data()
     self.assertIn('page_title', context)
Example #6
0
    def mutate(self, info, user_api_key, name, origin):
        user = User.objects.get(api_key=user_api_key)
        trip = Trip(name=name, user=user)
        response = get_coordinates(origin)

        if len(response) > 0:
            trip.origin = response[0]['formatted_address']
            trip.origin_lat = response[0]['geometry']['location']['lat']
            trip.origin_long = response[0]['geometry']['location']['lng']
            trip.origin_abbrev = get_airport_code(trip.origin)
            trip.save()
            return CreateTrip(trip=trip)
        else:
            raise GraphQLError('Invalid location. Please try again.')
Example #7
0
def create_trip(payload):
    session = Session()
    trip = Trip(payload=payload)
    session.add(trip)
    session.commit()
    return trip
Example #8
0
     car_plate = None
 try:
     check_code = trip["check_code"]
 except:
     check_code = None
 #Create trip
 trip = Trip(
     status=status,
     price=price,
     start_date=start_date,
     end_date=end_date,
     start_pickup_address=start_pickup_address,
     start_pickup_location_type=start_pickup_location_type,
     start_pickup_location_latitude=start_pickup_location_latitude,
     start_pickup_location_longitude=start_pickup_location_longitude,
     end_pickup_address=end_pickup_address,
     end_pickup_location_type=end_pickup_location_type,
     end_pickup_location_latitude=end_pickup_location_latitude,
     end_pickup_location_longitude=end_pickup_location_longitude,
     passenger_first_name=passenger_first_name,
     passenger_last_name=passenger_last_name,
     driver_first_name=driver_first_name,
     driver_last_name=driver_last_name,
     driver_location_type=driver_location_type,
     driver_location_latitude=driver_location_latitude,
     driver_location_longitude=driver_location_longitude,
     car_plate=car_plate,
     check_code=check_code,
     city=city,
     country=country)
 trip.save()