summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2016-08-04 11:56:31 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2016-08-04 12:38:58 -0400
commitf2fa9d000b44a54b0fd3ae6114eb5d53ef20c3b8 (patch)
treed7cec44ced27243d7f0d4a62831e5f4de9903bdc /test
parentaf6f4ab938f1ef66491cf239c91ffff393275d95 (diff)
downloadsqlalchemy-f2fa9d000b44a54b0fd3ae6114eb5d53ef20c3b8.tar.gz
Build string/int processors for JSONIndexType, JSONPathType
Fixed regression in JSON datatypes where the "literal processor" for a JSON index value, that needs to take effect for example within DDL, would not be invoked for the value. The native String and Integer datatypes are now called upon from within the JSONIndexType and JSONPathType. This is applied to the generic, Postgresql, and MySQL JSON types. Change-Id: Ifa5f2acfeee57a79d01d7fc85d265a37bd27c716 Fixes: #3765
Diffstat (limited to 'test')
-rw-r--r--test/sql/test_types.py71
1 files changed, 71 insertions, 0 deletions
diff --git a/test/sql/test_types.py b/test/sql/test_types.py
index 49a1d8f15..3374a6721 100644
--- a/test/sql/test_types.py
+++ b/test/sql/test_types.py
@@ -1630,6 +1630,77 @@ class JSONTest(fixtures.TestBase):
None
)
+ def _dialect_index_fixture(self, int_processor, str_processor):
+ class MyInt(Integer):
+ def bind_processor(self, dialect):
+ return lambda value: value + 10
+
+ def literal_processor(self, diaect):
+ return lambda value: str(value + 15)
+
+ class MyString(String):
+ def bind_processor(self, dialect):
+ return lambda value: value + "10"
+
+ def literal_processor(self, diaect):
+ return lambda value: value + "15"
+
+ class MyDialect(default.DefaultDialect):
+ colspecs = {}
+ if int_processor:
+ colspecs[Integer] = MyInt
+ if str_processor:
+ colspecs[String] = MyString
+
+ return MyDialect()
+
+ def test_index_bind_proc_int(self):
+ expr = self.test_table.c.test_column[5]
+
+ int_dialect = self._dialect_index_fixture(True, True)
+ non_int_dialect = self._dialect_index_fixture(False, True)
+
+ bindproc = expr.right.type._cached_bind_processor(int_dialect)
+ eq_(bindproc(expr.right.value), 15)
+
+ bindproc = expr.right.type._cached_bind_processor(non_int_dialect)
+ eq_(bindproc(expr.right.value), 5)
+
+ def test_index_literal_proc_int(self):
+ expr = self.test_table.c.test_column[5]
+
+ int_dialect = self._dialect_index_fixture(True, True)
+ non_int_dialect = self._dialect_index_fixture(False, True)
+
+ bindproc = expr.right.type._cached_literal_processor(int_dialect)
+ eq_(bindproc(expr.right.value), "20")
+
+ bindproc = expr.right.type._cached_literal_processor(non_int_dialect)
+ eq_(bindproc(expr.right.value), "5")
+
+ def test_index_bind_proc_str(self):
+ expr = self.test_table.c.test_column['five']
+
+ str_dialect = self._dialect_index_fixture(True, True)
+ non_str_dialect = self._dialect_index_fixture(False, False)
+
+ bindproc = expr.right.type._cached_bind_processor(str_dialect)
+ eq_(bindproc(expr.right.value), 'five10')
+
+ bindproc = expr.right.type._cached_bind_processor(non_str_dialect)
+ eq_(bindproc(expr.right.value), 'five')
+
+ def test_index_literal_proc_str(self):
+ expr = self.test_table.c.test_column['five']
+
+ str_dialect = self._dialect_index_fixture(True, True)
+ non_str_dialect = self._dialect_index_fixture(False, False)
+
+ bindproc = expr.right.type._cached_literal_processor(str_dialect)
+ eq_(bindproc(expr.right.value), "five15")
+
+ bindproc = expr.right.type._cached_literal_processor(non_str_dialect)
+ eq_(bindproc(expr.right.value), "'five'")
class ArrayTest(fixtures.TestBase):