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

Function mock_dot_postgresql

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

Source from the content-addressed store, hash-verified

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

Calls

no outgoing calls

Tested by

no test coverage detected