def test_submit(self): data = FactoryFloor.TransectFactory.get_valid_data() self.assert_success_url(self.test_url, data=data, user=self.user) # let's test out the save method data = FactoryFloor.TransectFactory.get_valid_data() data['start_latitude_d'] = 48 data['start_latitude_mm'] = 12.34 data['start_longitude_d'] = -64 data['start_longitude_mm'] = 56.78 data['end_latitude_d'] = 49 data['end_latitude_mm'] = 13.34 data['end_longitude_d'] = -65 data['end_longitude_mm'] = 57.78 self.assert_success_url(self.test_url, data=data, user=self.user) obj = get_object_or_404(models.Transect, pk=self.instance.pk) self.assertEqual( dm2decdeg(data['start_latitude_d'], data['start_latitude_mm']), obj.start_latitude) self.assertEqual( dm2decdeg(data['start_longitude_d'], data['start_longitude_mm']), obj.start_longitude) self.assertEqual( dm2decdeg(data['end_latitude_d'], data['end_latitude_mm']), obj.end_latitude) self.assertEqual( dm2decdeg(data['end_longitude_d'], data['end_longitude_mm']), obj.end_longitude)
def save(self, *args, **kwargs): self.start_latitude = dm2decdeg(self.start_latitude_d, self.start_latitude_mm) self.start_longitude = dm2decdeg(self.start_longitude_d, self.start_longitude_mm) self.end_latitude = dm2decdeg(self.end_latitude_d, self.end_latitude_mm) self.end_longitude = dm2decdeg(self.end_longitude_d, self.end_longitude_mm) super().save(*args, **kwargs)