diff options
| author | Matthew Somerville <matthew-github@dracos.co.uk> | 2015-06-05 21:56:00 +0100 |
|---|---|---|
| committer | Matthew Somerville <matthew-github@dracos.co.uk> | 2015-06-05 22:01:42 +0100 |
| commit | 2926559cce34e48efb4b073721926d737e372dd3 (patch) | |
| tree | 9e82e53286a19c1b4efd10b7cd6834d254071227 /tests/postgres_tests | |
| parent | 0a899157836cc4c3d3980ab6a70b2f37bbb7ba97 (diff) | |
Fixed #24937 -- fix serialization of Date(Time)RangeField.
Use the DjangoJSONEncoder so that datetime and date are encoded
appropriately.
Diffstat (limited to 'tests/postgres_tests')
| -rw-r--r-- | tests/postgres_tests/test_ranges.py | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/tests/postgres_tests/test_ranges.py b/tests/postgres_tests/test_ranges.py index 2461130b35..eca22c17f5 100644 --- a/tests/postgres_tests/test_ranges.py +++ b/tests/postgres_tests/test_ranges.py @@ -293,24 +293,35 @@ class TestSerialization(TestCase): test_data = ( '[{"fields": {"ints": "{\\"upper\\": 10, \\"lower\\": 0, ' '\\"bounds\\": \\"[)\\"}", "floats": "{\\"empty\\": true}", ' - '"bigints": null, "timestamps": null, "dates": null}, ' + '"bigints": null, "timestamps": "{\\"upper\\": \\"2014-02-02T12:12:12\\", ' + '\\"lower\\": \\"2014-01-01T00:00:00\\", \\"bounds\\": \\"[)\\"}", ' + '"dates": "{\\"upper\\": \\"2014-02-02\\", \\"lower\\": \\"2014-01-01\\", \\"bounds\\": \\"[)\\"}" }, ' '"model": "postgres_tests.rangesmodel", "pk": null}]' ) + lower_date = datetime.date(2014, 1, 1) + upper_date = datetime.date(2014, 2, 2) + lower_dt = datetime.datetime(2014, 1, 1, 0, 0, 0) + upper_dt = datetime.datetime(2014, 2, 2, 12, 12, 12) + def test_dumping(self): - instance = RangesModel(ints=NumericRange(0, 10), floats=NumericRange(empty=True)) + instance = RangesModel(ints=NumericRange(0, 10), floats=NumericRange(empty=True), + timestamps=DateTimeTZRange(self.lower_dt, self.upper_dt), + dates=DateRange(self.lower_date, self.upper_date)) data = serializers.serialize('json', [instance]) dumped = json.loads(data) - dumped[0]['fields']['ints'] = json.loads(dumped[0]['fields']['ints']) + for field in ('ints', 'dates', 'timestamps'): + dumped[0]['fields'][field] = json.loads(dumped[0]['fields'][field]) check = json.loads(self.test_data) - check[0]['fields']['ints'] = json.loads(check[0]['fields']['ints']) + for field in ('ints', 'dates', 'timestamps'): + check[0]['fields'][field] = json.loads(check[0]['fields'][field]) self.assertEqual(dumped, check) def test_loading(self): instance = list(serializers.deserialize('json', self.test_data))[0].object self.assertEqual(instance.ints, NumericRange(0, 10)) self.assertEqual(instance.floats, NumericRange(empty=True)) - self.assertEqual(instance.dates, None) + self.assertEqual(instance.bigints, None) class TestValidators(PostgreSQLTestCase): |
