def create_pumping_station(self):
        """Create a pumping station and save it to the database."""
        # Before we can create and save a PumpingStation, we have to set the
        # required fields.

        # If a required field refers to another model, we do not save that model
        # to the database, otherwise we would also have to create the required
        # fields of that model.
        open_water = OpenWater()
        open_water.pk = 1
        # If we do not set the pk field of the model or set it after we have
        # assigned the model to the PumpingStation, we get an IntegrityError.
        label = Label()
        label.pk = self.label_pk
        self.label_pk += 1

        pumping_station = PumpingStation()
        pumping_station.open_water = open_water
        pumping_station.label = label
        pumping_station.into = True
        pumping_station.computed_level_control = True
        pumping_station.percentage = 100
        pumping_station.save()

        return pumping_station
 def test_a(self):
     """Test the correct legend name is returned when the key is a string."""
     label = Label()
     label.name = "neerslag"
     label.program_name = "precipitation"
     label.save()
     legend_info = LegendInfo()
     legend_info.retrieve_labels()
     (legend_name, label) = legend_info.retrieve("precipitation")
     self.assertEqual("neerslag", legend_name)
     label.delete()
 def test_b(self):
     """Test the correct Label is returned when the key is a string."""
     label = Label()
     label.name = "neerslag"
     label.program_name = "precipitation"
     label.save()
     stored_label = Label.objects.get(name__iexact="neerslag")
     legend_info = LegendInfo()
     legend_info.retrieve_labels()
     (legend_name, label) = legend_info.retrieve("precipitation")
     self.assertEqual(stored_label.pk, label.pk)
     label.delete()
    def test_c(self):
        """Test the correct legend name is returned when the key is an intake.

        An intake is implemented by a PumpingStation.

        """
        label = Label()
        label.name = "inlaat 1"
        label.program_name = "inlet1"
        label.save()
        intake = PumpingStation()
        intake.name = "dijklek"
        intake.label = label
        # Note that we do not save the intake to the database. To save a
        # PumpingStation, we need to create a whole tree of objects. But that
        # is not necessary as long as a LegendInfo does not query that part of
        # the database.
        legend_info = LegendInfo()
        legend_info.retrieve_labels()
        (legend_name, label) = legend_info.retrieve(intake)
        self.assertEqual("dijklek", legend_name)
        label.delete()