Ejemplo n.º 1
0
def test_vehicle_null_id(vehicle: Vehicle) -> None:
    Vehicle({
        "manufacturer": "Mazda",
        "model": "R",
        "year": 2000,
        "vin": "some_vin"
    })
Ejemplo n.º 2
0
def update_vehicle(vehicle_id: int, vehicle: Vehicle) -> JSONResponse:
    """Updates vehicle by it's ID.

    Operates "/rest/{id}" route on "PUT" request e.g "http://127.0.0.1:5000/rest/99".

    Passes following body structure sample:
    ```
        {
            "manufacturer": "BMW",
            "model": "X5",
            "year": 2011,
            "vin": "WBAWV53589P465532"
        }
    ```

    Args:
        vehicle_id: vehicle ID e.g `2`
        vehicle: a vehicle item

    Returns:
        http json response
    """
    if not list_of_vehicles.get(vehicle_id):
        return RESPONSE_ERROR
    vehicle.id_ = vehicle_id
    list_of_vehicles[vehicle_id] = vehicle
    return JSONResponse(vehicle, status_code=Status.SUCCESS.code)
Ejemplo n.º 3
0
def list_vehicles() -> List[Vehicle]:
    """Returns a list of vehicles.

    Operates "/rest" route on "GET" request e.g "http://127.0.0.1:5000/rest".
    """
    return list(
        map(lambda vehicle: Vehicle(vehicle[1]),
            sorted(list_of_vehicles.items())))
Ejemplo n.º 4
0
def vehicle() -> Vehicle:
    return Vehicle({
        "id_": 1,
        "manufacturer": "Mazda",
        "model": "RX-8",
        "year": 2006,
        "vin": "JTJBARBZ2F2356837"
    })
Ejemplo n.º 5
0
def test_vehicle_wrong_vin(vehicle: Vehicle) -> None:
    with pytest.raises(ValidationError):
        Vehicle({
            "manufacturer": "Mazda",
            "model": "R",
            "year": 2000,
            "vin": "v" * 51
        })
Ejemplo n.º 6
0
def test_vehicle_wrong_year(vehicle: Vehicle) -> None:
    with pytest.raises(ValidationError):
        Vehicle({
            "manufacturer": "Mazda",
            "model": "R",
            "year": 1899,
            "vin": "some_vin"
        })
Ejemplo n.º 7
0
def create_vehicle(vehicle: Vehicle) -> JSONResponse:
    """Creates a vehicle.

    Operates "/rest" route on "POST" request e.g "http://127.0.0.1:5000/rest".
    Passes following body structure sample:
    ```
        {
            "manufacturer": "BMW",
            "model": "X5",
            "year": 2011,
            "vin": "WBAWV53589P465532"
        }
    ```

    Args:
        vehicle: a vehicle

    Returns:
        http json response
    """
    vehicle.id_ = len(list_of_vehicles) + 1
    list_of_vehicles[vehicle.id_] = vehicle
    return JSONResponse(vehicle, status_code=Status.CREATED.code)