Example #1
0
class TestUserStory(unittest.TestCase):
    def setUp(self):
        self.airport = Airport()
        self.plane = Plane()

    def test_instructing_a_plane_to_land_should_land_it(self):
        # As an air traffic controller
        # So I can get passengers to a destination
        # I want to instruct a plane to land at an airport and confirm that it has landed
        self.airport.instruct_to_land(self.plane)
        self.assertIn(self.plane, self.airport.planes)
        self.assertFalse(self.plane.isflying)

    def test_instructing_a_plane_to_take_off_should_take_it_off(self):
        # As an air traffic controller
        # So I can get passengers on the way to their destination
        # I want to instruct a plane to take off from an airport and confirm that it is no longer in the airport
        self.airport.instruct_to_land(self.plane)
        self.airport.instruct_to_take_off(self.plane)
        self.assertNotIn(self.plane, self.airport.planes)
        self.assertTrue(self.plane.isflying)
Example #2
0
class TestAirport(unittest.TestCase):

    def setUp(self):
        self.airport = Airport()
        self.plane = Mock()

    def test_airport_initializes_with_empty_planes_array(self):
        self.assertEqual(self.airport.planes, [])

    def test_instruct_to_land_sockets_plane_in_planes(self):
        self.airport.instruct_to_land(self.plane)
        self.assertIn(self.plane, self.airport.planes)

    def test_instruct_to_land_calls_land_on_plane(self):
        self.airport.instruct_to_land(self.plane)
        self.plane.land.assert_called_with()

    def test_instruct_to_take_off_removes_plane_from_planes(self):
        self.airport.instruct_to_land(self.plane)
        self.airport.instruct_to_take_off(self.plane)
        self.assertNotIn(self.plane, self.airport.planes)

    def test_instruct_to_take_off_calls_take_off_on_plane(self):
        self.airport.instruct_to_land(self.plane)
        self.airport.instruct_to_take_off(self.plane)
        self.plane.take_off.assert_called_with()

    def test_instruct_to_take_off_should_fail_if_plane_not_at_airport(self):
        with self.assertRaisesRegexp(Exception, 'Plane is not at this airport'):
            self.airport.instruct_to_take_off(self.plane)
class TestUserStory(unittest.TestCase):

    def setUp(self):
        self.airport = Airport()
        self.plane = Plane()

    def test_instructing_a_plane_to_land_should_land_it(self):
        # As an air traffic controller
        # So I can get passengers to a destination
        # I want to instruct a plane to land at an airport and confirm that it has landed
        self.airport.instruct_to_land(self.plane)
        self.assertIn(self.plane, self.airport.planes)
        self.assertFalse(self.plane.isflying)

    def test_instructing_a_plane_to_take_off_should_take_it_off(self):
        # As an air traffic controller
        # So I can get passengers on the way to their destination
        # I want to instruct a plane to take off from an airport and confirm that it is no longer in the airport
        self.airport.instruct_to_land(self.plane)
        self.airport.instruct_to_take_off(self.plane)
        self.assertNotIn(self.plane, self.airport.planes)
        self.assertTrue(self.plane.isflying)