def _add_to_orbit(r: RideRequest, o: Orbit): """ Description :type r:RideRequest: :param r:RideRequest: :type o:Orbit: :param o:Orbit: :raises: :rtype: """ # set RideRequest's requestCompletion to true r.request_completion = True # RideRequest's orbitId no longer null and references Orbit's oId r.orbit_ref = o.get_firestore_ref() user_id = r.user_id # fill in ticket and insert in to orbit's userTicketPairs ticket = { "rideRequestRef": r.get_firestore_ref(), "userWillDrive": r.driver_status, "hasCheckedIn": False, "inChat": False, "pickupAddress": r.pickup_address } o.user_ticket_pairs[user_id] = ticket r.request_completion = True return
def _drop_from_orbit(r: RideRequest, o: Orbit): # remove userRef from orbitRef's userTicketPairs # search userTicketPairs for userRef, remove userRef and corresponding ticket once done userIds = list(o.user_ticket_pairs.keys()) for userId in userIds: if userId == r.user_id: o.user_ticket_pairs.pop(userId) r.orbit_ref = None r.request_completion = False
def remove_from_orbit(r: RideRequest, o: Orbit): """ Removes userRef from orbitRef's userTicketPairs search userTicketPairs for userRef, remove userRef and corresponding ticket once done :param r: ride request to remove from orbit :param o: orbit :return: """ userIds = list(o.user_ticket_pairs.keys()) for userId in userIds: if userId == r.user_id: o.user_ticket_pairs.pop(userId) r.orbit_ref = None r.request_completion = False
def testFillRideRequestDictNew(self): mockForm = FormDictFactory().create(hasEarliestLatest=False, returnDict=False) result, _ = fill_ride_request_dict_builder_regression(mockForm, userId) valueExpected = RideRequest.from_dict({ 'rideCategory': 'airportRide', 'pickupAddress': "Tenaya Hall, San Diego, CA 92161", 'driverStatus': False, 'orbitRef': None, 'target': {'eventCategory': 'airportRide', 'toEvent': True, 'arriveAtEventTime': {'earliest': 1545058800, 'latest': 1545069600}}, 'eventRef': db.document('events', 'testeventid1'), 'userId': 'SQytDq13q00e0N3H4agR', 'hasCheckedIn': False, 'pricing': 987654321, "baggages": dict(), "disabilities": dict(), 'flightLocalTime': "2018-12-17T12:00:00.000", 'flightNumber': "DL89", "airportLocation": db.document("locations", "testairportlocationid1"), "requestCompletion": False }).to_dict() self.assertDictEqual(valueExpected, result) self.assertIsNotNone(result["eventRef"]) self.assertIsNotNone(result["airportLocation"])
def testPlaceInOrbit(self): orbitDict = { "orbitCategory": "airportRide", "eventRef": "testeventref1", "userTicketPairs": {}, "chatroomRef": "testchatroomref1", "costEstimate": 987654321, "status": 1 } orbit = Orbit.from_dict(orbitDict) rideRequestDict = test.store.model.getMockRideRequest( useDocumentRef=True, returnDict=True, returnSubset=False) rideRequest = RideRequest.from_dict(rideRequestDict) rideRequest.set_firestore_ref( db.document('rideRequests', 'testriderequestid1')) _add_to_orbit(rideRequest, orbit) userTicketPairsDict = orbit.to_dict()["userTicketPairs"] expectedDict = { rideRequest.user_id: { "rideRequestRef": db.document('rideRequests', 'testriderequestid1'), "userWillDrive": False, "hasCheckedIn": False, "inChat": False, "pickupAddress": "Tenaya Hall, San Diego, CA 92161" } } self.assertDictEqual(userTicketPairsDict, expectedDict)
def generate_ride_request() -> Type[RideRequest]: ride_request_dict = store.getMockRideRequest(returnDict=True) ride_request = RideRequest.from_dict(ride_request_dict) RideRequestGenericDao().create(ride_request) RideRequestGenericDao().set(ride_request) # ref = ride_request.get_firestore_ref() return ride_request
def testSet(self): rideRequestDict = self.rideRequestData1 rideRequest = RideRequest.from_dict(rideRequestDict) RideRequestGenericDao().create(rideRequest) RideRequestGenericDao().set(rideRequest) ref = rideRequest.get_firestore_ref() print(ref) self.toDelete.append(ref) d = RideRequestGenericDao().get(ref) self.assertEqual(rideRequestDict, d.to_dict())
def getMockRide(earliest: int = 1545058800, latest: int = 1545069600, firestoreRef=mock1["rideRequestRef"], userId=mock1["userId"], useDocumentRef=False, returnDict=False, returnSubset=False, driverStatus=False): locationRefStr = mock1["locationRef"] locationReference = mock1["locationFirestoreRef"] originRefStr = mock1["originRef"] originReference = mock1["originFirestoreRef"] destinationRefStr = mock1["destinationRef"] destinationReference = mock1["destinationFirestoreRef"] eventRefStr = mock1["eventRef"] eventReference = mock1["eventFirestoreRef"] rideRequestDict = { 'rideCategory': 'airportRide', 'driverStatus': driverStatus, 'orbitRef': None, 'target': {'eventCategory': 'airportRide', 'toEvent': True, 'arriveAtEventTime': {'earliest': earliest, 'latest': latest}}, 'userId': userId, 'hasCheckedIn': False, 'pricing': 987654321, "baggages": dict(), "disabilities": dict(), 'flightLocalTime': "2018-12-17T12:00:00.000", 'flightNumber': "DL89", "requestCompletion": False } if not returnSubset: rideRequestDict["airportLocation"] = locationReference if useDocumentRef else locationRefStr rideRequestDict["eventRef"] = eventReference if useDocumentRef else eventRefStr rideRequestDict['originRef'] = originReference if useDocumentRef else originRefStr rideRequestDict['destinationRef'] = destinationReference if useDocumentRef else destinationRefStr if returnDict: return rideRequestDict else: rideRequest = RideRequest.from_dict(rideRequestDict) rideRequest.set_firestore_ref(firestoreRef) return rideRequest
def testAfterDictEqualsOriginalDict2(self): """ Tests that to_dict returns the same dict as the passed to from_dict. :return: """ print(self.ride_request_data_2) ride_request_dict = self.ride_request_data_2 ride_request_ref = db.collection("rideRequests").document( "testriderequestid1") airport_ride_request: AirportRideRequest = RideRequest.from_dict_and_reference( ride_request_dict, ride_request_ref) result = airport_ride_request.to_dict() self.assertDictEqual( ride_request_dict, result, "The dictionaries should equal if RideRequest was not modified. ")
def testCreate(self): rideRequestDict = self.rideRequestData1 rideRequest = RideRequest.from_dict(rideRequestDict) RideRequestGenericDao().create(rideRequest) resultDict = rideRequest.to_dict() self.assertEqual(rideRequestDict, resultDict)