Skip to content

Commit 08ad1f8

Browse files
author
Jesse De Loore
committed
fix tests
1 parent d824333 commit 08ad1f8

File tree

3 files changed

+61
-17
lines changed

3 files changed

+61
-17
lines changed

asyncpg/connect_utils.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -597,15 +597,19 @@ def _parse_connect_dsn_and_args(*, dsn, host, port, user,
597597

598598
if target_session_attrs is None:
599599

600-
target_session_attrs = os.getenv("PGTARGETSESSIONATTRS", SessionAttribute.any)
600+
target_session_attrs = os.getenv(
601+
"PGTARGETSESSIONATTRS", SessionAttribute.any
602+
)
601603
try:
602604

603605
target_session_attrs = SessionAttribute(target_session_attrs)
604606
except ValueError as exc:
605607
raise exceptions.InterfaceError(
606608
"target_session_attrs is expected to be one of "
607609
"{!r}"
608-
", got {!r}".format(SessionAttribute.__members__.values, target_session_attrs)
610+
", got {!r}".format(
611+
SessionAttribute.__members__.values, target_session_attrs
612+
)
609613
) from exc
610614

611615
params = _ConnectionParameters(

asyncpg/connection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
from . import serverversion
3030
from . import transaction
3131
from . import utils
32-
from .connect_utils import SessionAttribute
3332

3433

3534
class ConnectionMeta(type):
@@ -2017,7 +2016,8 @@ async def connect(dsn=None, *,
20172016
none of the listed hosts is a standby server,
20182017
return any of them.
20192018
2020-
If not specified will try to use PGTARGETSESSIONATTRS from the environment.
2019+
If not specified will try to use PGTARGETSESSIONATTRS
2020+
from the environment.
20212021
Defaults to "any" if no value is set.
20222022
20232023
:return: A :class:`~asyncpg.connection.Connection` instance.

tests/test_connect.py

Lines changed: 53 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,8 @@ class TestConnectParams(tb.TestCase):
384384
'password': 'passw',
385385
'database': 'testdb',
386386
'ssl': True,
387-
'sslmode': SSLMode.prefer})
387+
'sslmode': SSLMode.prefer,
388+
'target_session_attrs': 'any'})
388389
},
389390

390391
{
@@ -406,7 +407,8 @@ class TestConnectParams(tb.TestCase):
406407
'result': ([('host2', 456)], {
407408
'user': 'user2',
408409
'password': 'passw2',
409-
'database': 'db2'})
410+
'database': 'db2',
411+
'target_session_attrs': 'any'})
410412
},
411413

412414
{
@@ -434,7 +436,8 @@ class TestConnectParams(tb.TestCase):
434436
'password': 'passw2',
435437
'database': 'db2',
436438
'sslmode': SSLMode.disable,
437-
'ssl': False})
439+
'ssl': False,
440+
'target_session_attrs': 'any'})
438441
},
439442

440443
{
@@ -455,7 +458,8 @@ class TestConnectParams(tb.TestCase):
455458
'password': '123123',
456459
'database': 'abcdef',
457460
'ssl': True,
458-
'sslmode': SSLMode.allow})
461+
'sslmode': SSLMode.allow,
462+
'target_session_attrs': 'any'})
459463
},
460464

461465
{
@@ -483,7 +487,8 @@ class TestConnectParams(tb.TestCase):
483487
'password': 'passw2',
484488
'database': 'db2',
485489
'sslmode': SSLMode.disable,
486-
'ssl': False})
490+
'ssl': False,
491+
'target_session_attrs': 'any'})
487492
},
488493

489494
{
@@ -504,7 +509,8 @@ class TestConnectParams(tb.TestCase):
504509
'password': '123123',
505510
'database': 'abcdef',
506511
'ssl': True,
507-
'sslmode': SSLMode.prefer})
512+
'sslmode': SSLMode.prefer,
513+
'target_session_attrs': 'any'})
508514
},
509515

510516
{
@@ -513,7 +519,8 @@ class TestConnectParams(tb.TestCase):
513519
'result': ([('localhost', 5555)], {
514520
'user': 'user3',
515521
'password': '123123',
516-
'database': 'abcdef'})
522+
'database': 'abcdef',
523+
'target_session_attrs': 'any'})
517524
},
518525

519526
{
@@ -522,6 +529,7 @@ class TestConnectParams(tb.TestCase):
522529
'result': ([('host1', 5432), ('host2', 5432)], {
523530
'database': 'db',
524531
'user': 'user',
532+
'target_session_attrs': 'any',
525533
})
526534
},
527535

