diff options
| author | Greg Chapple <gregchapple1@gmail.com> | 2016-01-25 12:30:40 +0000 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2016-01-29 09:51:23 -0500 |
| commit | 8dea9f089dcb8aea2c417c91344c4e680431e972 (patch) | |
| tree | f147304a6fd6bd762edb4d7646c53790c5214387 /tests/postgres_tests/test_hstore.py | |
| parent | 93897a6a75754c1c17d8a60dee188c86f13de232 (diff) | |
Fixed #26120 -- Made HStoreField cast keys and values to strings.
HStoreField now converts all keys and values to string before they're
saved to the database.
Diffstat (limited to 'tests/postgres_tests/test_hstore.py')
| -rw-r--r-- | tests/postgres_tests/test_hstore.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/tests/postgres_tests/test_hstore.py b/tests/postgres_tests/test_hstore.py index 80e46e5021..13c08386e2 100644 --- a/tests/postgres_tests/test_hstore.py +++ b/tests/postgres_tests/test_hstore.py @@ -1,3 +1,6 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + import json from django.core import exceptions, serializers @@ -37,6 +40,20 @@ class SimpleTests(PostgreSQLTestCase): reloaded = HStoreModel.objects.get() self.assertEqual(reloaded.field, value) + def test_key_val_cast_to_string(self): + value = {'a': 1, 'b': 'B', 2: 'c', 'ï': 'ê', b'x': b'test'} + expected_value = {'a': '1', 'b': 'B', '2': 'c', 'ï': 'ê', 'x': 'test'} + + instance = HStoreModel.objects.create(field=value) + instance = HStoreModel.objects.get() + self.assertDictEqual(instance.field, expected_value) + + instance = HStoreModel.objects.get(field__a=1) + self.assertDictEqual(instance.field, expected_value) + + instance = HStoreModel.objects.get(field__has_keys=[2, 'a', 'ï']) + self.assertDictEqual(instance.field, expected_value) + class TestQuerying(PostgreSQLTestCase): |
