コード例 #1
0
    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)
コード例 #2
0
    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)
コード例 #3
0
    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)
コード例 #4
0
    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))})
コード例 #5
0
    def test_none_value_also_survives_db_roundtrip(self):
        obj = Interval(value=None)
        obj.save()

        obj.refresh_from_db()
        self.assertIsNone(obj.value)