@@ -531,6 +539,7 @@ class TestConnectParams(tb.TestCase):
531539
'result': ([('host1', 1111), ('host2', 2222)], {
532540
'database': 'db',
533541
'user': 'user',
542+
'target_session_attrs': 'any',
534543
})
535544
},
536545

@@ -540,6 +549,7 @@ class TestConnectParams(tb.TestCase):
540549
'result': ([('2001:db8::1234%eth0', 5432), ('::1', 5432)], {
541550
'database': 'db',
542551
'user': 'user',
552+
'target_session_attrs': 'any',
543553
})
544554
},
545555

@@ -549,6 +559,7 @@ class TestConnectParams(tb.TestCase):
549559
'result': ([('2001:db8::1234', 1111), ('::1', 2222)], {
550560
'database': 'db',
551561
'user': 'user',
562+
'target_session_attrs': 'any',
552563
})
553564
},
554565

@@ -558,6 +569,7 @@ class TestConnectParams(tb.TestCase):
558569
'result': ([('2001:db8::1234', 5432), ('::1', 5432)], {
559570
'database': 'db',
560571
'user': 'user',
572+
'target_session_attrs': 'any',
561573
})
562574
},
563575

@@ -572,6 +584,7 @@ class TestConnectParams(tb.TestCase):
572584
'result': ([('host1', 1111), ('host2', 2222)], {
573585
'database': 'db',
574586
'user': 'foo',
587+
'target_session_attrs': 'any',
575588
})
576589
},
577590

@@ -584,6 +597,7 @@ class TestConnectParams(tb.TestCase):
584597
'result': ([('host1', 1111), ('host2', 2222)], {
585598
'database': 'db',
586599
'user': 'foo',
600+
'target_session_attrs': 'any',
587601
})
588602
},
589603

@@ -597,6 +611,7 @@ class TestConnectParams(tb.TestCase):
597611
'result': ([('host1', 5432), ('host2', 5432)], {
598612
'database': 'db',
599613
'user': 'foo',
614+
'target_session_attrs': 'any',
600615
})
601616
},
602617

@@ -616,7 +631,8 @@ class TestConnectParams(tb.TestCase):
616631
'password': 'ask',
617632
'database': 'db',
618633
'ssl': True,
619-
'sslmode': SSLMode.require})
634+
'sslmode': SSLMode.require,
635+
'target_session_attrs': 'any'})
620636
},
621637

622638
{
@@ -637,15 +653,17 @@ class TestConnectParams(tb.TestCase):
637653
'password': 'ask',
638654
'database': 'db',
639655
'sslmode': SSLMode.verify_full,
640-
'ssl': True})
656+
'ssl': True,
657+
'target_session_attrs': 'any'})
641658
},
642659

643660
{
644661
'name': 'dsn_only_unix',
645662
'dsn': 'postgresql:///dbname?host=/unix_sock/test&user=spam',
646663
'result': ([os.path.join('/unix_sock/test', '.s.PGSQL.5432')], {
647664
'user': 'spam',
648-
'database': 'dbname'})
665+
'database': 'dbname',
666+
'target_session_attrs': 'any'})
649667
},
650668

651669
{
@@ -657,6 +675,7 @@ class TestConnectParams(tb.TestCase):
657675
'user': 'us@r',
658676
'password': 'p@ss',
659677
'database': 'db',
678+
'target_session_attrs': 'any',
660679
}
661680
)
662681
},
@@ -670,6 +689,7 @@ class TestConnectParams(tb.TestCase):
670689
'user': 'user',
671690
'password': 'p',
672691
'database': 'db',
692+
'target_session_attrs': 'any',
673693
}
674694
)
675695
},
@@ -682,6 +702,7 @@ class TestConnectParams(tb.TestCase):
682702
{
683703
'user': 'us@r',
684704
'database': 'db',
705+
'target_session_attrs': 'any',
685706
}
686707
)
687708
},
@@ -709,7 +730,8 @@ class TestConnectParams(tb.TestCase):
709730
'user': 'user',
710731
'database': 'user',
711732
'sslmode': SSLMode.disable,
712-
'ssl': None
733+
'ssl': None,
734+
'target_session_attrs': 'any',
713735
}
714736
)
715737
},
@@ -723,7 +745,8 @@ class TestConnectParams(tb.TestCase):
723745
'.s.PGSQL.5432'
724746
)], {
725747
'user': 'spam',
726-
'database': 'db'
748+
'database': 'db',
749+
'target_session_attrs': 'any',
727750
}
728751
)
729752
},
@@ -744,6 +767,7 @@ class TestConnectParams(tb.TestCase):
744767
'database': 'db',
745768
'ssl': True,
746769
'sslmode': SSLMode.prefer,
770+
'target_session_attrs': 'any',
747771
}
748772
)
749773
},
@@ -874,7 +898,9 @@ def test_test_connect_params_run_testcase(self):
874898
'host': 'abc',
875899
'result': (
876900
[('abc', 5432)],
877-
{'user': '__test__', 'database': '__test__'}
901+
{'user': '__test__',
902+
'database': '__test__',
903+
'target_session_attrs': 'any'}
878904
)
879905
})
880906

