Example #1
0
    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 testRaiseRequestAlreadyExistsError(self):
        # Create new rideRequests
        for userId in self.userIds:
            form = FormDictFactory().create(returnDict=True)
            form["flightLocalTime"] = "2018-12-20T12:00:00.000"
            form["testUserId"] = userId
            r = self.app.post(  # TODO: change everywhere to json=form (used to be json=json.dumps(form))
                path='/rideRequests', json=form, headers=getMockAuthHeaders(userId))
            print(r.json)
            # self.assertRaises(service_errors.RequestAlreadyExistsError)
            # self.assertIn("firestoreRef", r.json.keys())
            firestore_ref = r.json["firestoreRef"]  # Not that it is actually rideRequestId
            self.ride_request_ids_to_delete.append((userId, firestore_ref))

        userId = self.userIds[0]
        r = self.app.post(  # TODO: change everywhere to json=form (used to be json=json.dumps(form))
            path='/rideRequests', json=form, headers=getMockAuthHeaders(userId))
        print(r.json)
        error_return_expected = {
                "message": "Ride request on the same day (or for the same event) already exists",
                "status": 400
            }
        error_message_expected = error_return_expected["message"]
        error_status_code_expected = error_return_expected["status"]
        self.assertEqual(r.json["message"], error_message_expected)
        self.assertEqual(r.status_code, error_status_code_expected)
Example #3
0
    def setUp(self):

        main.app.testing = True
        self.app = main.app.test_client()
        self.userIds = ["testuid1", "testuid2"]
        self.c = scripts.SetUpTestDatabase()
        self.c.clear_before()
        self.c.generate_test_data(start_string="2018-12-17T08:00:00.000",
                                  num_days=5)

        for userId in self.userIds:
            form = FormDictFactory().create(returnDict=True)
            form["flightLocalTime"] = "2018-12-20T12:00:00.000"
            form["testUserId"] = userId
            r = self.app.post(  # TODO: change everywhere to json=form (used to be json=json.dumps(form))
                path='/rideRequests',
                json=form,
                headers=getMockAuthHeaders(userId))
            print(r.json)
            # self.assertRaises(service_errors.RequestAlreadyExistsError)
            firestore_ref = r.json[
                "firestoreRef"]  # Not that it is actually rideRequestId
            self.ride_request_ids_to_unmatch.append((userId, firestore_ref))
            self.ride_request_ids_to_delete.append((userId, firestore_ref))

        uid, rid = self.ride_request_ids_to_delete[0]
        self.rideRequestId = rid

        r = self.app.post(path='/devForceMatch',
                          json=json.dumps({
                              "operationMode":
                              "two",
                              "rideRequestIds":
                              [i[1] for i in self.ride_request_ids_to_delete]
                          }))
    def testDeleteReturnsRequestAlreadyMatchedError(self):
        """
        Test that trying to delete ride request that is already matched would return an error
        :return:
        """
        for userId in self.userIds:
            form = FormDictFactory().create(returnDict=True)
            form["flightLocalTime"] = "2018-12-20T12:00:00.000"
            form["testUserId"] = userId
            r = self.app.post(  # TODO: change everywhere to json=form (used to be json=json.dumps(form))
                path='/rideRequests', json=form, headers=getMockAuthHeaders(userId))
            print(r.json)
            # self.assertRaises(service_errors.RequestAlreadyExistsError)
            firestore_ref = r.json["firestoreRef"]  # Not that it is actually rideRequestId
            self.ride_request_ids_to_unmatch.append((userId, firestore_ref))
            self.ride_request_ids_to_delete.append((userId, firestore_ref))

        uid, rid = self.ride_request_ids_to_delete[0]

        r = self.app.post(path='/devForceMatch',
                          json=json.dumps({"operationMode": "two",
                                           "rideRequestIds": [i[1] for i in self.ride_request_ids_to_delete]
                                           })
                          )
        r = self.app.delete(path='/rideRequests' + '/' + rid,
                            headers=getMockAuthHeaders(uid=uid)
                            )
        error_return_expected = {
            "message": "Ride request has requestCompletion as True. Un-match from an orbit first. ",
            "status": 500
        }
        error_message_expected = error_return_expected["message"]
        error_status_code_expected = error_return_expected["status"]
        self.assertEqual(r.json["message"], error_message_expected)
        self.assertEqual(r.status_code, error_status_code_expected)
 def setUp(self):
     d = FormDictFactory().create(hasEarliestLatest=True,
                                  returnDict=True,
                                  isE5L2=False)
     self.user_id = 'testuserid1'
     self.builder = service_utils.AirportRideRequestBuilder(
     ).set_with_form_and_user_id(d, user_id=self.user_id)
