Exemplo n.º 1
0
    def get_with_transaction(transaction: Transaction,
                             locationRef: DocumentReference) -> Type[Location]:
        """ Description
        Note that this cannot take place if transaction already received write operations.
        "If a transaction is used and it already has write operations added, this method cannot be used
        (i.e. read-after-write is not allowed)."

        :type self:
        :param self:

        :type transaction:Transaction:
        :param transaction:Transaction:

        :type locationRef:DocumentReference:
        :param locationRef:DocumentReference:

        :raises:

        :rtype:
        """

        try:
            snapshot: DocumentSnapshot = locationRef.get(
                transaction=transaction)
            snapshotDict: dict = snapshot.to_dict()
            location = Location.from_dict(snapshotDict)
            location.set_firestore_ref(locationRef)
            return location
        except google.cloud.exceptions.NotFound:
            raise Exception('No such document! ' + str(locationRef.id))
Exemplo n.º 2
0
    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
Exemplo n.º 3
0
    def generate_test_data(self,
                           airport_code="LAX",
                           start_string="2018-12-07T08:00:00.000",
                           num_days=3,
                           event_category="airport"):
        """
        Generate data needed by the test
        :param airport_code:
        :param start_string:
        :param num_days:
        :param event_category:
        :return:
        """
        c = scripts.populate_locations.PopulateLocationCommand(
            airport_code=airport_code)
        refs = c.execute()
        self.refs_to_delete.extend(refs)
        c = scripts.populate_airport_events.PopulateEventCommand(
            start_string=start_string,
            num_days=num_days,
            event_category=event_category)
        refs = c.execute()
        self.refs_to_delete.extend(refs)

        d = store.getUserLocationDict()
        location = Location.from_dict(d,
                                      doc_id=store.getMockKeys()["originId"])
        location.save()
        location_ref = location.doc_ref
        # LocationGenericDao().set(location, location_ref)
        self.refs_to_delete.append(location_ref)
Exemplo n.º 4
0
 def get(self, locationRef: DocumentReference):
     if isinstance(locationRef, str):
         locationRef = str_to_ref(locationRef)
     snapshot: DocumentSnapshot = locationRef.get()
     snapshotDict: dict = snapshot.to_dict()
     location = Location.from_dict(snapshotDict)
     location.set_firestore_ref(locationRef)
     return location
     return locationResult
Exemplo n.º 5
0
    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()
Exemplo n.º 6
0
def getLocation():
    locationDict = getLocationDict()
    location = Location.from_dict(locationDict)
    location.set_firestore_ref(mock1["locationFirestoreRef"])
    return location
Exemplo n.º 7
0
    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
Exemplo n.º 8
0
 def exportToLocation(self):
     return Location.from_dict(self.locationDict)