Esempio n. 1
0
def test_get_conn_async(mocker):
    conn_mock = mocker.patch('psycopg2.connect')
    conn_wait_mock = mocker.patch('lib.db.DB._async_conn_wait')
    conn = DB._get_conn(TEST_DSN, True)
    conn_mock.assert_called_with(TEST_DSN, async_=True)
    conn_wait_mock.assert_called_with(conn)
Esempio n. 2
0
def test_get_conn_fail(mocker):
    exit_mock = mocker.patch('sys.exit')
    conn_mock = mocker.patch('psycopg2.connect',
                             side_effect=psycopg2.OperationalError)
    DB._get_conn(TEST_DSN, False)
    exit_mock.assert_called_with(1)
Esempio n. 3
0
def test_get_conn_sync(mocker):
    conn_mock = mocker.patch('psycopg2.connect')
    conn = DB._get_conn(TEST_DSN, False)
    conn_mock.assert_called_with(TEST_DSN, async_=False)
    assert conn.autocommit