1212# See the License for the specific language governing permissions and
1313# limitations under the License.
1414
15- from sqlalchemy import select
15+ from sqlalchemy import func , select , text
1616from sqlalchemy .orm import Session
1717from sqlalchemy .testing import eq_ , is_instance_of
1818from google .cloud .spanner_v1 import (
@@ -73,7 +73,24 @@ def test_insert_array(self):
7373 '[{"size":"Great","type":"Stadium"}]' ,
7474 )
7575
76- def _test_insert_json (self , description , expected ):
76+ def test_insert_fn (self ):
77+ add_update_count (
78+ "INSERT INTO venues (id, name, description) "
79+ "VALUES (@a0, @a1, parse_json(@a2, wide_number_mode=>'round'))" ,
80+ 1 ,
81+ )
82+ self ._test_insert_json (
83+ func .parse_json (
84+ '{"type": "Stadium", "size": "Great"}' ,
85+ text ("wide_number_mode=>'round'" ),
86+ ),
87+ '{"type": "Stadium", "size": "Great"}' ,
88+ expected_type_code = TypeCode .STRING ,
89+ )
90+
91+ def _test_insert_json (
92+ self , description , expected , expected_type_code = TypeCode .JSON
93+ ):
7794 from test .mockserver_tests .json_model import Venue
7895
7996 add_update_count (
@@ -100,7 +117,7 @@ def _test_insert_json(self, description, expected):
100117 eq_ (expected , request .params ["a2" ])
101118 eq_ (TypeCode .INT64 , request .param_types ["a0" ].code )
102119 eq_ (TypeCode .STRING , request .param_types ["a1" ].code )
103- eq_ (TypeCode . JSON , request .param_types ["a2" ].code )
120+ eq_ (expected_type_code , request .param_types ["a2" ].code )
104121
105122 def test_select_dict (self ):
106123 self ._test_select_json (
0 commit comments