def tearDown(self) -> None: self.from_location_1.delete() self.to_location_1.delete() self.from_location_2.delete() self.to_location_2.delete() for booking_id in self.booking_id_to_delete: RiderBooking.get(doc_id=booking_id).delete()
def setUp(self): main.app.testing = True self.app = main.app.test_client() self.userIds = ["testuid1", "testuid2"] self.from_location = LocationFactory.from_pickup_address( "Tenaya Hall, San Diego, CA 92161") self.from_location.save() self.to_location = LocationFactory.from_pickup_address( "Tioga Hall, San Diego, CA 92161") self.to_location.save() self.ride_host = RideHost.new(doc_id="tmp_ride_host_1", earliest_departure=1419851578, from_location=self.from_location, to_location=self.to_location, user_id="testuid1", status="created") self.ride_host.save() self.rider_booking = RiderBooking.new( doc_id="tmp_rider_booking_1", earliest_departure=1419851578, from_location=self.from_location, to_location=self.to_location, user_id="xHU5Hp8OJbVitZEWPlWk3VGyC8I3", status="created") self.rider_booking.save()
def _add_rider_transactional(transaction, orbit_id, booking_id, **kwargs): orbit = cls.get(doc_id=orbit_id, transaction=transaction) rider_booking = RiderBooking.get(doc_id=booking_id, transaction=transaction) orbit._add_rider(rider_booking, **kwargs) orbit.save(transaction=transaction) rider_booking.save(transaction=transaction)
def setUp(self): main.app.testing = True self.app = main.app.test_client() self.userIds = ["testuid1", "testuid2"] self.from_location: UserLocation = LocationFactory.from_pickup_address("Tenaya Hall, San Diego, CA 92161") self.from_location.save() self.sublocation = Sublocation.get_with_latlng( latitude=self.from_location.latitude, longitude=self.from_location.longitude ) self.sublocation.save() testing_utils._wait() UserLocation.add_sublocation_with_id( self.from_location.doc_id, [self.sublocation.doc_id], ) self.to_location = LocationFactory.from_pickup_address("Tioga Hall, San Diego, CA 92161") self.to_location.save() testing_utils._wait() UserLocation.add_sublocation_with_id( self.to_location.doc_id, [self.sublocation.doc_id] ) self.users = { user_id: User.new(doc_id=user_id, name="My Name", email=f"{user_id}@myemail.com") for user_id in self.userIds } _ = [user.save() for _, user in self.users.items()] self.ride_host = RideHost.new( doc_id="tmp_ride_host_1", earliest_departure=1419851578, from_location=self.from_location, to_location=self.to_location, user_id=self.userIds[0], status="created" ) self.ride_host.save() self.rider_booking = RiderBooking.new( doc_id="tmp_rider_booking_1", earliest_departure=1419851578, from_location=self.from_location, to_location=self.to_location, user_id=self.userIds[1], status="created" ) self.rider_booking.save()
def _add_rider( self, rider_booking: RiderBooking, pickup_sublocation_id=None, dropoff_sublocation_id=None, ): if rider_booking.status != "created": raise ValueError rider_booking.orbit_ref = self.doc_ref rider_booking.status = "matched" self.bookings.append(rider_booking) self.user_ticket_pairs[rider_booking.user_id] = { "bookingId": rider_booking.doc_id, "userWillDrive": False, "hasCheckedIn": False, "state": "added", "pickupSublocationId": pickup_sublocation_id, "dropoffSublocationId": dropoff_sublocation_id }
def _match_transactional(transaction, orbit_id=None, hosting_id=None, rider_records=None): if orbit_id is None: orbit: Orbit = cls.new(status="open", transaction=transaction) else: orbit = cls.get(doc_id=orbit_id, transaction=transaction) ride_host = RideHost.get(doc_id=hosting_id, transaction=transaction) orbit._add_host(ride_host) for booking_id, pickup_sublocation_id, dropoff_sublocation_id in rider_records: rider_booking = RiderBooking.get(doc_id=booking_id, transaction=transaction) orbit._add_rider(rider_booking=rider_booking, pickup_sublocation_id=pickup_sublocation_id, dropoff_sublocation_id=dropoff_sublocation_id) # rider_booking.save(transaction=transaction) orbit.save(transaction=transaction)
from flask_boiler.view.query_delta import ProtocolBase from google.cloud.firestore import Query from google.cloud.firestore import DocumentSnapshot from gravitate import CTX from gravitate.domain import bookings from gravitate.domain.bookings import RiderBooking, RiderTarget from gravitate.domain.bookings.view_mediator import BookingTargetMediator from gravitate.domain.host_car import RideHostTarget from gravitate.domain.matcher.orbit import Orbit from gravitate.domain.target import Target from gravitate.domain import host_car from gravitate.distance_func import edge_weight booking_target_mediator = BookingTargetMediator(query=RiderBooking.get_query()) class RiderTargetMediator(QueryMediator): def __init__(self, *args, target_repo, **kwargs): super().__init__(*args, **kwargs) self.model_cls = bookings.RiderTarget self.target_repo = target_repo class Protocol(ProtocolBase): @staticmethod def on_create(snapshot: DocumentSnapshot, mediator): assert isinstance(snapshot, DocumentSnapshot) obj = snapshot_to_obj(snapshot=snapshot) mediator.target_repo.add(obj)
user_booking_mediator = UserBookingEditMediator( query=Context.db.collection_group("bookings_POST")) user_hosting_mediator = UserHostingEditMediator( query=Context.db.collection_group("hostings_POST")) user_location_mediator = UserLocationFormMediator( query=Context.db.collection_group("locations_POST")) user_sublocation_mediator = UserSublocationFormMediator( query=Context.db.collection_group("sublocations_POST")) user_location_view_mediator = UserLocationViewMediator( query=UserLocation.get_query()) booking_mediator = UserBookingMediator(query=RiderBooking.get_query()) ride_host_mediator = \ RHMediator(view_model_cls=RideHostForm, app=app, mutation_cls=RideHostMutation) ride_host_mediator.add_list_post( rule='/rideHosts', list_post_view=ride_host_mediator._default_list_post_view()) hosting_mediator = UserHostingMediator(query=RideHost.get_query()) # target_match_mediator = TargetMatchMediator( # query=RiderTarget.get_query() # ) orbit_view_mediator = OrbitViewMediator(query=Orbit.get_query())
def setUp(self): # main.app.testing = True # self.app = main.app.test_client() self.userIds = ["testuid1", "testuid2"] self.users = { user_id: User.new(doc_id=user_id, name="My Name", email=f"{user_id}@myemail.com") for user_id in self.userIds } _ = [user.save() for _, user in self.users.items()] self.host_from = LocationFactory.from_place_address( "8775 Costa Verde Blvd, San Diego, CA 92122") self.host_from.user_id = self.userIds[0] self.host_from.save() self.host_to = LocationFactory.from_place_address( "Center Hall, San Diego, CA") self.host_to.user_id = self.userIds[0] self.host_to.save() self.rider_from = LocationFactory.from_place_address( "3915 Nobel Drive, San Diego, CA") a = Sublocation.get_with_latlng( latitude=self.rider_from.coordinates["latitude"], longitude=self.rider_from.coordinates["longitude"]) a.save() self.a = a self.rider_from.sublocations = [a.doc_ref] self.rider_from.user_id = self.userIds[1] self.rider_from.save() self.rider_to = LocationFactory.from_place_address( "Center Hall, San Diego, CA") b = Sublocation.get_with_latlng( latitude=self.rider_to.coordinates["latitude"], longitude=self.rider_to.coordinates["longitude"]) b.save() self.b = b self.rider_to.sublocations = [b.doc_ref] self.rider_to.user_id = self.userIds[1] self.rider_to.save() self.ride_host = RideHost.new( doc_id="tmp_ride_host_1", earliest_departure=fields.timestamp_from_local_time( "2020-04-09T10:55:00"), from_location=self.host_from, to_location=self.host_to, user_id=self.userIds[0], status="created") self.ride_host.save() self.rider_booking = RiderBooking.new( doc_id="tmp_rider_booking_1", earliest_departure=fields.timestamp_from_local_time( "2020-04-09T11:00:00"), from_location=self.rider_from, to_location=self.rider_to, user_id=self.userIds[1], status="created") self.rider_booking.save()