MCPcopy
hub / github.com/psycopg/psycopg / test_invalid_name

Method test_invalid_name

tests/test_sql.py:405–437  ·  view source on GitHub ↗
(self, conn, name)

Source from the content-addressed store, hash-verified

403 @pytest.mark.crdb_skip("composite") # create type, actually
404 @pytest.mark.parametrize("name", ["a-b", f"{eur}", "order", "foo bar", "FooBar"])
405 def test_invalid_name(self, conn, name):
406 if conn.info.parameter_status("is_superuser") != "on":
407 pytest.skip("not a superuser")
408 conn.execute(f"""
409 set client_encoding to utf8;
410 create type "{name}";
411 create function invin(cstring) returns "{name}"
412 language internal immutable strict as 'textin';
413 create function invout("{name}") returns cstring
414 language internal immutable strict as 'textout';
415 create type "{name}" (input=invin, output=invout, like=text);
416 """)
417 info = TypeInfo.fetch(conn, f'"{name}"')
418
419 class InvDumper(StrDumper):
420 oid = info.oid
421
422 def dump(self, obj):
423 rv = super().dump(obj)
424 return b"%s-inv" % rv
425
426 info.register(conn)
427 conn.adapters.register_dumper(str, InvDumper)
428
429 assert sql.Literal("hello").as_string(conn) == f"'hello-inv'::\"{name}\""
430 cur = conn.execute(sql.SQL("select {}").format("hello"))
431 assert cur.fetchone()[0] == "hello-inv"
432
433 assert (
434 sql.Literal(["hello"]).as_string(conn) == f"'{{hello-inv}}'::\"{name}\"[]"
435 )
436 cur = conn.execute(sql.SQL("select {}").format(["hello"]))
437 assert cur.fetchone()[0] == ["hello-inv"]
438
439
440class TestSQL:

Callers

nothing calls this directly

Calls 8

fetchMethod · 0.80
registerMethod · 0.80
register_dumperMethod · 0.80
formatMethod · 0.80
parameter_statusMethod · 0.45
executeMethod · 0.45
as_stringMethod · 0.45
fetchoneMethod · 0.45

Tested by

no test coverage detected