|
| 1 | +import ast |
1 | 2 | import contextlib
|
2 | 3 | import logging
|
3 | 4 |
|
|
9 | 10 | from ..fields import (BatchSQLAlchemyConnectionField,
|
10 | 11 | default_connection_field_factory)
|
11 | 12 | from ..types import ORMField, SQLAlchemyObjectType
|
12 |
| -from .models import Article, HairKind, Pet, Reporter |
13 | 13 | from ..utils import is_sqlalchemy_version_less_than
|
14 |
| -from .utils import to_std_dicts |
| 14 | +from .models import Article, HairKind, Pet, Reporter |
| 15 | +from .utils import remove_cache_miss_stat, to_std_dicts |
15 | 16 |
|
16 | 17 |
|
17 | 18 | class MockLoggingHandler(logging.Handler):
|
@@ -127,26 +128,12 @@ async def test_many_to_one(session_factory):
|
127 | 128 | assert len(sql_statements) == 1
|
128 | 129 | return
|
129 | 130 |
|
130 |
| - assert messages == [ |
131 |
| - 'BEGIN (implicit)', |
132 |
| - |
133 |
| - 'SELECT articles.id AS articles_id, ' |
134 |
| - 'articles.headline AS articles_headline, ' |
135 |
| - 'articles.pub_date AS articles_pub_date, ' |
136 |
| - 'articles.reporter_id AS articles_reporter_id \n' |
137 |
| - 'FROM articles', |
138 |
| - '()', |
139 |
| - |
140 |
| - 'SELECT reporters.id AS reporters_id, ' |
141 |
| - '(SELECT CAST(count(reporters.id) AS INTEGER) AS anon_2 \nFROM reporters) AS anon_1, ' |
142 |
| - 'reporters.first_name AS reporters_first_name, ' |
143 |
| - 'reporters.last_name AS reporters_last_name, ' |
144 |
| - 'reporters.email AS reporters_email, ' |
145 |
| - 'reporters.favorite_pet_kind AS reporters_favorite_pet_kind \n' |
146 |
| - 'FROM reporters \n' |
147 |
| - 'WHERE reporters.id IN (?, ?)', |
148 |
| - '(1, 2)', |
149 |
| - ] |
| 131 | + if not is_sqlalchemy_version_less_than('1.4'): |
| 132 | + messages[2] = remove_cache_miss_stat(messages[2]) |
| 133 | + messages[4] = remove_cache_miss_stat(messages[4]) |
| 134 | + |
| 135 | + assert ast.literal_eval(messages[2]) == () |
| 136 | + assert sorted(ast.literal_eval(messages[4])) == [1, 2] |
150 | 137 |
|
151 | 138 | assert not result.errors
|
152 | 139 | result = to_std_dicts(result.data)
|
@@ -219,26 +206,12 @@ async def test_one_to_one(session_factory):
|
219 | 206 | assert len(sql_statements) == 1
|
220 | 207 | return
|
221 | 208 |
|
222 |
| - assert messages == [ |
223 |
| - 'BEGIN (implicit)', |
224 |
| - |
225 |
| - 'SELECT (SELECT CAST(count(reporters.id) AS INTEGER) AS anon_2 \nFROM reporters) AS anon_1, ' |
226 |
| - 'reporters.id AS reporters_id, ' |
227 |
| - 'reporters.first_name AS reporters_first_name, ' |
228 |
| - 'reporters.last_name AS reporters_last_name, ' |
229 |
| - 'reporters.email AS reporters_email, ' |
230 |
| - 'reporters.favorite_pet_kind AS reporters_favorite_pet_kind \n' |
231 |
| - 'FROM reporters', |
232 |
| - '()', |
233 |
| - |
234 |
| - 'SELECT articles.reporter_id AS articles_reporter_id, ' |
235 |
| - 'articles.id AS articles_id, ' |
236 |
| - 'articles.headline AS articles_headline, ' |
237 |
| - 'articles.pub_date AS articles_pub_date \n' |
238 |
| - 'FROM articles \n' |
239 |
| - 'WHERE articles.reporter_id IN (?, ?)', |
240 |
| - '(1, 2)' |
241 |
| - ] |
| 209 | + if not is_sqlalchemy_version_less_than('1.4'): |
| 210 | + messages[2] = remove_cache_miss_stat(messages[2]) |
| 211 | + messages[4] = remove_cache_miss_stat(messages[4]) |
| 212 | + |
| 213 | + assert ast.literal_eval(messages[2]) == () |
| 214 | + assert sorted(ast.literal_eval(messages[4])) == [1, 2] |
242 | 215 |
|
243 | 216 | assert not result.errors
|
244 | 217 | result = to_std_dicts(result.data)
|
@@ -323,26 +296,12 @@ async def test_one_to_many(session_factory):
|
323 | 296 | assert len(sql_statements) == 1
|
324 | 297 | return
|
325 | 298 |
|
326 |
| - assert messages == [ |
327 |
| - 'BEGIN (implicit)', |
328 |
| - |
329 |
| - 'SELECT (SELECT CAST(count(reporters.id) AS INTEGER) AS anon_2 \nFROM reporters) AS anon_1, ' |
330 |
| - 'reporters.id AS reporters_id, ' |
331 |
| - 'reporters.first_name AS reporters_first_name, ' |
332 |
| - 'reporters.last_name AS reporters_last_name, ' |
333 |
| - 'reporters.email AS reporters_email, ' |
334 |
| - 'reporters.favorite_pet_kind AS reporters_favorite_pet_kind \n' |
335 |
| - 'FROM reporters', |
336 |
| - '()', |
337 |
| - |
338 |
| - 'SELECT articles.reporter_id AS articles_reporter_id, ' |
339 |
| - 'articles.id AS articles_id, ' |
340 |
| - 'articles.headline AS articles_headline, ' |
341 |
| - 'articles.pub_date AS articles_pub_date \n' |
342 |
| - 'FROM articles \n' |
343 |
| - 'WHERE articles.reporter_id IN (?, ?)', |
344 |
| - '(1, 2)' |
345 |
| - ] |
| 299 | + if not is_sqlalchemy_version_less_than('1.4'): |
| 300 | + messages[2] = remove_cache_miss_stat(messages[2]) |
| 301 | + messages[4] = remove_cache_miss_stat(messages[4]) |
| 302 | + |
| 303 | + assert ast.literal_eval(messages[2]) == () |
| 304 | + assert sorted(ast.literal_eval(messages[4])) == [1, 2] |
346 | 305 |
|
347 | 306 | assert not result.errors
|
348 | 307 | result = to_std_dicts(result.data)
|
@@ -451,31 +410,12 @@ async def test_many_to_many(session_factory):
|
451 | 410 | assert len(sql_statements) == 1
|
452 | 411 | return
|
453 | 412 |
|
454 |
| - assert messages == [ |
455 |
| - 'BEGIN (implicit)', |
456 |
| - |
457 |
| - 'SELECT (SELECT CAST(count(reporters.id) AS INTEGER) AS anon_2 \nFROM reporters) AS anon_1, ' |
458 |
| - 'reporters.id AS reporters_id, ' |
459 |
| - 'reporters.first_name AS reporters_first_name, ' |
460 |
| - 'reporters.last_name AS reporters_last_name, ' |
461 |
| - 'reporters.email AS reporters_email, ' |
462 |
| - 'reporters.favorite_pet_kind AS reporters_favorite_pet_kind \n' |
463 |
| - 'FROM reporters', |
464 |
| - '()', |
465 |
| - |
466 |
| - 'SELECT reporters_1.id AS reporters_1_id, ' |
467 |
| - 'pets.id AS pets_id, ' |
468 |
| - 'pets.name AS pets_name, ' |
469 |
| - 'pets.pet_kind AS pets_pet_kind, ' |
470 |
| - 'pets.hair_kind AS pets_hair_kind, ' |
471 |
| - 'pets.reporter_id AS pets_reporter_id \n' |
472 |
| - 'FROM reporters AS reporters_1 ' |
473 |
| - 'JOIN association AS association_1 ON reporters_1.id = association_1.reporter_id ' |
474 |
| - 'JOIN pets ON pets.id = association_1.pet_id \n' |
475 |
| - 'WHERE reporters_1.id IN (?, ?) ' |
476 |
| - 'ORDER BY pets.id', |
477 |
| - '(1, 2)' |
478 |
| - ] |
| 413 | + if not is_sqlalchemy_version_less_than('1.4'): |
| 414 | + messages[2] = remove_cache_miss_stat(messages[2]) |
| 415 | + messages[4] = remove_cache_miss_stat(messages[4]) |
| 416 | + |
| 417 | + assert ast.literal_eval(messages[2]) == () |
| 418 | + assert sorted(ast.literal_eval(messages[4])) == [1, 2] |
479 | 419 |
|
480 | 420 | assert not result.errors
|
481 | 421 | result = to_std_dicts(result.data)
|
|
0 commit comments