Esempio n. 1
0
def test_pooling_load_second():
    service = CarPooling([(1, -2), (-2, 3), (3, 0), (0, 4), (2, 3), (6, 7)])
    assert len(service.car_pooling) == 1
    assert service.car_pooling.get(2)
    assert service.car_pooling.get(1) is None  # outbound minus seats
    assert service.car_pooling.get(-2) is None  # outbound minus index
    assert service.car_pooling.get(3) is None  # outbound cero seats
    assert service.car_pooling.get(0) is None  # outbound cero index
    assert service.car_pooling.get(6) is None  # outbound seats
Esempio n. 2
0
def test_journey_waiting_first():
    service = CarPooling([(1, 3), (2, 2), (3, 1), (4, 3)])
    assert service.journey(1, 6) == 0  # waiting list
    assert service.journey(2, 6) == 0  # waiting list
    assert service.journey(3, 1) == 3  # allocated (*)
    assert service.journey(4, 6) == 0  # waiting list
    assert service.drop_off(1) == 1  # drop-off
    assert service.drop_off(4) == 4
    assert service.drop_off(5) is None  # drop-off not found
    service.cars([(1, 5), (2, 2), (3, 1), (4, 3), (5, 6),
                  (6, 4)])  # new car list
    assert service.journey(
        5, 6) == 0  # waiting list first -> new one go to waiting list
    assert service.journey(6, 4) == 6  # new journey request
    assert service.journey(7, 6) == 0
    assert len(service.journey_request.waiting) == 2  # waiting list not empty
    assert service.journey_location.is_allocated(
        6) == 6  # check car allocation
    assert service.journey_location.is_allocated(
        3) == 3  # allocated from previous car list (*)
    assert service.journey(8, 3)
    assert service.journey_location.is_allocated(
        8) == 4  # allocated from new car list
Esempio n. 3
0
def test_journey_dropoff():
    service = CarPooling([(1, 3), (2, 2), (3, 1), (4, 3)])
    assert service.journey(1, 6) == 0
    assert service.drop_off(1) == 1
    assert service.drop_off(1) is None
Esempio n. 4
0
def test_journey_sixth():
    service = CarPooling([(1, 4), (1, 3), (1, 1),
                          (1, 7)])  # (1, 7) bad request
    assert service.journey(1, 4) == 0  # dictionary integrity
Esempio n. 5
0
def test_journey_fifth():
    service = CarPooling([(1, 3), (4, 4), (7, 6)])
    assert service.journey(1, 1) == 1
Esempio n. 6
0
def test_journey_fourth():
    service = CarPooling([(1, 2), (2, 3)])
    assert service.journey(1, 7) == -1
Esempio n. 7
0
def test_journey_third():
    service = CarPooling([])
    assert service.journey(1, 5) == 0
Esempio n. 8
0
def test_journey_second():
    service = CarPooling([(1, 2), (2, 3)])
    assert service.journey(1, 5) == 0
Esempio n. 9
0
def test_pooling_load_first():
    service = CarPooling([])
    assert len(service.car_pooling) == 0
    service.cars([(1, 2), (2, 3), (3, 0)])
    assert service.car_pooling is not None
Esempio n. 10
0
def test_journey_fist():
    service = CarPooling([(1, 3), (2, 4), (3, 6)])
    assert service.journey(1, 5) == 3
Esempio n. 11
0
def test_pooling_load_third():
    service = CarPooling([])
    assert len(service.car_pooling) == 0
Esempio n. 12
0
    * **404 Not Found** When the group is not to be found.
    * **400 Bad Request** When there is a failure in the request format or the
      payload can't be unmarshalled.
    """
    try:
        if request.headers[
                "content-type"] != 'application/x-www-form-urlencoded':
            return Response(status_code=status.HTTP_400_BAD_REQUEST)

        if ID is None:
            return Response(status_code=status.HTTP_400_BAD_REQUEST)

        journey_id = int(ID)
        car_id = car_pooling.journey_location.is_allocated(journey_id)
        if car_id is None:  # car ID not found
            return Response(status_code=status.HTTP_404_NOT_FOUND)
        elif car_pooling.journey_request.is_waiting(
                journey_id):  # car ID waiting
            return Response(status_code=status.HTTP_204_NO_CONTENT)
        else:  # car ID located
            return JSONResponse(content={'car_id': car_id},
                                status_code=status.HTTP_200_OK)

    except Exception:
        return Response(status_code=status.HTTP_400_BAD_REQUEST)


if __name__ == "__main__":
    car_pooling = CarPooling()
    uvicorn.run(app, host="0.0.0.0", port=9091, log_level="info")