MCPcopy Index your code
hub / github.com/PyMySQL/PyMySQL / test_json

Method test_json

pymysql/tests/test_basic.py:299–329  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

297 c.close()
298
299 def test_json(self):
300 args = self.databases[0].copy()
301 args["charset"] = "utf8mb4"
302 conn = pymysql.connect(**args)
303 # MariaDB only has limited JSON support, stores data as longtext
304 # https://mariadb.com/kb/en/json-data-type/
305 if not self.mysql_server_is(conn, (5, 7, 0)):
306 pytest.skip("JSON type is only supported on MySQL >= 5.7")
307
308 self.safe_create_table(
309 conn,
310 "test_json",
311 """\
312create table test_json (
313 id int not null,
314 json JSON not null,
315 primary key (id)
316);""",
317 )
318 cur = conn.cursor()
319
320 json_str = '{"hello": "こんにちは"}'
321 cur.execute("INSERT INTO test_json (id, `json`) values (42, %s)", (json_str,))
322 cur.execute("SELECT `json` from `test_json` WHERE `id`=42")
323 res = cur.fetchone()[0]
324 self.assertEqual(json.loads(res), json.loads(json_str))
325
326 if self.get_mysql_vendor(conn) == "mysql":
327 cur.execute("SELECT CAST(%s AS JSON) AS x", (json_str,))
328 res = cur.fetchone()[0]
329 self.assertEqual(json.loads(res), json.loads(json_str))
330
331
332class TestBulkInserts(base.PyMySQLTestCase):

Callers

nothing calls this directly

Calls 7

mysql_server_isMethod · 0.80
safe_create_tableMethod · 0.80
cursorMethod · 0.80
executeMethod · 0.80
get_mysql_vendorMethod · 0.80
connectMethod · 0.45
fetchoneMethod · 0.45

Tested by

no test coverage detected