Exemplo n.º 1
0
 def test_validate(self):
     form = CurvePeriodForm(
         {
             "start_date": dt.date(2019, 9, 3),
             "end_date": dt.date(2021, 9, 3),
             "points": "garbage",
         },
         instance=self.period,
     )
     self.assertFalse(form.is_valid())
     self.assertEqual(
         form.errors["points"][0],
         'Error in line 1: "garbage" is not a valid pair of numbers',
     )
Exemplo n.º 2
0
 def test_save(self):
     form = CurvePeriodForm(
         {
             "start_date": dt.date(2019, 9, 3),
             "end_date": dt.date(2021, 9, 3),
             "points": "1\t2",
         },
         instance=self.period,
     )
     self.assertTrue(form.is_valid())
     form.save()
     point = models.CurvePoint.objects.get(curve_period=self.period)
     period = models.CurvePeriod.objects.get(curve_interpolation=self.ci)
     self.assertEqual(period.start_date, dt.date(2019, 9, 3))
     self.assertEqual(period.end_date, dt.date(2021, 9, 3))
     self.assertAlmostEqual(point.x, 1)
     self.assertAlmostEqual(point.y, 2)
Exemplo n.º 3
0
 def test_init(self):
     form = CurvePeriodForm(instance=self.period)
     content = form.as_p()
     self.assertTrue("2.718\t3.141\n4.0\t5.0" in content)