Example #1
0
def test_trip_price():
    """
    Location:
     *  0-30 min: gratuit
     * 30-60 min: 0.5
     * 60-90 min: 1.5
     * 90+ min: 1.5 + 2*(min-90)/30
    """
    from_date, to_date = "2015-07-12T10:10:10", "2015-07-12T10:20:10"

    t = db.Trip(
        user_id=42, bike_id=42, departure_station_id=42,
        departure_date=from_date, arrival_date=to_date)
    assert t.duration().total_seconds() == 600
    assert t.price() == 0

    t.arrival_date = parse_date("2015-07-12T10:50:10")
    assert t.duration().total_seconds() == 2400
    assert t.price() == 0.5

    t.arrival_date = parse_date("2015-07-12T11:20:10")
    assert t.duration().total_seconds() == 4200
    assert t.price() == 1.5

    t.arrival_date = parse_date("2015-07-12T11:50:10")
    assert t.duration().total_seconds() == 6000
    assert t.price() == 3.5
Example #2
0
def add_absence(p):
    if p['student'] not in data['students']:
      jsonabort(400, 'Could not find student in database')

    try:
        m.parse_date(p['startdate'])
        m.parse_date(p['enddate'])
    except:
        jsonabort(400, '{} or {} is not in the form YYYY-mm-dd'.format(
          p['startdate'], p['enddate']))

    if p['enddate'] < p['startdate']:
        jsonabort(400, 'Enddate should be greater than startdate')

    if p['enddate'] == p['startdate']:
        data['students'][p['student']].add_absence(p['startdate'])

    data['students'][p['student']].add_absence(p['startdate'], p['enddate'])
    return data['students'][p['student']].json
Example #3
0
def test_trip_is_insertion():
    u = db.User.create(password="******")
    b = db.Bike.create(model="mytest")
    s = db.Station.create(
        latitude=50.3245, longitude=4.0326, 
        name="Station 1", capacity=42, payment=True)
    date = "2015-07-12T10:10:10"

    t = db.Trip.create(
        departure_station_id=s.id, arrival_station_id=s.id,
        departure_date=date, arrival_date=date,
        user_id=u.id, bike_id=b.id
    )
    assert t.is_insertion()

    u.expire_date = parse_date("2015-09-11T10:00:00")
    u.update()
    assert not t.is_insertion()
Example #4
0
def create_interaction(p):
    try:
      m.parse_date(p['date'])
    except:
      jsonabort(400, "{} is not a date string in the form YYYY-mm-dd".format(
          p['date']))

    if p['student'] not in data['students']:
      jsonabort(400, 'Student {} does not exist'.format(p['student']))

    try:
      m.parse_date(p['time_in'])
    except:
      jsonabort(400, "{} is not a time string in the form HH:mm:ss".format(
          p['date']))

    try:
      m.parse_date(p['time_out'])
    except:
      jsonabort(400, "{} is not a date string in the form HH:mm:ss".format(
          p['date']))

    data['interactions'].append(m.Interaction(**p))