def test_sql_wrapper_results_limit_exceeded(monkeypatch, fx_sql): kwargs, _, _, _ = fx_sql connect = mock_connect() monkeypatch.setattr('psycopg2.connect', connect) sql = SqlWrapper(**kwargs) with pytest.raises(DbError): sql.execute(STMT).results(max_results=RESULT_COUNT - 1)
def test_sql_wrapper_result_errors(monkeypatch, fx_sql): kwargs, _, _, _ = fx_sql connect = mock_connect() monkeypatch.setattr('psycopg2.connect', connect) sql = SqlWrapper(**kwargs) connect.return_value.cursor.return_value.fetchone.side_effect = Exception() with pytest.raises(DbError): sql.execute(STMT).result()
def test_sql_wrapper_results_errors(monkeypatch, fx_sql): kwargs, _, _, _ = fx_sql connect = mock_connect() monkeypatch.setattr('psycopg2.connect', connect) sql = SqlWrapper(**kwargs) connect.return_value.cursor.return_value.fetchmany.side_effect = Exception() with pytest.raises(DbError): sql.execute(STMT).results()
def test_sql_wrapper_results(monkeypatch, fx_sql): kwargs, results, _, exp_results = fx_sql connect = mock_connect(results=results) monkeypatch.setattr('psycopg2.connect', connect) sql = SqlWrapper(**kwargs) assert sql assert_connect(connect, kwargs) res = sql.execute(STMT).results() assert res == exp_results res = sql.execute(STMT).results(raise_if_limit_exceeded=False) assert res == exp_results assert STMT == sql._stmt
def test_sql_wrapper_result(monkeypatch, fx_sql): kwargs, results, exp_res, _ = fx_sql connect = mock_connect(results=results) monkeypatch.setattr('psycopg2.connect', connect) sql = SqlWrapper(**kwargs) assert sql assert_connect(connect, kwargs) res = sql.execute(STMT).result() assert res == exp_res assert STMT == sql._stmt