def test_set_plane_occupancy_FAIL(self, mock_plane): plane_small = Plane(id=1, size="small", currentPassengerCount=0, maxPassengerCount=50) self.assertEqual(plane_small.setOccupancy(400), False) self.assertEqual(plane_small.Occupancy_Current, 0)
def test_set_plane_occupancy_PASS(self, mock_plane): plane_large = Plane(id=1, size="large", currentPassengerCount=0, maxPassengerCount=500) self.assertEqual(plane_large.setOccupancy(400), True) self.assertEqual(plane_large.Occupancy_Current, 400)
def __init__(self): self.planes = { plane0 = Plane(id=0, size="small", speed=1, airport_dest=0, airport_src=3, dt_depart=NOW, dt_arrival=NOW + 1, currentPassengerCount=0, maxPassengerCount=500), plane1 = Plane(id=1, size="small", speed=1, airport_dest=1, airport_src=2, dt_depart=NOW, dt_arrival=NOW + 1, currentPassengerCount=0, maxPassengerCount=500), plane0 = Plane(id=0, size="small", speed=1, airport_dest=0, airport_src=1, dt_depart=NOW, dt_arrival=NOW + 1, currentPassengerCount=0, maxPassengerCount=500), plane1 = Plane(id=1, size="small", speed=1, airport_dest=2, airport_src=3, dt_depart=NOW, dt_arrival=NOW + 1, currentPassengerCount=0, maxPassengerCount=500), } self.airports = { airport00 = Airport(id=0, name="0", x=0, y=0), airport01 = Airport(id=1, name="0", x=0, y=10), airport10 = Airport(id=2, name="0", x=10, y=0), airport11 = Airport(id=3, name="1", x=10, y=10), } def getPlane(id)
def test_get_plane_airline_Null(self, mock_Gate): plane1 = Plane(id="1", size="small") mock_Gate.getPlane.side_effect = has_airline(True) if plane1.getAirline() is None: # This test should fail. Every plane must have a parent airline. self.assertEqual(True, False)
def __init__(self): self.planes = { plane0 = Plane(id=0, size="small", speed=1, airport_dest=0, airport_src=3, dt_depart=NOW, dt_arrival=NOW + 1, currentPassengerCount=0, maxPassengerCount=500), plane1 = Plane(id=1, size="small", speed=1, airport_dest=3, airport_src=0, dt_depart=NOW, dt_arrival=NOW + 1, currentPassengerCount=0, maxPassengerCount=500), plane0 = Plane(id=0, size="small", speed=1, airport_dest=0, airport_src=1, dt_depart=NOW, dt_arrival=NOW + 1, currentPassengerCount=0, maxPassengerCount=500), plane1 = Plane(id=1, size="small", speed=1, airport_dest=2, airport_src=3, dt_depart=NOW, dt_arrival=NOW + 1, currentPassengerCount=0, maxPassengerCount=500), } def getPlane(id)
def has_plane(doesHave: bool): return Plane( id=1, size="small", currentPassengerCount=5, maxPassengerCount=500) if doesHave else None
class FakeGates: def __init__(self): self.gates = { Junct(gate_id=1, plane_id=1, dt_available=NOW), Junct(gate_id=2, plane_id=2, dt_available=NOW), } def checkGate(self, gate_id, plane_eta): return self.gates.filter(gate_id=gate_id).filter( dt_available__lt=plane_eta) plane = Plane(id=1, size="small", currentPassengerCount=0, maxPassengerCount=500) @mock.patch("classes.models.Plane") class UnitTestCases(TestCase): def test_assign_FAIL(self, mock_plane): mock_plane.check_gate.side_effect = FakeGates.checkGate(2, NOW - 1) self.assertEqual(plane.check_gate(1), False) # FAIL, since gate is not avaialable yet def test_assign_PASS(self, mock_plane): mock_plane.check_gate.side_effect = FakeGates.checkGate(2, NOW + 1) self.assertEqual(plane.check_gate(1), True) # PASS, since gate is avaialable then
self.gates = { Junct(id=1, size="small"), Junct(id=2, size="medium"), Junct(id=3, size="large"), } def getPlane(self, gate_id): return self.gates.get(gate_id=gate_id) def fake_gate(gate_id: int): return lambda: FakeGates.getGate(gate_id) plane_small = Plane(id=1, size="small", currentPassengerCount=0, maxPassengerCount=500) plane_large = Plane(id=2, size="large", currentPassengerCount=0, maxPassengerCount=500) @mock.patch("classes.models.Gate") class UnitTestCases(TestCase): def test_too_small_Gate(self, mock_plane): mock_plane.fetchGate.side_effect = fake_gate(1) self.assertEqual(plane_large.setGate(1), False) def test_large_Gate(self, mock_datetime):
def test_get_plane_gate_Null(self, mock_Gate): plane1 = Plane(id="1", size="small") mock_Gate.getGate.side_effect = has_gate(False) self.assertEqual(plane1.getGate(), None)
def test_get_plane_gate(self, mock_Gate): plane1 = Plane(id="1", size="small") mock_Gate.getPlane.side_effect = has_gate(True) self.assertEqual(plane1.getGate(), not None)