예제 #1
0
    def setUp(self):
        self.test_user = Passenger(email='*****@*****.**')
        self.test_user.set_access_type('passenger')
        User.insert(self.test_user)

        secret_key = self.app.config['SECRET_KEY']
        self.test_user_token = self.test_user.generate_token(secret_key)

        self.test_itinerary = Itinerary(id='1', name='test_itinerary')
        Itinerary.insert(self.test_itinerary)
예제 #2
0
    def setUp(self):
        super(ItineraryAddPartnerTestCase, self).setUp()

        self.test_driver = Driver(email='*****@*****.**')
        Driver.insert(self.test_driver)

        secret_key = self.app.config['SECRET_KEY']
        self.test_driver_token = self.test_driver.generate_token(secret_key)

        self.test_itinerary = Itinerary(id='1', name='test_itinerary')
        Itinerary.insert(self.test_itinerary)
예제 #3
0
    def setUp(self):
        super(ItineraryGetDriverItineraries, self).setUp()

        self.test_driver = Driver(email='*****@*****.**')
        Driver.insert(self.test_driver)

        secret_key = self.app.config['SECRET_KEY']
        self.test_driver_token = self.test_driver.generate_token(secret_key)

        self.test_itinerary = Itinerary(id='1', name='test_itinerary', owner='*****@*****.**',
                                        timestart='12:00', endtime='13:00', weekdays='Seg')
        Itinerary.insert(self.test_itinerary)
예제 #4
0
def update_driver_location(itinerary_id):
    data = request.get_json()

    itinerary = Itinerary.get_by_key(itinerary_id)

    if not itinerary:
        return jsonify({'errors': ['Itinerary not found']}), 404

    driver = Driver.get_by_email(g.user['email'])

    if not driver:
        return jsonify({'errors': ['Driver not found.']}), 404

    itinerary.update_driver_location(data)
    Itinerary.update(itinerary)

    return jsonify({'id': itinerary_id}), 201
예제 #5
0
def create():
    data = request.get_json()

    itinerary = Itinerary.get_by_key(data['itinerary_id'])
    data.pop("itinerary_id")

    schema = PassengerSchema(strict=True)
    data, errors = schema.load(data)

    if errors:
        return jsonify({'errors': errors}), 400

    user = Passenger(**data)
    user.set_password('123')
    result = User.insert(user)

    itinerary.add_passenger(user)
    Itinerary.update(itinerary)

    if result['errors']:
        return jsonify({'errors': result['first_error']}), 409

    return jsonify({'email': user['email']}), 201
예제 #6
0
def add_partner(itinerary_id):
    data = request.get_json()
    print(data)
    itinerary = Itinerary.get_by_key(itinerary_id)

    if not itinerary:
        return jsonify({'errors': ['Itinerary not found']}), 404
    '''schema = ItineraryAddPartnerSchema(strict=True)
    data, errors = schema.load(data)

    if errors:
        return jsonify({
            'errors': errors
        }), 409'''

    driver = Driver.get_by_email(data['name'])
    if not driver:
        return jsonify({'errors': ['Driver not found.']}), 404

    itinerary.add_partner(driver)
    Itinerary.update(itinerary)

    return jsonify({'id': itinerary_id}), 201
예제 #7
0
    def test_create_itinerary(self):
        url = url_for('itinerary.create')

        response = self.client.post(url, data=json.dumps({
            'name': 'IT123',
            'timestart': '06:00',
            'endtime': '07:00',
            'destination': {
                'street': 'Street 1',
                'neighborhood': 'Neigh 1',
                'city': 'City 1',
                'state': 'AB',
                'latitude': -27.4578,
                'longitude': -45.8796
            },
            'weekdays': 'Seg Ter Qua Qui Sex'
        }), headers={
            'Content-Type': 'application/json',
            'Authorization': self.test_driver_token
        })

        self.assertEqual(response.status_code, 201)

        itinerary = Itinerary.find_one({
            'name': 'IT123',
            'timestart': '06:00',
            'endtime': '07:00',
            'destination': {
                'street': 'Street 1',
                'neighborhood': 'Neigh 1',
                'city': 'City 1',
                'state': 'AB',
                'latitude': -27.4578,
                'longitude': -45.8796
            },
            'weekdays': 'Seg Ter Qua Qui Sex',
            'owner': '*****@*****.**',
            'drivers': []
        })

        self.assertIsNotNone(itinerary)
예제 #8
0
def notify(itinerary_id):
    data = request.get_json()

    itinerary = Itinerary.get_by_key(itinerary_id)

    if not itinerary:
        return jsonify({'errors': ['Itinerary not found']}), 404

    schema = AbsenceNotificationSchema(strict=True)
    data, errors = schema.load(data)

    if errors:
        return jsonify({'errors': errors}), 400

    notification = AbsenceNotification(**data)
    notification['itinerary_id'] = itinerary['id']
    notification['email'] = g.user['email']

    result = AbsenceNotification.insert(notification)

    if result['errors']:
        return jsonify({'errors': result['first_error']}), 409

    return jsonify({'message': notification['message']}), 201
예제 #9
0
def create():
    data = request.get_json()

    schema = ItinerarySchema(strict=True)
    data, errors = schema.load(data)

    if errors:
        return jsonify({'errors': errors}), 400

    itinerary = Itinerary(owner=g.user['email'],
                          drivers=[],
                          passengers=[],
                          **data)
    result = Itinerary.insert(itinerary, return_changes=True)

    itinerary = Itinerary(**result['changes'][0]['new_val'])

    g.user.insert_itinerary(itinerary)
    Driver.update(g.user)

    return jsonify({'id': itinerary.get_id()}), 201
예제 #10
0
def list_passenger_itineraries():

    itineraries = Itinerary.find_by_passenger(g.user['email'])

    return jsonify({"objects": list(itineraries)}), 201
예제 #11
0
def get_driver_location(itinerary_id):

    itinerary = Itinerary.get_by_key(itinerary_id)
    print(itinerary['driver_location'])

    return jsonify(itinerary['driver_location']), 201