11import psycopg
2- import psycopg .extras
3- import psycopg .pool
42import psycopg .sql
3+ import psycopg_pool
54
65import pytest
76import testing .postgresql
@@ -49,32 +48,6 @@ def test_execute_dsn_kwargs():
4948 assert sql ['database_version' ]
5049
5150
52- def test_execute_dsn_kwargs_alt_dbname ():
53- """
54- Psycopg supports database to be passed as `database` or `dbname`
55- """
56- q = 'SELECT 1'
57-
58- with testing .postgresql .Postgresql () as postgresql :
59- url = postgresql .url ()
60- dsn = postgresql .dsn ()
61- conn = psycopg .connect (database = dsn ['database' ],
62- user = dsn ['user' ],
63- password = '' ,
64- host = dsn ['host' ],
65- port = dsn ['port' ])
66- cur = conn .cursor ()
67- cur .execute (q )
68-
69- subsegment = xray_recorder .current_segment ().subsegments [0 ]
70- assert subsegment .name == 'execute'
71- sql = subsegment .sql
72- assert sql ['database_type' ] == 'PostgreSQL'
73- assert sql ['user' ] == dsn ['user' ]
74- assert sql ['url' ] == url
75- assert sql ['database_version' ]
76-
77-
7851def test_execute_dsn_string ():
7952 q = 'SELECT 1'
8053 with testing .postgresql .Postgresql () as postgresql :
@@ -102,14 +75,16 @@ def test_execute_in_pool():
10275 with testing .postgresql .Postgresql () as postgresql :
10376 url = postgresql .url ()
10477 dsn = postgresql .dsn ()
105- pool = psycopg .pool .SimpleConnectionPool (1 , 1 ,
106- dbname = dsn ['database' ],
107- user = dsn ['user' ],
108- password = '' ,
109- host = dsn ['host' ],
110- port = dsn ['port' ])
111- cur = pool .getconn (key = dsn ['user' ]).cursor ()
112- cur .execute (q )
78+ pool = psycopg_pool .ConnectionPool ('dbname=' + dsn ['database' ] +
79+ ' password=mypassword' +
80+ ' host=' + dsn ['host' ] +
81+ ' port=' + str (dsn ['port' ]) +
82+ ' user=' + dsn ['user' ],
83+ min_size = 1 ,
84+ max_size = 1 )
85+ with pool .connection () as conn :
86+ cur = conn .cursor ()
87+ cur .execute (q )
11388
11489 subsegment = xray_recorder .current_segment ().subsegments [0 ]
11590 assert subsegment .name == 'execute'
@@ -147,20 +122,6 @@ def test_execute_bad_query():
147122 exception = subsegment .cause ['exceptions' ][0 ]
148123 assert exception .type == 'UndefinedColumn'
149124
150-
151- def test_register_extensions ():
152- with testing .postgresql .Postgresql () as postgresql :
153- url = postgresql .url ()
154- dsn = postgresql .dsn ()
155- conn = psycopg .connect ('dbname=' + dsn ['database' ] +
156- ' password=mypassword' +
157- ' host=' + dsn ['host' ] +
158- ' port=' + str (dsn ['port' ]) +
159- ' user=' + dsn ['user' ])
160- assert psycopg .extras .register_uuid (None , conn )
161- assert psycopg .extras .register_uuid (None , conn .cursor ())
162-
163-
164125def test_query_as_string ():
165126 with testing .postgresql .Postgresql () as postgresql :
166127 url = postgresql .url ()
@@ -173,17 +134,3 @@ def test_query_as_string():
173134 test_sql = psycopg .sql .Identifier ('test' )
174135 assert test_sql .as_string (conn )
175136 assert test_sql .as_string (conn .cursor ())
176-
177-
178- def test_register_default_jsonb ():
179- with testing .postgresql .Postgresql () as postgresql :
180- url = postgresql .url ()
181- dsn = postgresql .dsn ()
182- conn = psycopg .connect ('dbname=' + dsn ['database' ] +
183- ' password=mypassword' +
184- ' host=' + dsn ['host' ] +
185- ' port=' + str (dsn ['port' ]) +
186- ' user=' + dsn ['user' ])
187-
188- assert psycopg .extras .register_default_jsonb (conn_or_curs = conn , loads = lambda x : x )
189- assert psycopg .extras .register_default_jsonb (conn_or_curs = conn .cursor (), loads = lambda x : x )
0 commit comments