def test_create(self):
     main.user_sublocation_mediator.start()
     main.user_location_mediator.start()
     main.user_location_view_mediator.start()
     doc_ref: firestore.DocumentReference = \
         CTX.db.document(self.expected_path)
     form = {
         'latitude': 32.8794203,
         'longitude': -117.2428555,
         'address': 'Tenaya Hall, San Diego, CA 92161',
         'placeId': 'test_place_id_1',
     }
     doc_ref.create(
         document_data=form
     )
     testing_utils._wait()
     user_location = UserLocation.get(doc_id=self.doc_id)
     d = user_location.to_dict()
     assert d.items() >= {'obj_type': 'UserLocation', 'placeId': 'test_place_id_1',
                  'sublocations': [], 'doc_id': 'test_doc_id_1',
                  'userId': 'user_id_1',
                  'doc_ref': 'locations/test_doc_id_1',
                  'coordinates': {'longitude': -117.2428555,
                                  'latitude': 32.8794203},
                  'address': 'Tenaya Hall, San Diego, CA 92161'}.items()
    def test_view(self):
        main.user_sublocation_mediator.start()
        main.user_location_mediator.start()
        main.user_location_view_mediator.start()
        doc_ref = CTX.db.document(self.user_location_path)
        doc_ref.set(
            document_data={'placeId': 'test_place_id_1',
                           'userId': 'user_id_1',
                           'longitude': -117.2428555,
                           'latitude': 32.8794203,
                           'address': 'Tenaya Hall, San Diego, CA 92161',
                           'id': 'test_doc_id_1',
                           }
        )

        testing_utils._wait()
        snapshot = UserLocation.ref_from_id(doc_id=self.user_location_id).get()
        obj = UserLocationView.new(
            snapshot=snapshot
        )
        assert obj.to_dict().items() >= {
            'id': 'test_doc_id_1',
            'address': 'Tenaya Hall, San Diego, CA 92161',
            'latitude': 32.8794203,
            'longitude': -117.2428555,
            'placeId': 'test_place_id_1',
            'sublocations': []
        }.items()
 def setUp(self):
     testing_utils._delete_all(CTX, subcollection_name="sublocations_POST")
     testing_utils._delete_all(CTX, collection_name="locations")
     self.user_id = "user_id_1"
     self.doc_id = "test_doc_id_1"
     self.expected_path = "users/user_id_1/locations_POST/test_doc_id_1"
     self.app = main.app.test_client()  # to make sure that main is run
     testing_utils._wait()
Esempio n. 4
0
    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 test_new(self):
     obj = UserSublocationForm.new(
         doc_id=self.doc_id,
         user_location_id=self.user_location_id,
         latitude=32.87952213052025,
         longitude = -117.2436009719968
     )
     testing_utils._wait(1)
     assert obj.location.address == \
            "Scholars Dr S, San Diego, CA 92161, USA"
