async def test_no_parking_lots_retry(http_client, base_url): car_id = str(uuid4()) car_cli = await CarWebsocket.create( base_url=base_url.replace('http', 'ws') + "/ws", user_id=car_id) logger.debug("car websocket client connected") response = await car_cli.send_parking_request(Location(0.0, 1.0), {}) logger.debug(f'requested allocation: {response}') allocated = await car_cli.receive(wsmodels.ErrorMessage) logger.debug(f'allocation failed: {allocated}') assert allocated.error.msg == 'No parking lot available.' cli = ParkingLotRest(base_url, http_client) lot = ParkingLot(10, 'a', 1.0, Location(0.0, 1.0)) response = await cli.create_lot(lot) lot.id = response logger.debug(f'created lot {response}') response = await car_cli.send_parking_request(Location(0.0, 1.0), {}) logger.debug(f'requested allocation: {response}') allocated = await car_cli.receive(wsmodels.ParkingAllocationMessage) logger.debug(f'allocation recieved: {allocated}') assert allocated.lot.id == lot.id
async def test_create_parking_lot_confirm(caplog, http_client, base_url): caplog.set_level(logging.INFO) # create parking lot... cli = ParkingLotRest(base_url, http_client) lot = ParkingLot(10, 'a', 1.0, Location(0.0, 1.0)) response = await cli.create_lot(lot) lot.id = response await asyncio.sleep(1) # create car car_id = str(uuid4()) car_cli = await CarWebsocket.create( base_url=base_url.replace('http', 'ws') + "/ws", user_id=car_id) response = await car_cli.send_parking_request(Location(0.0, 1.0), {}) # ask for allocation allocated = await car_cli.receive(wsmodels.ParkingAllocationMessage) assert allocated.lot.id == lot.id # accept allocation await car_cli.send_parking_acceptance(allocated.lot.id) # wait for confirmation await car_cli.receive(wsmodels.ConfirmationMessage)
async def test_create_multiple_parking_lot(http_client, base_url): cli = ParkingLotRest(base_url, http_client) lot = ParkingLot(10, 'a', 1.0, Location(0.0, 1.0)) response = await cli.create_lot(lot) lot.id = response logger.debug(f'[test_create_parking_lot] created lot {lot.id}') lot2 = ParkingLot(10, 'b', 1.0, Location(2.0, 2.0)) response = await cli.create_lot(lot2) lot2.id = response logger.debug(f'[test_create_parking_lot] created lot2 {lot2.id}') car_id = str(uuid4()) car_cli = await CarWebsocket.create( base_url=base_url.replace('http', 'ws') + "/ws", user_id=car_id) logger.debug("car websocket client connected") response = await car_cli.send_parking_request(Location(0.0, 1.0), {}) logger.debug(f'requested allocation: {response}') allocated = await car_cli.receive(wsmodels.ParkingAllocationMessage) logger.debug(f'allocation recieved: {allocated}') assert allocated.lot.id == lot.id