MCPcopy Create free account
hub / github.com/MagicStack/asyncpg / mock_dot_postgresql

Function mock_dot_postgresql

tests/test_connect.py:60–82  ·  view source on GitHub ↗
(*, ca=True, crl=False, client=False, protected=False)

Source from the content-addressed store, hash-verified

58
59@contextlib.contextmanager
60def mock_dot_postgresql(*, ca=True, crl=False, client=False, protected=False):
61 with tempfile.TemporaryDirectory() as temp_dir:
62 home = pathlib.Path(temp_dir)
63 pg_home = home / '.postgresql'
64 pg_home.mkdir()
65 if ca:
66 shutil.copyfile(SSL_CA_CERT_FILE, pg_home / 'root.crt')
67 if crl:
68 shutil.copyfile(SSL_CA_CRL_FILE, pg_home / 'root.crl')
69 if client:
70 shutil.copyfile(CLIENT_SSL_CERT_FILE, pg_home / 'postgresql.crt')
71 if protected:
72 shutil.copyfile(
73 CLIENT_SSL_PROTECTED_KEY_FILE, pg_home / 'postgresql.key'
74 )
75 else:
76 shutil.copyfile(
77 CLIENT_SSL_KEY_FILE, pg_home / 'postgresql.key'
78 )
79 with unittest.mock.patch(
80 'pathlib.Path.home', unittest.mock.Mock(return_value=home)
81 ):
82 yield
83
84
85@contextlib.contextmanager

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…