summaryrefslogtreecommitdiff
path: root/tests/postgres_tests/test_array.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/postgres_tests/test_array.py')
-rw-r--r--tests/postgres_tests/test_array.py47
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/postgres_tests/test_array.py b/tests/postgres_tests/test_array.py
index 7b7793f6c1..481d93f830 100644
--- a/tests/postgres_tests/test_array.py
+++ b/tests/postgres_tests/test_array.py
@@ -37,6 +37,53 @@ except ImportError:
pass
+@isolate_apps('postgres_tests')
+class BasicTests(PostgreSQLSimpleTestCase):
+ def test_get_field_display(self):
+ class MyModel(PostgreSQLModel):
+ field = ArrayField(
+ models.CharField(max_length=16),
+ choices=[
+ ['Media', [(['vinyl', 'cd'], 'Audio')]],
+ (('mp3', 'mp4'), 'Digital'),
+ ],
+ )
+
+ tests = (
+ (['vinyl', 'cd'], 'Audio'),
+ (('mp3', 'mp4'), 'Digital'),
+ (('a', 'b'), "('a', 'b')"),
+ (['c', 'd'], "['c', 'd']"),
+ )
+ for value, display in tests:
+ with self.subTest(value=value, display=display):
+ instance = MyModel(field=value)
+ self.assertEqual(instance.get_field_display(), display)
+
+ def test_get_field_display_nested_array(self):
+ class MyModel(PostgreSQLModel):
+ field = ArrayField(
+ ArrayField(models.CharField(max_length=16)),
+ choices=[
+ [
+ 'Media',
+ [([['vinyl', 'cd'], ('x',)], 'Audio')],
+ ],
+ ((['mp3'], ('mp4',)), 'Digital'),
+ ],
+ )
+ tests = (
+ ([['vinyl', 'cd'], ('x',)], 'Audio'),
+ ((['mp3'], ('mp4',)), 'Digital'),
+ ((('a', 'b'), ('c',)), "(('a', 'b'), ('c',))"),
+ ([['a', 'b'], ['c']], "[['a', 'b'], ['c']]"),
+ )
+ for value, display in tests:
+ with self.subTest(value=value, display=display):
+ instance = MyModel(field=value)
+ self.assertEqual(instance.get_field_display(), display)
+
+
class TestSaveLoad(PostgreSQLTestCase):
def test_integer(self):