def test_empty_value_survives_db_roundtrip(self): obj = Interval(value=relativedelta()) obj.save() obj.refresh_from_db() self.assertEqual(relativedelta(), obj.value) self.assertStrictEqual(relativedelta(), obj.value)
def test_basic_value_survives_db_roundtrip(self): input_value = relativedelta(years=2, months=3, days=4, hours=5, minutes=52, seconds=30, microseconds=5) obj = Interval(value=input_value) obj.save() obj.refresh_from_db() self.assertStrictEqual(input_value, obj.value)
def test_weeks_value_survives_db_roundtrip_as_days(self): input_value = relativedelta(weeks=2, days=1) obj = Interval(value=input_value) obj.save() obj.refresh_from_db() self.assertStrictEqual(15, obj.value.days) self.assertStrictEqual(2, obj.value.weeks)
def test_filterning_non_postgres(self): obj1 = Interval(value='P1Y3M1W4.5DT5H70.5M80.10001S') obj1.save() obj2 = Interval(value='P12D') obj2.save() q = Interval.objects.filter(value__gt='P99D') self.assertEqual(1, q.count()) q = Interval.objects.filter(value__gt='P9D') self.assertEqual(2, q.count())
def test_filtering_works(self): obj1 = Interval(value='P1Y3M1W4.5DT5H70.5M80.10001S') obj1.save() obj2 = Interval(value='P12D') obj2.save() q = Interval.objects.filter(value__gt='P1Y') self.assertEqual(1, q.count()) q = Interval.objects.filter(value__lt='P2Y') self.assertEqual(2, q.count())
def test_each_separate_value_survives_db_roundtrip(self): values = { 'years': 501, 'months': 10, 'days': 2, 'hours': 1, 'minutes': 52, 'seconds': 12, } for k in values: input_value = relativedelta(**{k: values[k]}) obj = Interval(value=input_value) obj.save() obj.refresh_from_db() # Put the object in a dict to get descriptive output on failure self.assertEqual({k: input_value}, {k: obj.value}) self.assertEqual({k: int}, {k: type(getattr(obj.value, k))})
def test_none_value_also_survives_db_roundtrip(self): obj = Interval(value=None) obj.save() obj.refresh_from_db() self.assertIsNone(obj.value)