Esempio n. 6
0
    def testCreateTrip(self):

        orbit_id = Orbit.create_one()

        Orbit.match(orbit_id=orbit_id,
                    hosting_id=self.ride_host.doc_id,
                    rider_records=[(self.rider_booking.doc_id, self.a.doc_id,
                                    self.b.doc_id)])

        testing_utils._wait()

        CTX._enable_logging()
        from gravitate.domain.matcher.orbit import OrbitTripMediator

        orbit_trip_mediator = OrbitTripMediator(query=Orbit.get_query())
        orbit_trip_mediator.start()

        testing_utils._wait(factor=2)

        order_path = f"orders/{self.rider_booking.doc_id}"
        order_doc_ref: DocumentReference = CTX.db.document(order_path)
        assert order_doc_ref.get().to_dict() == {
            'created_at': '2020-05-06T15:13:17Z',
            'driver': {
                'device_id': '',
                'id': 'testuid1',
                'name': 'My Name',
                'phone_number': '',
                'role': 'driver'
            },
            'dropoff': {
                'address': 'Library Walk',
                'latitude': 32.877622,
                'longitude': -117.2375391
            },
            'pickup': {
                'address': '3915-3927',
                'latitude': 32.8683701,
                'longitude': -117.2221759
            },
            'rider': {
                'device_id': '',
                'id': 'testuid2',
                'name': 'My Name',
                'phone_number': '',
                'role': 'rider'
            },
            'status': 'ACCEPTED',
            'updated_at': '2020-05-06T15:13:17Z'
        }
    def test_view_with_sublocation(self):
        main.user_sublocation_mediator.start()
        main.user_location_mediator.start()
        main.user_location_view_mediator.start()
        doc_ref = CTX.db.document(self.user_location_path)
        doc_ref.set(
            document_data={'placeId': 'test_place_id_1',
                           'userId': 'user_id_1',
                           'longitude': -117.2428555,
                           'latitude': 32.8794203,
                           'address': 'Tenaya Hall, San Diego, CA 92161',
                           'id': 'test_doc_id_1',
                           }
        )

        testing_utils._wait()

        sublocation_ref = CTX.db.document(self.expected_path)
        sublocation_ref.create(
            document_data={
                'latitude': 32.87952213052025,
                'longitude': -117.2436009719968,
            }
        )

        testing_utils._wait()

        snapshot = UserLocation.ref_from_id(doc_id=self.user_location_id).get()
        obj = UserLocationView.new(
            snapshot=snapshot
        )
        assert obj.to_dict().items() >= {
            'id': 'test_doc_id_1',
            'address': 'Tenaya Hall, San Diego, CA 92161',
            'latitude': 32.8794203,
            'longitude': -117.2428555,
            'placeId': 'test_place_id_1',
            'sublocations': [
                {'address': 'Scholars Dr S, San Diego, CA 92161, USA',
                 'coordinates': {'latitude': 32.87952213052025,
                                 'longitude': -117.2436009719968},
                 'doc_id': 'sublocation_id',
                 'doc_ref': 'locations/sublocation_id',
                 'obj_type': 'Sublocation'}]
        }.items()
Esempio n. 8
0
    def testMatch(self):
        from gravitate.main import orbit_view_mediator
        from gravitate.algo_server import booking_target_mediator

        orbit_view_mediator.start()

        booking_target_mediator.start()

        target_repo = TargetRepo()
        rider_target_mediator = RiderTargetMediator(
            target_repo=target_repo, query=RiderTarget.get_query())
        rider_target_mediator.start()

        testing_utils._wait()  # Necessary

        host_target_search_mediator = HostTargetSearchMediator(
            target_repo=target_repo, query=RideHost.get_query())
        host_target_search_mediator.start()

        testing_utils._wait(factor=10)

        # for _doc in CTX.db.collection("Orbit").stream():
        #     doc = _doc
        #     break
        # else:
        #     raise
        #
        # view = OrbitView.new(snapshot=doc)
        # is_iterable_but_not_string(view)

        for doc in CTX.db.collection(
                f"users/{self.userIds[1]}/bookings/{self.rider_booking.doc_id}/orbits"
        ).stream():
            assert isinstance(doc, DocumentSnapshot)
            print(doc.to_dict())
            # assert False
            json.dumps(doc.to_dict())
            break
        else:
            # Should contain at least one element
            assert False
    def test_create(self):
        main.user_sublocation_mediator.start()
        main.user_location_mediator.start()
        main.user_location_view_mediator.start()
        doc_ref = CTX.db.document(self.user_location_path)
        UserLocation.new(doc_id=self.user_location_id,
                         user_id=self.user_id,
                         **{
            'coordinates': {
                           'longitude': -117.2428555,
                           'latitude': 32.8794203},
                           'address': 'Tenaya Hall, San Diego, CA 92161'}
        ).save()

        testing_utils._wait()

        sublocation_ref = CTX.db.document(self.expected_path)
        sublocation_ref.create(
            document_data={
                'latitude': 32.87952213052025,
                'longitude': -117.2436009719968,
            }
        )

        # Tests that a new location is created
        testing_utils._wait()
        sublocation = Sublocation.get(doc_id=self.doc_id)
        d = sublocation.to_dict()
        assert d == {'coordinates': {'longitude': -117.2436009719968,
                                     'latitude': 32.87952213052025},
                     'doc_id': 'sublocation_id',
                     'obj_type': 'Sublocation',
                     'doc_ref': 'locations/sublocation_id',
                     'address': 'Scholars Dr S, San Diego, CA 92161, USA'}

        # Tests that the new location is registered as a sublocation
        #       of the parent UserLocation
        user_location = UserLocation.get(doc_id=self.user_location_id)
        d = user_location.to_dict()
        assert d["sublocations"] == [sublocation.doc_ref]
        testing_utils._wait()