Example #6
0
 def testCreation(self):
     formDict = FormDictFactory().create(hasEarliestLatest=False,
                                         returnDict=True)
     form: RideRequestCreationValidateForm = RideRequestCreationValidateForm(
         data=formDict)
     form.validate()
     self.assertDictEqual(formDict, form.data)
 def testCreateRideRequestsTemp(self):
     # Create new rideRequests
     for userId in self.userIds:
         form = FormDictFactory().create(returnDict=True)
         form["flightLocalTime"] = "2018-12-20T12:00:00.000"
         form["testUserId"] = userId
         r = self.app.post(  # TODO: change everywhere to json=form (used to be json=json.dumps(form))
             path='/rideRequests', json=form, headers=getMockAuthHeaders(userId))
         print(r)
         self.assertIn("firestoreRef", r.json.keys())
         firestore_ref = r.json["firestoreRef"]  # Not that it is actually rideRequestId
         self.ride_request_ids_to_delete.append((userId, firestore_ref))
Example #8
0
def _create_ride_requests_for_tests(app, userIds, to_tear_down,
                                    rideRequestIds):

    for userId in userIds:

        form = FormDictFactory().create(returnDict=True)
        form["flightLocalTime"] = "2018-12-20T12:00:00.000"
        r = app.post(path='/rideRequests',
                     json=form,
                     headers=getMockAuthHeaders(uid=userId))
        print(r.data)
        assert r.status_code == 200
        rideRequestIds.append(r.json["firestoreRef"])
        to_tear_down.append((userId, r.json["firestoreRef"]))
Example #9
0
 def testCreateAirportTarget(self):
     mock_form = FormDictFactory().create(hasEarliestLatest=False,
                                          returnDict=False)
     target_dict = Target.create_with_flight_local_time(
         mock_form.flightLocalTime,
         mock_form.toEvent,
         offset_low_abs_sec=3600,
         offset_high_abs_sec=10800).to_dict()
     value_expected = {
         'eventCategory': 'airportRide',
         'toEvent': True,
         'arriveAtEventTime': {
             'earliest': 1545066000,
             'latest': 1545073200
         }
     }
     self.assertDictEqual(target_dict, value_expected)
    def testSetWithForm(self):
        userId = 'testuserid1'
        d = FormDictFactory().create(hasEarliestLatest=False, returnDict=True)

        b = service_utils.AirportRideRequestBuilder(
        ).set_with_form_and_user_id(d, user_id=userId)
        expected_vars = {
            'user_id': 'testuserid1',
            'flight_local_time': '2018-12-17T12:00:00.000',
            'flight_number': 'DL89',
            'airport_code': 'LAX',
            'pickup_address': 'Tenaya Hall, San Diego, CA 92161',
            'driver_status': False,
            'to_event': True
        }

        # Assert that all required variables are set
        self.assertTrue(expected_vars.items() <= vars(b).items())
    def testCreateRideRequestsEarliestLatest(self):
        # Create new rideRequests
        for userId in self.userIds:
            form = FormDictFactory().create(returnDict=True, hasEarliestLatest=True, isE5L2=False)
            form["flightLocalTime"] = "2018-12-20T12:00:00.000"
            form["testUserId"] = userId
            r = self.app.post(  # TODO: change everywhere to json=form (used to be json=json.dumps(form))
                path='/rideRequests', json=form, headers=getMockAuthHeaders(userId))
            print(r)
            self.assertIn("firestoreRef", r.json.keys())
            firestore_ref = r.json["firestoreRef"]  # Not that it is actually rideRequestId
            self.ride_request_ids_to_delete.append((userId, firestore_ref))

            r = self.app.get(path='/rideRequests' + '/' + firestore_ref,
                             headers=getMockAuthHeaders()
                             )

            result = dict(r.json)
            self.assertEqual(result["target"]["arriveAtEventTime"]["earliest"], 1545066000)
Example #12
0
    def testSetVariables(self):
        userId = 'testuserid1'
        d = FormDictFactory().create(hasEarliestLatest=False, returnDict=True)

        b = RideRequestBaseBuilder().set_data(
            user_id=userId,
            flight_local_time=d["flightLocalTime"],
            flight_number=d["flightNumber"],
            # pricing=d["pricing"],  # diabilities=d["disabilities"], baggages=d["baggages"],
            airport_code=d["airportCode"],
            to_event=d["toEvent"],
            pickup_address=d["pickupAddress"],
            driver_status=d["driverStatus"])
        expected_vars = {
            'user_id': 'testuserid1',
            'flight_local_time': '2018-12-17T12:00:00.000',
            'flight_number': 'DL89',
            'airport_code': 'LAX',
            'pickup_address': 'Tenaya Hall, San Diego, CA 92161',
            'driver_status': False,
            'to_event': True,
        }
        # Assert that all required variables are set
        self.assertTrue(expected_vars.items() <= vars(b).items())
Example #13
0
 def testPrintMockForm(self):
     formDict = FormDictFactory().create(hasEarliestLatest=False,
                                         returnDict=True)
     print(json.dumps(formDict))