def testSetWithTransaction(self): transaction = db.transaction() ref = model.mock1["locationFirestoreRef"] LocationGenericDao.set_with_transaction(transaction, model.getLocation(), ref) self.to_delete.append(ref) transaction.commit()
def execute(self) -> list: """ :return: a list of DocumentReference for all Documents created """ airportLocation = None refs = list() if self.airport_code == 'LAX': airportLocation = LaxBuilder().exportToLocation() ref = LocationGenericDao().insert_new(airportLocation) airportLocation.set_firestore_ref(ref) refs.append(ref) elif self.airport_code == 'SAN': airportLocation = SanBuilder().exportToLocation() ref = LocationGenericDao().insert_new(airportLocation) airportLocation.set_firestore_ref(ref) refs.append(ref) else: raise ValueError("unsupported airportCode: {}".format( self.airport_code)) print(vars(airportLocation)) return refs
def testGet(self): # ref = model.mock1["locationFirestoreRef"] ref = LocationGenericDao().insert_new(model.getLocation()) self.to_delete.append(ref) location = LocationGenericDao().get(ref) self.assertIsNotNone(location) print(location.to_dict())
def _create_airport_ride_request(args, user_id): """ Creates an airport ride request with arguments received by REST API endpoint :param args: argument dict returned by .parse_args() from a reqparse object :param user_id: user id :return: RideRequest object """ builder = AirportRideRequestBuilder() ride_request: AirportRideRequest = builder \ .set_with_form_and_user_id(args, user_id) \ .build_airport_ride_request() \ .export_as_class(AirportRideRequest) location = LocationGenericDao().get(ride_request.airport_location) if ride_request.target.to_event: user_location = LocationGenericDao().get(ride_request.origin_ref) else: raise ValueError("to_event is False ") # Do Validation Tasks before saving rideRequest # 1. Check that rideRequest is not submitted by the same user # for the flight on the same day already # TODO: move to transactional logic for better atomicity if utils.check_duplicate(ride_request.user_id, ride_request.event_ref): raise service_errors.RequestAlreadyExistsError # Starts database operations to (save rideRequest and update user's eventSchedule) transaction = db.transaction() # Transactional business logic for adding rideRequest utils.add_ride_request(transaction, ride_request, location, user_id) # Save write result transaction.commit() return ride_request
def doWork(airportCode='LAX'): airportLocation = None if airportCode == 'LAX': airportLocation = LaxBuilder().exportToLocation() ref = LocationGenericDao().insert_new(airportLocation) airportLocation.set_firestore_ref(ref) elif airportCode == 'SAN': airportLocation = SanBuilder().exportToLocation() ref = LocationGenericDao().insert_new(airportLocation) airportLocation.set_firestore_ref(ref) else: raise ValueError print(vars(airportLocation))
def run_orbit_group(ride_requests: dict): """ Create an orbit and group ride requests into the orbit. :param ride_requests: ride requests to place in the same orbit. :return: ride requests that could not be joined """ assert len(ride_requests) != 0 event_ids: set = {r.event_ref.id for rid, r in ride_requests.items()} assert len(event_ids) == 1 event_ref = EventDao().get_ref(event_ids.pop()) orbit = Orbit.from_dict({ "orbitCategory": "airportRide", "eventRef": event_ref, "userTicketPairs": { }, "chatroomRef": None, "costEstimate": 987654321, "status": 1 }) orbit_ref = OrbitDao().create(orbit) orbit.set_firestore_ref(orbit_ref) event = EventDao().get(event_ref) location_ref: DocumentReference = event.location_ref location = LocationGenericDao().get(location_ref) ride_request_refs = [r.get_firestore_ref() for rid, r in ride_requests.items()] transaction = db.transaction() # TODO: implement and call validate_entities_not_changed not_joined = _add_to_group(transaction, orbit_ref, ride_request_refs, event_ref, location_ref) return not_joined
def setUp(self): self.refs_to_delete = list() event_dict = getEventDict(use_firestore_ref=True, to_earliest=1545033600, to_latest=1545119999, from_earliest=1545033600, from_latest=1545119999) self.event = Event.from_dict(event_dict) main.app.testing = True self.app = main.app.test_client() self.userId = "testuid1" self.c = scripts.SetUpTestDatabase() self.c.clear_before() self.c.generate_test_data(start_string="2018-12-17T08:00:00.000", num_days=5) # Populate location location_ref = event_dict["locationRef"] location_d = getLocationDict(location_category="social") location = Location.from_dict(location_d) LocationGenericDao().set(location, location_ref) self.refs_to_delete.append(location_ref) event_ref: firestore.DocumentReference = EventDao().create(self.event) self.event.set_firestore_ref(event_ref) self.refs_to_delete.append(event_ref) self.event_id = event_ref.id
def testGetUserLocation(self): location = Location.from_pickup_address( "Tenaya Hall, San Diego, CA 92161") ref = LocationGenericDao().insert_new(location) self.to_delete.append(ref) location = LocationGenericDao().get(ref) d = location.to_dict() self.assertEqual( d, { 'locationCategory': "user", 'coordinates': { 'latitude': 32.8794203, 'longitude': -117.2428555 }, 'address': 'Tenaya Hall, San Diego, CA 92161', })
def get_location_ref_by_id(location_id: str) -> DocumentReference: """ This method return the location_ref by location_id. :param location_id: :return: """ return LocationGenericDao().get_ref_by_id(location_id)
def doWorkDeprecated(): terminals = ['1', '2', '3', '4', '5', '6', '7', '8', 'B'] for terminal in terminals: airportLocation = buildLaxTerminal(terminal) ref = LocationGenericDao().insert_new(airportLocation) airportLocation.set_firestore_ref(ref) print(vars(airportLocation))
def get_airport_location(airport_code) -> AirportLocation: """ Description This method returns an airportLocation with airportCode. :param airport_code: :return: """ return LocationGenericDao().find_by_airport_code(airport_code)
def _build_location(self, d): """ Create location with facebook event - place :param d: :return: """ location: SocialEventLocation = SocialEventLocation.from_fb_place(d) self._event_dict["locationRef"] = LocationGenericDao().insert_new( location)
def location(self): """ Note that this method is non-transactional. We are assuming that Location objects are immutable and ready before the transaction. :return: """ location_ref = self.location_ref location = LocationGenericDao().get(location_ref) return location
def setUp(self): fb_d = { "name": "Coachella", "location": { "latitude": 33.679974, "longitude": -116.237221 }, "id": "20281766647" } location = SocialEventLocation.from_fb_place(fb_d) self.location_ref = LocationGenericDao().insert_new(location) self.refs_to_delete.append(self.location_ref)
def setUp(self): self._to_delete = list() campusLocation = Location.from_code("UCSB", "campus") ref = LocationGenericDao().insert_new(campusLocation) campusLocation.set_firestore_ref(ref) self._to_delete.append(ref) self.event_dict = { "eventCategory": "campus", "campusCode": "UCSB", "isClosed": False, "targets": [{ 'eventCategory': 'campus', 'toEvent': True, 'arriveAtEventTime': { 'earliest': 1545033600, 'latest': 1545119999 } }, { 'eventCategory': 'campus', 'toEvent': False, 'leaveEventTime': { 'earliest': 1545033600, 'latest': 1545119999 } }], "localDateString": "2018-12-17", "pricing": 123456789, "parkingInfo": { "parkingAvailable": False, "parkingPrice": 0, "parkingLocation": "none" }, "description": "UCSB on 2018-12-17", "name": "UCSB", "locationRef": "/locations/testlocationid1", "participants": [] }
def setUp(self): main.app.testing = True self.app = main.app.test_client() self.userIds = ["testuid1", "testuid2"] self.refs_to_delete = list() location_dict = store.getLocationDict(location_category="social") location = Location.from_dict(location_dict) location_ref = LocationGenericDao().insert_new(location) self.refs_to_delete.append(location_ref) event_dict = store.getEventDict(event_category="social") event_dict["locationRef"] = location_ref event = Event.from_dict(event_dict) event_ref = EventDao().create(event) self.refs_to_delete.append(event_ref) event_id = event_ref.id self.d = store.EventRideRequestFormDictFactory().create( event_id=event_id) self.ride_request_ids_to_delete = list()
def _get_location(transaction: Transaction = None, location_id: str = None) -> Type[Location]: location_ref = LocationGenericDao().get_ref_by_id(location_id) return LocationGenericDao.get_with_transaction(transaction, location_ref)
def _build_pickup(self): origin_location = Location.from_pickup_address( pickup_address=self.pickup_address) origin_ref = LocationGenericDao().insert_new(origin_location) self._ride_request_dict["originRef"] = origin_ref
def build_airport(self, airport_code): self._event_dict["airportCode"] = airport_code self._event_dict["locationRef"] = LocationGenericDao( ).find_by_airport_code(airport_code).get_firestore_ref()
def doWorkUc(campusCode="UCSB"): campusLocation = Location.from_code("UCSB", "campus") ref = LocationGenericDao().insert_new(campusLocation) campusLocation.set_firestore_ref(ref)
def build_campus(self, campus_code): self._event_dict["campusCode"] = campus_code self._event_dict["locationRef"] = LocationGenericDao( ).find_by_campus_code(campus_code).get_firestore_ref()
def testFindByAirportCode(self): result = LocationGenericDao().find_by_airport_code('LAX') self.assertNotEqual(None, result, 'Should return a result. ')
def setUp(self): self.arr = [[12000000, 12005000, 32.8802438, -117.2426505, 'A'], [12000000, 12005000, 32.8796722, -117.2414153, 'B'], [12000000, 12005000, 32.8687404, -117.2306258, 'C'], [12005000, 12006000, 32.8805864, -117.2318744, 'D'], [12007000, 12009000, 32.83228020000001, -117.1480747, 'E'], [12009001, 12009900, 32.8255484, -117.1543703, 'F'], [11000000, 11009000, 32.8248571, -117.1559327, 'G']] arr = self.arr rideRequests = list() configs = list() configs_other = [[12000000, 12005000, 'A'], [12000000, 12005000, 'B'], [12000000, 12005000, 'C'], [12005000, 12006000, 'D'], [12007000, 12009000, 'E'], [12009001, 12009900, 'F'], [11000000, 11009000, 'G']] addresses = [ # These are ucsd addresed "9500 Gilman Dr, La Jolla, CA 92093", "Muir Ln, San Diego, CA 92161", "8825 Villa La Jolla Dr, La Jolla, CA 92037", # Whole foods "3390 Voigt Dr, San Diego, CA 92121", # Canyonview Aquatic Center # These are Kearny Mesa Addressed "8199 Clairemont Mesa Blvd Suite H, San Diego, CA 92111", # Camellia "4681 Convoy St, San Diego, CA 92111", # Tajima Japanese Restaurant "4646 Convoy St, San Diego, CA 92111" # Tasty Noodle House ] locations_ds = [ {'locationCategory': 'user', 'coordinates': {'latitude': 32.8802438, 'longitude': -117.2426505}, 'address': '9500 Gilman Dr, La Jolla, CA 92093'}, {'locationCategory': 'user', 'coordinates': {'latitude': 32.8796722, 'longitude': -117.2414153}, 'address': 'Muir Ln, San Diego, CA 92161'}, {'locationCategory': 'user', 'coordinates': {'latitude': 32.8687404, 'longitude': -117.2306258}, 'address': '8825 Villa La Jolla Dr, La Jolla, CA 92037'}, {'locationCategory': 'user', 'coordinates': {'latitude': 32.8805864, 'longitude': -117.2318744}, 'address': '3390 Voigt Dr, San Diego, CA 92121'}, {'locationCategory': 'user', 'coordinates': {'latitude': 32.83228020000001, 'longitude': -117.1480747}, 'address': '8199 Clairemont Mesa Blvd Suite H, San Diego, CA 92111'}, {'locationCategory': 'user', 'coordinates': {'latitude': 32.8255484, 'longitude': -117.1543703}, 'address': '4681 Convoy St, San Diego, CA 92111'}, {'locationCategory': 'user', 'coordinates': {'latitude': 32.8248571, 'longitude': -117.1559327}, 'address': '4646 Convoy St, San Diego, CA 92111'}, ] for i in range(len(configs_other)): earliest, latest, firestoreRef = configs_other[i] address = addresses[i] location_d = locations_ds[i] ride_request = test.store.model.getMockRideRequest( earliest=earliest, latest=latest, firestoreRef=firestoreRef, returnDict=False) # Generate Test Locations location = Location.from_dict(location_d) ref = LocationGenericDao().insert_new(location) ride_request.origin_ref = ref rideRequests.append(ride_request) self.ride_requests = rideRequests