def registerVehicle(path, postBody): response = {} try: fleet_id = path.split("/")[1] if not(validFleet(ObjectId(fleet_id))): raise PyMongoError(f"Fleet with ID: {fleet_id} does not exist") vehicleClass = Vehicle(postBody['vehicle_model'], postBody['license_plate'], postBody['vehicle_status'], ObjectId(fleet_id) ) vehicleObj = vehicleClass.get_register_data() # 2. Open a new database connection client = mongoConnect() # 3. write data from the database db = client.team12_supply # check vehicle = db.vehicle if (vehicle.count_documents({'license_plate': vehicleObj['license_plate']}) == 0): vehicleID = vehicle.insert_one(vehicleObj).inserted_id response = {'status': 'OK', 'data': {'fleet_id': vehicleObj['fleet_id'], 'vehicle_model': vehicleObj['vehicle_model'], 'license_plate': vehicleObj[ 'license_plate'], 'vehicle_status': vehicleObj['vehicle_status'], '_id': vehicleID, "current_location": vehicleObj["current_location"]}} else: response = {'status': 'CONFLICT', 'data': {'msg': 'Vehicle already registered'}} except PyMongoError as err: response = {'status': 'CONFLICT', 'data': { 'msg': err}} except ValueError as err: response = {'status': 'CONFLICT', 'data': { 'msg': err}} except Exception as err: logging.error(err) response = {'status': 'INTERNAL_SERVER_ERROR', 'data': { 'msg': 'Server stopped working, please try again later'}} return response
def __init__(self): # make instances # power source self.battery = Battery(90, 60, 7.7) # kWh,lb,kw # gal,lb,pound per gallon self.gastank = GasTank(25, 24, 6) # lb,w self.solarPanel = SolarPanel(44.5, 315) self.electricEngine = EletricEngine( 'EE1', 150, [self.battery * 8], [self.solarPanel * 1]) self.gasEngine = GasEngine('GE1', 449, [self.gastank * 9]) self.mask = Cargo('Mask', 0.525, (5.625, 5.625, 8)) self.ventilator = Cargo('Ventilator', 25, (24, 12, 24)) #self.vehicle = Vehicle(4600-25-449, 1920, 536.4+396, [self.gasEngine]) self.vehicle = Vehicle(4600-25-449, 1920, 536.4+396, [self.electricEngine]) departure = Coordinate(32.71573611111111, -117.161086111111120) destination = Coordinate(42.65258055555555, -73.75623333333333) monument = Coordinate(36.998980555555555, -109.04518611111111) self.pathA = Path([departure, destination]) self.pathB = Path([departure, monument, destination],[.1705,.0528]) self.pathC = Path([departure, destination], [3, -3] * 22) self.tz_PST = pytz.timezone('America/Los_Angeles') self.tz_UTC = pytz.utc self.departDatetime = datetime( 2020, 8, 31, 12, 00, tzinfo=self.tz_PST).astimezone(self.tz_UTC)
def updateVehicle(postBody): response = {} try: vehicle_id = postBody['vehicle_id'] vehicleDoc = getVehicles({"_id": ObjectId(vehicle_id)})[0] vehicleInst = Vehicle(vehicleDoc['vehicle_model'], vehicleDoc['license_plate'], vehicleDoc['vehicle_status'], vehicleDoc['fleet_id'] ) if "vehicle_status" in postBody: vehicleInst.setVehicleStatus(postBody['vehicle_status']) if "current_location" in postBody: vehicleInst.setCurrentLocation(postBody['current_location']) vehicleObj = vehicleInst.get_register_data() updateVehicleDoc(vehicleDoc['_id'], vehicleObj) response = {'status': 'OK', 'data': {'fleet_id': vehicleObj['fleet_id'], 'vehicle_model': vehicleObj['vehicle_model'], 'license_plate': vehicleObj[ 'license_plate'], 'vehicle_status': vehicleObj['vehicle_status'], '_id': vehicle_id, "current_location": vehicleObj["current_location"]}} except Exception as err: print(err) response = {"status": "INTERNAL_SERVER_ERROR", "data": { "msg": "Server stopped working, please try again later"}} return response
def setUp(self): self.vehicle = Vehicle("testmodel", "588TST", "available", ObjectId("6070a81d27d869d2d83ffeca"))
if (cpi.num_ports == len(cpi.ports)): print("Pass: Simulator num ports test") else: print("Fail: Simulator num ports test") if (cpi.get_load() == 0.0): print("Pass: Simulator no load test") else: print("Fail: Simulator no load test") if (cpi.get_num_charge_sessions() == 0): print("Pass: Simulator no charge sessions test") else: print("Fail: Simulator no charge sessions test") v = Vehicle("Goofy") v.set_specs("Prius", 100, 6, 1, 80) v.set_charge(50.0) free_port = cpi.get_free_port() if (free_port is not None): print("Pass: Simulator free port test") else: print("Fail: Simulator free port test") plugin_port = cpi.plugin(v) if (plugin_port is not None): print("Pass: Simulator vehicle plugin test") else: print("Fail: Simulator vehicle plugin test") if (cpi.get_num_charge_sessions() == 1):
def setUp(self): self.vehicle = Vehicle()
class TestVehicle(unittest.TestCase): def setUp(self): self.vehicle = Vehicle() def test_vehicle_can_start_engine(self): self.assertEqual("Vrrmmm", self.vehicle.start_engine())