@@ -912,6 +938,7 @@ def test_connect_pgpass_regular(self):
912938
'password': 'password from pgpass for user@abc',
913939
'user': 'user',
914940
'database': 'db',
941+
'target_session_attrs': 'any',
915942
}
916943
)
917944
})
@@ -928,6 +955,7 @@ def test_connect_pgpass_regular(self):
928955
'password': 'password from pgpass for user@abc',
929956
'user': 'user',
930957
'database': 'db',
958+
'target_session_attrs': 'any',
931959
}
932960
)
933961
})
@@ -942,6 +970,7 @@ def test_connect_pgpass_regular(self):
942970
'password': 'password from pgpass for user@abc',
943971
'user': 'user',
944972
'database': 'db',
973+
'target_session_attrs': 'any',
945974
}
946975
)
947976
})
@@ -957,6 +986,7 @@ def test_connect_pgpass_regular(self):
957986
'password': 'password from pgpass for localhost',
958987
'user': 'user',
959988
'database': 'db',
989+
'target_session_attrs': 'any',
960990
}
961991
)
962992
})
@@ -974,6 +1004,7 @@ def test_connect_pgpass_regular(self):
9741004
'password': 'password from pgpass for localhost',
9751005
'user': 'user',
9761006
'database': 'db',
1007+
'target_session_attrs': 'any',
9771008
}
9781009
)
9791010
})
@@ -991,6 +1022,7 @@ def test_connect_pgpass_regular(self):
9911022
'password': 'password from pgpass for cde:5433',
9921023
'user': 'user',
9931024
'database': 'db',
1025+
'target_session_attrs': 'any',
9941026
}
9951027
)
9961028
})
@@ -1007,6 +1039,7 @@ def test_connect_pgpass_regular(self):
10071039
'password': 'password from pgpass for testuser',
10081040
'user': 'testuser',
10091041
'database': 'db',
1042+
'target_session_attrs': 'any',
10101043
}
10111044
)
10121045
})
@@ -1023,6 +1056,7 @@ def test_connect_pgpass_regular(self):
10231056
'password': 'password from pgpass for testdb',
10241057
'user': 'user',
10251058
'database': 'testdb',
1059+
'target_session_attrs': 'any',
10261060
}
10271061
)
10281062
})
@@ -1039,6 +1073,7 @@ def test_connect_pgpass_regular(self):
10391073
'password': 'password from pgpass with escapes',
10401074
'user': R'test\\',
10411075
'database': R'test\:db',
1076+
'target_session_attrs': 'any',
10421077
}
10431078
)
10441079
})
@@ -1066,6 +1101,7 @@ def test_connect_pgpass_badness_mode(self):
10661101
{
10671102
'user': 'user',
10681103
'database': 'db',
1104+
'target_session_attrs': 'any',
10691105
}
10701106
)
10711107
})
@@ -1086,6 +1122,7 @@ def test_connect_pgpass_badness_non_file(self):
10861122
{
10871123
'user': 'user',
10881124
'database': 'db',
1125+
'target_session_attrs': 'any',
10891126
}
10901127
)
10911128
})
@@ -1102,6 +1139,7 @@ def test_connect_pgpass_nonexistent(self):
11021139
{
11031140
'user': 'user',
11041141
'database': 'db',
1142+
'target_session_attrs': 'any',
11051143
}
11061144
)
11071145
})
@@ -1122,6 +1160,7 @@ def test_connect_pgpass_inaccessible_file(self):
11221160
{
11231161
'user': 'user',
11241162
'database': 'db',
1163+
'target_session_attrs': 'any',
11251164
}
11261165
)
11271166
})
@@ -1144,6 +1183,7 @@ def test_connect_pgpass_inaccessible_directory(self):
11441183
{
11451184
'user': 'user',
11461185
'database': 'db',
1186+
'target_session_attrs': 'any',
11471187
}
11481188
)
11491189
})

0 commit comments

Comments
 (0)