1
1
import psycopg
2
- import psycopg .extras
3
- import psycopg .pool
4
2
import psycopg .sql
3
+ import psycopg_pool
5
4
6
5
import pytest
7
6
import testing .postgresql
@@ -49,32 +48,6 @@ def test_execute_dsn_kwargs():
49
48
assert sql ['database_version' ]
50
49
51
50
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
-
78
51
def test_execute_dsn_string ():
79
52
q = 'SELECT 1'
80
53
with testing .postgresql .Postgresql () as postgresql :
@@ -102,14 +75,16 @@ def test_execute_in_pool():
102
75
with testing .postgresql .Postgresql () as postgresql :
103
76
url = postgresql .url ()
104
77
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 )
113
88
114
89
subsegment = xray_recorder .current_segment ().subsegments [0 ]
115
90
assert subsegment .name == 'execute'
@@ -147,20 +122,6 @@ def test_execute_bad_query():
147
122
exception = subsegment .cause ['exceptions' ][0 ]
148
123
assert exception .type == 'UndefinedColumn'
149
124
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
-
164
125
def test_query_as_string ():
165
126
with testing .postgresql .Postgresql () as postgresql :
166
127
url = postgresql .url ()
@@ -173,17 +134,3 @@ def test_query_as_string():
173
134
test_sql = psycopg .sql .Identifier ('test' )
174
135
assert test_sql .as_string (conn )
175
136
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